From a534a93d35bd3faa711c4e948113f1e290bc8147 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 1 Jan 2024 13:07:42 -0600 Subject: [PATCH] remove is const --- .../Conversations/IConversationStateService.cs | 2 +- .../Conversations/Services/ConversationService.cs | 2 +- .../Services/ConversationStateService.cs | 14 +++----------- .../Controllers/ConversationController.cs | 10 +++++----- .../Controllers/InstructModeController.cs | 8 ++++---- .../ChatbotUiController.cs | 10 +++++----- 6 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs index 65570dc4..eeb39f73 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs @@ -12,7 +12,7 @@ public interface IConversationStateService string GetState(string name, string defaultValue = ""); bool ContainsState(string name); ConversationState GetStates(); - IConversationStateService SetState(string name, T value, bool isConst = false); + IConversationStateService SetState(string name, T value); void SaveStateByArgs(JsonDocument args); void CleanState(); void Save(); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index a39af217..d6a15072 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -120,6 +120,6 @@ public partial class ConversationService : IConversationService { _conversationId = conversationId; _state.Load(_conversationId); - states.ForEach(x => _state.SetState(x.Split('=')[0], x.Split('=')[1], true)); + states.ForEach(x => _state.SetState(x.Split('=')[0], x.Split('=')[1])); } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 1b560f43..1975e53d 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -36,7 +36,7 @@ public class ConversationStateService : IConversationStateService, IDisposable /// /// whether the state is related to message or not /// - public IConversationStateService SetState(string name, T value, bool isConst = false) + public IConversationStateService SetState(string name, T value) { if (value == null) { @@ -58,6 +58,7 @@ public class ConversationStateService : IConversationStateService, IDisposable var historyStateValue = new HistoryStateValue { + MessageId = GetCurrentMessageId(), Data = currentValue, UpdateTime = DateTime.UtcNow }; @@ -67,16 +68,7 @@ public class ConversationStateService : IConversationStateService, IDisposable _historyStates[name] = new List(); } - if (isConst) - { - _historyStates[name] = new List { historyStateValue }; - } - else - { - var messageId = GetCurrentMessageId(); - historyStateValue.MessageId = messageId ?? string.Empty; - _historyStates[name].Add(historyStateValue); - } + _historyStates[name].Add(historyStateValue); } return this; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 4d5fed54..505f794f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -117,11 +117,11 @@ public class ConversationController : ControllerBase { var conv = _services.GetRequiredService(); conv.SetConversationId(conversationId, input.States); - conv.States.SetState("channel", input.Channel, true) - .SetState("provider", input.Provider, true) - .SetState("model", input.Model, true) - .SetState("temperature", input.Temperature, true) - .SetState("sampling_factor", input.SamplingFactor, true); + conv.States.SetState("channel", input.Channel) + .SetState("provider", input.Provider) + .SetState("model", input.Model) + .SetState("temperature", input.Temperature) + .SetState("sampling_factor", input.SamplingFactor); var response = new ChatResponseModel(); var inputMsg = new RoleDialogModel(AgentRole.User, input.Text); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs index 5bd8e1c2..750719b8 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs @@ -22,10 +22,10 @@ public class InstructModeController : ControllerBase [FromBody] InstructMessageModel input) { var state = _services.GetRequiredService(); - input.States.ForEach(x => state.SetState(x.Split('=')[0], x.Split('=')[1], true)); - state.SetState("provider", input.Provider, true) - .SetState("model", input.Model, true) - .SetState("instruction", input.Instruction, true) + input.States.ForEach(x => state.SetState(x.Split('=')[0], x.Split('=')[1])); + state.SetState("provider", input.Provider) + .SetState("model", input.Model) + .SetState("instruction", input.Instruction) .SetState("input_text", input.Text); var instructor = _services.GetRequiredService(); diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index b6f3b0b2..9c422a7a 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -75,11 +75,11 @@ public class ChatbotUiController : ControllerBase var conv = _services.GetRequiredService(); conv.SetConversationId(input.ConversationId, input.States); - conv.States.SetState("channel", input.Channel, true) - .SetState("provider", input.Provider, true) - .SetState("model", input.Model, true) - .SetState("temperature", input.Temperature, true) - .SetState("sampling_factor", input.SamplingFactor, true); + conv.States.SetState("channel", input.Channel) + .SetState("provider", input.Provider) + .SetState("model", input.Model) + .SetState("temperature", input.Temperature) + .SetState("sampling_factor", input.SamplingFactor); var result = await conv.SendMessage(input.AgentId, message,