Skip to content

Commit

Permalink
.Net: Remove default chat system prompt (#5551)
Browse files Browse the repository at this point in the history
### Motivation and Context

Closes #5544 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
markwallace-microsoft committed Mar 21, 2024
1 parent d1b8f25 commit 1ce0343
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ internal static ChatHistory CreateNewChat(string? text = null, OpenAIPromptExecu

if (!string.IsNullOrWhiteSpace(executionSettings?.ChatSystemPrompt))
{
chat.AddSystemMessage(executionSettings!.ChatSystemPrompt);
chat.AddSystemMessage(executionSettings!.ChatSystemPrompt!);
textRole = AuthorRole.User;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,13 @@ public object? ResponseFormat
/// Defaults to "Assistant is a large language model."
/// </summary>
[JsonPropertyName("chat_system_prompt")]
public string ChatSystemPrompt
public string? ChatSystemPrompt
{
get => this._chatSystemPrompt;

set
{
this.ThrowIfFrozen();

if (string.IsNullOrWhiteSpace(value))
{
value = DefaultChatSystemPrompt;
}

this._chatSystemPrompt = value;
}
}
Expand Down Expand Up @@ -305,11 +299,6 @@ public override PromptExecutionSettings Clone()
};
}

/// <summary>
/// Default value for chat system property.
/// </summary>
internal static string DefaultChatSystemPrompt { get; } = "Assistant is a large language model.";

/// <summary>
/// Default max tokens for a text generation
/// </summary>
Expand Down Expand Up @@ -381,7 +370,7 @@ public static OpenAIPromptExecutionSettings FromExecutionSettingsWithData(Prompt
private IDictionary<int, int>? _tokenSelectionBiases;
private ToolCallBehavior? _toolCallBehavior;
private string? _user;
private string _chatSystemPrompt = DefaultChatSystemPrompt;
private string? _chatSystemPrompt;

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public async Task ItAddsIdToChatMessageAsync()
var actualRequestContent = Encoding.UTF8.GetString(this._messageHandlerStub.RequestContent!);
Assert.NotNull(actualRequestContent);
var optionsJson = JsonSerializer.Deserialize<JsonElement>(actualRequestContent);
Assert.Equal(2, optionsJson.GetProperty("messages").GetArrayLength());
Assert.Equal("John Doe", optionsJson.GetProperty("messages")[1].GetProperty("tool_call_id").GetString());
Assert.Equal(1, optionsJson.GetProperty("messages").GetArrayLength());
Assert.Equal("John Doe", optionsJson.GetProperty("messages")[0].GetProperty("tool_call_id").GetString());
}

[Fact]
Expand Down Expand Up @@ -258,13 +258,10 @@ public async Task ItAddsSystemMessageAsync()
var optionsJson = JsonSerializer.Deserialize<JsonElement>(actualRequestContent);

var messages = optionsJson.GetProperty("messages");
Assert.Equal(2, messages.GetArrayLength());
Assert.Equal(1, messages.GetArrayLength());

Assert.Equal("Assistant is a large language model.", messages[0].GetProperty("content").GetString());
Assert.Equal("system", messages[0].GetProperty("role").GetString());

Assert.Equal("Hello", messages[1].GetProperty("content").GetString());
Assert.Equal("user", messages[1].GetProperty("role").GetString());
Assert.Equal("Hello", messages[0].GetProperty("content").GetString());
Assert.Equal("user", messages[0].GetProperty("role").GetString());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void ItCreatesOpenAIExecutionSettingsFromJsonSnakeCase()
}

[Theory]
[InlineData("", "Assistant is a large language model.")]
[InlineData("", "")]
[InlineData("System prompt", "System prompt")]
public void ItUsesCorrectChatSystemPrompt(string chatSystemPrompt, string expectedChatSystemPrompt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void ItProvidesAccessToFunctionsViaFunctionCollection()
}

[Theory]
[InlineData(null, "Assistant is a large language model.")]
[InlineData(null, null)]
[InlineData("My Chat Prompt", "My Chat Prompt")]
public async Task ItUsesChatSystemPromptWhenProvidedAsync(string? providedSystemChatPrompt, string expectedSystemChatPrompt)
public async Task ItUsesChatSystemPromptWhenProvidedAsync(string? providedSystemChatPrompt, string? expectedSystemChatPrompt)
{
// Arrange
var mockTextGeneration = new Mock<ITextGenerationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public void DeserializingDoNotExpectChatSystemPromptToExist()

// Assert
Assert.NotNull(settings);
Assert.NotNull(settings.ChatSystemPrompt);
Assert.Equal("Assistant is a large language model.", settings.ChatSystemPrompt);
Assert.Null(settings.ChatSystemPrompt);
}

[Fact]
Expand Down

0 comments on commit 1ce0343

Please sign in to comment.