using AIStudio.Chat;
namespace AIStudio.Assistants;
///
/// Which system prompt a chat gets which continues the conversation of an assistant.
///
///
/// Every assistant makes this choice itself, see AssistantBase.ChatSystemPrompt. The prompt of an assistant
/// may forbid follow-up questions or demand JSON, while the default prompt of AI Studio knows nothing about
/// the role and the settings of the assistant. A prompt of its own for the chat keeps the role and the
/// settings, but leaves out the rules for the result.
///
/// That prompt is built only when it is needed, so the choice itself can be read without the state of the
/// assistant.
///
/// Where the system prompt of the chat comes from.
/// Builds the prompt of the assistant for the chat; only read for ChatSystemPromptSource.CUSTOM.
public sealed record ChatSystemPromptChoice(ChatSystemPromptSource Source, Func BuildCustomPrompt)
{
///
/// The chat gets the default prompt of AI Studio.
///
public static readonly ChatSystemPromptChoice AI_STUDIO_DEFAULT = new(ChatSystemPromptSource.AI_STUDIO_DEFAULT, () => string.Empty);
///
/// The chat gets the prompt with which the assistant ran its conversation.
///
public static readonly ChatSystemPromptChoice ASSISTANT = new(ChatSystemPromptSource.ASSISTANT, () => string.Empty);
///
/// The chat gets a prompt which the assistant writes for it.
///
/// Builds the prompt from the settings of the assistant.
/// The choice of a prompt of its own.
public static ChatSystemPromptChoice Custom(Func buildPrompt) => new(ChatSystemPromptSource.CUSTOM, buildPrompt);
///
/// Creates the system prompt of the chat.
///
/// The prompt with which the assistant ran its conversation.
/// The system prompt of the chat; empty when the assistant wrote an empty prompt for the chat.
public string CreatePrompt(string promptOfAssistant) => this.Source switch
{
ChatSystemPromptSource.ASSISTANT => promptOfAssistant,
ChatSystemPromptSource.CUSTOM => this.BuildCustomPrompt(),
_ => SystemPrompts.DEFAULT,
};
}