diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionResult.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionResult.cs new file mode 100644 index 000000000..dfb73a44e --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionResult.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; + +namespace BotSharp.Abstraction.Conversations.Models; + +public class FunctionExecutionResult where T : new() +{ + private readonly string _name; + + public FunctionExecutionResult(string name) + { + _name = name; + } + + [JsonPropertyName("function_name")] + public string Name => _name; + + [JsonPropertyName("execution_result")] + public T Result { get; set; } = new T(); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionStatus.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionStatus.cs deleted file mode 100644 index 3d8224cd5..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionStatus.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BotSharp.Abstraction.Conversations.Models; - -public enum FunctionExecutionStatus -{ - Success = 1, - Failure = 2 -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionValidationResult.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionValidationResult.cs index d7221828b..34cbb28dc 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionValidationResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/FunctionExecutionValidationResult.cs @@ -4,6 +4,11 @@ namespace BotSharp.Abstraction.Conversations.Models; public class FunctionExecutionValidationResult { + public FunctionExecutionValidationResult() + { + + } + public FunctionExecutionValidationResult(string validationStatus, string validationMessage = "") { ValidationStatus = validationStatus; diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 067c5624c..e9cbee53b 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -81,17 +81,19 @@ public async Task SendMessage(string agentId, string conversationId, RoleD if (msg.Role == "function") { var result = msg.ExecutionResult.Replace("\r", " ").Replace("\n", " "); - var content = $"{msg.FunctionName} {result}"; - Console.WriteLine(content); - /*_storage.Append(agentId, conversationId, new RoleDialogModel(msg.Role, content) + var content = $"{result}"; + Console.WriteLine($"{msg.Role}: {content}"); + _storage.Append(agentId, conversationId, new RoleDialogModel(msg.Role, content) { FunctionName = msg.FunctionName, - });*/ + }); } else { var content = msg.Content.Replace("\r", " ").Replace("\n", " "); + Console.WriteLine($"{msg.Role}: {content}"); _storage.Append(agentId, conversationId, new RoleDialogModel(msg.Role, content)); + await onMessageReceived(msg); } }); diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index 946204124..b3759e433 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -120,7 +120,6 @@ public async Task GetChatCompletionsAsync(Agent agent, List Parameters = BinaryData.FromObjectAsJson(function.Parameters) }); } - + foreach (var message in conversations) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); + if (message.Role == ChatRole.Function) + { + var funcContext = JsonSerializer.Deserialize>(message.Content); + chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content) + { + Name = funcContext.Name + }); + } + else + { + chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); + } } return chatCompletionsOptions;