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.
.Net: Fixed usage of chat system prompt (microsoft#4994)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Resolves: microsoft#4377 Resolves: microsoft#4510 When invoking prompt or function from kernel, chat system prompt is ignored, and prompt is sent to AI as system message instead of user message. The example of code that didn't work: ```csharp var settings = new OpenAIPromptExecutionSettings { ChatSystemPrompt = "Reply \"I don't know\" to every question." }; // Result contains the right answer instead of "I don't know", as it was defined in system prompt. // That's because the question was set to system message instead of user message and ChatSystemPrompt property was ignored. var result = await target.InvokePromptAsync("Where is the most famous fish market in Seattle, Washington, USA?", new(settings)); ``` This fix may potentially change the behavior of applications that rely on system message input instead of user message. In order to temporarily resolve the problem, previous behavior could be achieved by using chat prompt as in the following example: ```csharp KernelFunction function = KernelFunctionFactory.CreateFromPrompt(@" <message role=""system"">Where is the most famous fish market in Seattle, Washington, USA?</message> "); var result = await kernel.InvokeAsync(function); ``` But this is just a temporary workaround, and valid usage is presented in first example above. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> 1. Updated `ChatCompletionServiceExtensions` to use prompt as user message instead of system message. 2. Added unit and integration tests to verify this scenario. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
- Loading branch information
1 parent
715d0d7
commit 48b6bb2
Showing
4 changed files
with
133 additions
and
8 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
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
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
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