From dd82952b0eec52e8dafe47c60cef97c1769f7ebf Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 22 Oct 2024 06:31:21 -0500 Subject: [PATCH 1/3] Rollback message payload change --- .../Services/ConversationService.SendMessage.cs | 8 ++++---- .../Routing/RoutingService.InvokeFunction.cs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index ba739dac..59ce88c2 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -40,10 +40,10 @@ public partial class ConversationService routing.Context.Push(agent.Id, reason: "request started"); // Save payload in order to assign the payload before hook is invoked - // if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload)) - // { - // message.Payload = replyMessage.Payload; - // } + if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload)) + { + message.Payload = replyMessage.Payload; + } // Before chat completion hook hooks = ReOrderConversationHooks(hooks); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index 499c8981..64b96136 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -53,7 +53,8 @@ public partial class RoutingService message.PostbackFunctionName = clonedMessage.PostbackFunctionName; message.CurrentAgentId = clonedMessage.CurrentAgentId; message.Content = clonedMessage.Content; - message.Payload = clonedMessage.Payload; + // Don't copy payload + // message.Payload = clonedMessage.Payload; message.StopCompletion = clonedMessage.StopCompletion; message.RichContent = clonedMessage.RichContent; message.Data = clonedMessage.Data; From 108be726de89e15a08179d84c92dfd4dcd9dd522 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 22 Oct 2024 06:43:40 -0500 Subject: [PATCH 2/3] Rollback GetConversationContent. --- .../Routing/RoutingService.GetConversationContent.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs index f8efab46..60e81bbe 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs @@ -16,7 +16,15 @@ public partial class RoutingService role = agent.Name; } - conversation += $"{role}: {dialog.Payload ?? dialog.Content}\r\n"; + if (role == AgentRole.User) + { + conversation += $"{role}: {dialog.Payload ?? dialog.Content}\r\n"; + } + else + { + // Assistant reply doesn't need help with payload + conversation += $"{role}: {dialog.Content}\r\n"; + } } return conversation; From 51340e7b67774a3a8ae3c3c99ff782be48be0994 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 22 Oct 2024 07:04:40 -0500 Subject: [PATCH 3/3] Rollback PrepareOptions assistant message. --- .../Providers/Chat/ChatCompletionProvider.cs | 2 +- .../Providers/Chat/ChatCompletionProvider.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs index b77a47c1..3384e3b7 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -312,7 +312,7 @@ public class ChatCompletionProvider : IChatCompletion } else if (message.Role == AgentRole.Assistant) { - messages.Add(new AssistantChatMessage(message.Payload ?? message.Content)); + messages.Add(new AssistantChatMessage(message.Content)); } } diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs index 1c9ca641..50151513 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -290,7 +290,7 @@ public class ChatCompletionProvider : IChatCompletion } else if (message.Role == AgentRole.Assistant) { - messages.Add(new AssistantChatMessage(message.Payload ?? message.Content)); + messages.Add(new AssistantChatMessage(message.Content)); } }