diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index 7115ccf16..4092f9c79 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -28,6 +28,7 @@ public class Agent /// [JsonIgnore] public List Samples { get; set; } + = new List(); /// /// Functions @@ -70,6 +71,7 @@ public class Agent /// [JsonIgnore] public Dictionary TemplateDict { get; set; } + = new Dictionary(); public override string ToString() => $"{Name} {Id}"; diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs index 172329206..c1d702ac1 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs @@ -38,6 +38,15 @@ public static string JsonContent(this string text) public static T? JsonContent(this string text) { text = JsonContent(text); - return JsonSerializer.Deserialize(text); + + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true, + AllowTrailingCommas = true + }; + + return JsonSerializer.Deserialize(text, options); } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index 8aed5989e..517bd0f7c 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -464,9 +464,6 @@ private void UpdateAgentAllFields(Agent inputAgent) } #endregion -#if !DEBUG - [MemoryCache(10 * 60)] -#endif public List GetAgentResponses(string agentId, string prefix, string intent) { var responses = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 7cf24a23e..feb75ef69 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -23,15 +23,22 @@ public async Task InvokeAgent(string agentId, List dialog var settings = _services.GetRequiredService(); 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; diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index f2c78be2f..b91d70027 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -298,7 +298,7 @@ private string GetPrompt(ChatCompletionsOptions chatCompletionsOptions) { 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"; }