forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copilot Chat: Use standard semantic skills to define chat prompts (mi…
…crosoft#1853) ### Motivation and Context Currently the prompts are made available inside of appsettings.json which differs from the standard convention of shipping prompts in skprompt.txt files. This PR updates the copilot chat to call Semantic Skills that have been configured with config.json and skprompt.txt files instead of inline prompts in code. In response to: [microsoft#1726](microsoft#1763) ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) - [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with `dotnet format` - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Gina Triolo <[email protected]> Co-authored-by: Harleen Thind <[email protected]> Co-authored-by: Ben Thomas <[email protected]>
- Loading branch information
1 parent
fc86af0
commit 7d972b7
Showing
23 changed files
with
582 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
samples/apps/copilot-chat-app/webapi/CopilotChat/Options/PromptPluginOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.SemanticKernel.AI.TextCompletion; | ||
using Microsoft.SemanticKernel.SemanticFunctions; | ||
using SemanticKernel.Service.CopilotChat.Skills; | ||
|
||
namespace SemanticKernel.Service.CopilotChat.Options; | ||
|
||
/// <summary> | ||
/// Options for prompts of semantic functions | ||
/// </summary> | ||
public class PluginPromptOptions | ||
{ | ||
/// <summary> | ||
/// Number of tokens used by the prompt.txt template | ||
/// </summary> | ||
public int PromptTokenCount { get; set; } | ||
|
||
/// <summary> | ||
/// Settings for the text completion request. | ||
/// </summary> | ||
public CompleteRequestSettings CompletionSettings { get; set; } | ||
|
||
private readonly ILogger _logger; | ||
|
||
public PluginPromptOptions(int promptTokenCount, CompleteRequestSettings completionSettings, ILogger logger) | ||
{ | ||
this.PromptTokenCount = promptTokenCount; | ||
this.CompletionSettings = completionSettings; | ||
this._logger = logger; | ||
} | ||
|
||
public PluginPromptOptions(string promptTextPath, string configJsonPath, ILogger logger) | ||
{ | ||
this._logger = logger; | ||
|
||
if (!File.Exists(promptTextPath)) | ||
{ | ||
var exceptionMsg = $"{Constants.PromptFileName} file does not exist at " + nameof(promptTextPath); | ||
throw new ArgumentException(exceptionMsg); | ||
} | ||
|
||
var promptText = File.ReadAllText(promptTextPath); | ||
this.PromptTokenCount = Utilities.TokenCount(promptText); | ||
|
||
if (File.Exists(configJsonPath)) | ||
{ | ||
try | ||
{ | ||
var config = PromptTemplateConfig.FromJson(File.ReadAllText(configJsonPath)); | ||
this.CompletionSettings = CompleteRequestSettings.FromCompletionConfig(config.Completion); | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
const string exceptionAdditionalInfoMsg = "Unable to parse the config file located at " + nameof(ex.ParamName); | ||
this._logger.LogWarning(exceptionAdditionalInfoMsg); | ||
throw ex; | ||
} | ||
} | ||
else | ||
{ | ||
var exceptionMsg = $"{Constants.ConfigFileName} file does not exist at " + nameof(configJsonPath); | ||
throw new ArgumentException(exceptionMsg); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.