remove is const

This commit is contained in:
Jicheng Lu 2024-01-01 13:07:42 -06:00
parent 010c92db1a
commit a534a93d35
6 changed files with 19 additions and 27 deletions

View file

@ -12,7 +12,7 @@ public interface IConversationStateService
string GetState(string name, string defaultValue = "");
bool ContainsState(string name);
ConversationState GetStates();
IConversationStateService SetState<T>(string name, T value, bool isConst = false);
IConversationStateService SetState<T>(string name, T value);
void SaveStateByArgs(JsonDocument args);
void CleanState();
void Save();

View file

@ -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]));
}
}

View file

@ -36,7 +36,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
/// <param name="value"></param>
/// <param name="isConst">whether the state is related to message or not</param>
/// <returns></returns>
public IConversationStateService SetState<T>(string name, T value, bool isConst = false)
public IConversationStateService SetState<T>(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<HistoryStateValue>();
}
if (isConst)
{
_historyStates[name] = new List<HistoryStateValue> { historyStateValue };
}
else
{
var messageId = GetCurrentMessageId();
historyStateValue.MessageId = messageId ?? string.Empty;
_historyStates[name].Add(historyStateValue);
}
_historyStates[name].Add(historyStateValue);
}
return this;

View file

@ -117,11 +117,11 @@ public class ConversationController : ControllerBase
{
var conv = _services.GetRequiredService<IConversationService>();
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);

View file

@ -22,10 +22,10 @@ public class InstructModeController : ControllerBase
[FromBody] InstructMessageModel input)
{
var state = _services.GetRequiredService<IConversationStateService>();
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<IInstructService>();

View file

@ -75,11 +75,11 @@ public class ChatbotUiController : ControllerBase
var conv = _services.GetRequiredService<IConversationService>();
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,