Skip to content

Commit

Permalink
Add chat system prompt option for text completion (#1465)
Browse files Browse the repository at this point in the history
This change adds a new property to the CompleteRequestSettings class
that allows specifying a custom system prompt to use when generating
text completions using a chat model. This can be useful for setting the
tone and context of the conversation. The default value is "Assistant is
a large language model." which is the same as the OpenAI API.

The change also modifies the ClientBase class to pass the chat system
prompt to the InternalCreateNewChat method, which creates a new instance
of the OpenAIChatHistory class. This way, the chat history will include
the system prompt as the first message.

Co-authored-by: Lee Miller <[email protected]>
  • Loading branch information
lemillermicrosoft and lemillermicrosoft authored Jun 15, 2023
1 parent 32a1185 commit fa8b8b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private protected async IAsyncEnumerable<ITextStreamingResult> InternalGetChatSt
private static OpenAIChatHistory PrepareChatHistory(string text, CompleteRequestSettings? requestSettings, out ChatRequestSettings settings)
{
requestSettings ??= new();
var chat = InternalCreateNewChat();
var chat = InternalCreateNewChat(requestSettings.ChatSystemPrompt);
chat.AddUserMessage(text);
settings = new ChatRequestSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class CompleteRequestSettings
/// </summary>
public int ResultsPerPrompt { get; set; } = 1;

/// <summary>
/// The system prompt to use when generating text completions using a chat model.
/// Defaults to "Assistant is a large language model."
/// </summary>
public string ChatSystemPrompt { get; set; } = "Assistant is a large language model.";

/// <summary>
/// Create a new settings object with the values from another settings object.
/// </summary>
Expand Down

0 comments on commit fa8b8b7

Please sign in to comment.