Set default ModelName as null.
This commit is contained in:
parent
17bfcb2518
commit
4b6c32586c
|
|
@ -8,7 +8,7 @@ public interface IConversationStateService
|
|||
ConversationState Load(string conversationId);
|
||||
string GetState(string name, string defaultValue = "");
|
||||
ConversationState GetStates();
|
||||
void SetState(string name, string value);
|
||||
IConversationStateService SetState(string name, string value);
|
||||
void CleanState();
|
||||
void Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class IncomingMessageModel
|
|||
/// Model name
|
||||
/// </summary>
|
||||
[JsonPropertyName("model")]
|
||||
public virtual string ModelName { get; set; } = "gpt-3.5-turbo";
|
||||
public virtual string? ModelName { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// The sampling temperature to use that controls the apparent creativity of generated completions.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Repositories;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Core.Agents.Services;
|
||||
|
||||
|
|
@ -17,6 +16,7 @@ public partial class AgentService
|
|||
return query.ToList();
|
||||
}
|
||||
|
||||
[MemoryCache(10 * 60)]
|
||||
public async Task<Agent> GetAgent(string id)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
_states = new ConversationState();
|
||||
}
|
||||
|
||||
public void SetState(string name, string value)
|
||||
public IConversationStateService SetState(string name, string value)
|
||||
{
|
||||
var hooks = _services.GetServices<IConversationHook>();
|
||||
string preValue = _states.ContainsKey(name) ? _states[name] : "";
|
||||
|
|
@ -43,6 +43,8 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
hook.OnStateChanged(name, preValue, currentValue).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConversationState Load(string conversationId)
|
||||
|
|
@ -118,6 +120,12 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
{
|
||||
_states[name] = defaultValue ?? "";
|
||||
}
|
||||
|
||||
if (_states[name] == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return _states[name];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@ namespace BotSharp.Core.Infrastructures;
|
|||
|
||||
public class CompletionProvider
|
||||
{
|
||||
public static IChatCompletion GetChatCompletion(IServiceProvider services)
|
||||
public static IChatCompletion GetChatCompletion(IServiceProvider services, string? model = null)
|
||||
{
|
||||
var completions = services.GetServices<IChatCompletion>();
|
||||
// var settings = services.GetRequiredService<ConversationSetting>();
|
||||
// completions.FirstOrDefault(x => x.GetType().FullName.EndsWith(settings.ChatCompletion));
|
||||
|
||||
var state = services.GetRequiredService<IConversationStateService>();
|
||||
var model = state.GetState("model", "gpt-3.5-turbo");
|
||||
if (model == null)
|
||||
{
|
||||
model = state.GetState("model", "gpt-3.5-turbo");
|
||||
}
|
||||
|
||||
return completions.FirstOrDefault(x => x.ModelName == model);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using Aspects.Cache;
|
||||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
|
|
@ -53,11 +52,11 @@ public class Router : IAgentRouting
|
|||
|
||||
public RoutingItem GetRecordByName(string name)
|
||||
{
|
||||
return GetRoutingRecords().First(x => x.Name.ToLower() == name.ToLower());
|
||||
return GetRoutingRecords().FirstOrDefault(x => x.Name.ToLower() == name.ToLower());
|
||||
}
|
||||
|
||||
public RoutingItem GetRecordByAgentId(string id)
|
||||
{
|
||||
return GetRoutingRecords().First(x => x.AgentId == id);
|
||||
return GetRoutingRecords().FirstOrDefault(x => x.AgentId == id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,11 @@ public class Simulator
|
|||
|
||||
private void SaveStateByArgs(JsonDocument args)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stateService = _services.GetRequiredService<IConversationStateService>();
|
||||
if (args.RootElement is JsonElement root)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ public class ConversationController : ControllerBase, IApiAdapter
|
|||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(conversationId, input.States);
|
||||
conv.States.SetState("channel", input.Channel);
|
||||
conv.States.SetState("model", input.ModelName);
|
||||
conv.States.SetState("temperature", input.Temperature.ToString());
|
||||
conv.States.SetState("sampling_factor", input.SamplingFactor.ToString());
|
||||
conv.States.SetState("channel", input.Channel)
|
||||
.SetState("model", input.ModelName)
|
||||
.SetState("temperature", input.Temperature.ToString())
|
||||
.SetState("sampling_factor", input.SamplingFactor.ToString());
|
||||
|
||||
var response = new MessageResponseModel();
|
||||
var stackMsg = new List<RoleDialogModel>();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
|||
|
||||
public class ChatCompletionProvider : IChatCompletion
|
||||
{
|
||||
private readonly AzureOpenAiSettings _settings;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger _logger;
|
||||
protected readonly AzureOpenAiSettings _settings;
|
||||
protected readonly IServiceProvider _services;
|
||||
protected readonly ILogger _logger;
|
||||
|
||||
public virtual string ModelName => "gpt-3.5-turbo";
|
||||
|
||||
|
|
|
|||
|
|
@ -8,19 +8,12 @@ namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
|||
|
||||
public class GPT4CompletionProvider : ChatCompletionProvider
|
||||
{
|
||||
private readonly AzureOpenAiSettings _settings;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public override string ModelName => "gpt-4";
|
||||
|
||||
public GPT4CompletionProvider(AzureOpenAiSettings settings,
|
||||
ILogger<GPT4CompletionProvider> logger,
|
||||
IServiceProvider services) : base(settings, logger, services)
|
||||
{
|
||||
_settings = settings;
|
||||
_logger = logger;
|
||||
_services = services;
|
||||
}
|
||||
|
||||
protected override (OpenAIClient, string) GetClient()
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public class ChatbotUiController : ControllerBase, IApiAdapter
|
|||
conv.SetConversationId(input.ConversationId, input.States);
|
||||
conv.States.SetState("model", input.ModelName);
|
||||
conv.States.SetState("channel", "webchat");
|
||||
conv.States.SetState("temperature", "0.5");
|
||||
conv.States.SetState("sampling_factor", "0.5");
|
||||
conv.States.SetState("temperature", input.Temperature.ToString());
|
||||
conv.States.SetState("sampling_factor", input.SamplingFactor.ToString());
|
||||
|
||||
var result = await conv.SendMessage(input.AgentId,
|
||||
message,
|
||||
|
|
|
|||
Loading…
Reference in a new issue