Merge pull request #197 from hchen2020/master

Fix RichContent pass alway bug.
This commit is contained in:
Haiping 2023-11-01 16:32:32 -05:00 committed by GitHub
commit e87f505b09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 8 deletions

View file

@ -28,6 +28,7 @@ public class Agent
/// </summary>
[JsonIgnore]
public List<string> Samples { get; set; }
= new List<string>();
/// <summary>
/// Functions
@ -70,6 +71,7 @@ public class Agent
/// </summary>
[JsonIgnore]
public Dictionary<string, object> TemplateDict { get; set; }
= new Dictionary<string, object>();
public override string ToString()
=> $"{Name} {Id}";

View file

@ -38,6 +38,15 @@ public static class StringExtensions
public static T? JsonContent<T>(this string text)
{
text = JsonContent(text);
return JsonSerializer.Deserialize<T>(text);
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
AllowTrailingCommas = true
};
return JsonSerializer.Deserialize<T>(text, options);
}
}

View file

@ -464,9 +464,6 @@ public class FileRepository : IBotSharpRepository
}
#endregion
#if !DEBUG
[MemoryCache(10 * 60)]
#endif
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
{
var responses = new List<string>();

View file

@ -23,15 +23,22 @@ public partial class RoutingService
var settings = _services.GetRequiredService<ChatCompletionSetting>();
var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider: settings.Provider, model: settings.Model);
RoleDialogModel response = chatCompletion.GetChatCompletions(agent, dialogs);
var message = dialogs.Last();
var response = chatCompletion.GetChatCompletions(agent, dialogs);
if (response.Role == AgentRole.Function)
{
await InvokeFunction(agent, response, dialogs);
message = RoleDialogModel.From(message,
role: AgentRole.Function);
message.FunctionName = response.FunctionName;
message.FunctionArgs = response.FunctionArgs;
await InvokeFunction(agent, message, dialogs);
}
else
{
dialogs.Add(response);
dialogs.Add(RoleDialogModel.From(message,
role: AgentRole.Assistant,
content: response.Content));
}
return true;

View file

@ -298,7 +298,7 @@ public class ChatCompletionProvider : IChatCompletion
{
var functions = string.Join("\r\n", chatCompletionsOptions.Functions.Select(x =>
{
return $"{x.Name}: {x.Description}\r\n{x.Parameters}";
return $"\r\n{x.Name}: {x.Description}\r\n{x.Parameters}";
}));
prompt += $"\r\n[FUNCTIONS]\r\n{functions}\r\n";
}