Open
Description
How to use context correlation is not well demonstrated in the example, and I am not able to effectively utilize contextual content. Can you provide corresponding support.
I have used ai dev galley. But the examples it provides cannot support contextual content well.
Its example code is to add questions and answers to prompt words.
private string GetPrompt(IEnumerable<ChatMessage> history)
{
if (!history.Any())
{
return string.Empty;
}
string prompt = string.Empty;
var firstMessage = history.FirstOrDefault();
_languageModelContext = firstMessage?.Role == ChatRole.System ?
_languageModel?.CreateContext(firstMessage.Text, new ContentFilterOptions()) :
_languageModel?.CreateContext();
for (var i = 0; i < history.Count(); i++)
{
var message = history.ElementAt(i);
if (message.Role == ChatRole.System)
{
if (i > 0)
{
throw new ArgumentException("Only first message can be a system message");
}
}
else if (message.Role == ChatRole.User)
{
string msgText = message.Text ?? string.Empty;
prompt += msgText;
}
else if (message.Role == ChatRole.Assistant)
{
prompt += message.Text;
}
}
return prompt;
}