commit
15bbd4bb2e
|
|
@ -8,4 +8,5 @@ public interface ILlmProviderService
|
|||
List<string> GetProviders();
|
||||
LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null, bool? realTime = false, bool imageGenerate = false);
|
||||
List<LlmModelSetting> GetProviderModels(string provider);
|
||||
List<LlmProviderSetting> GetLlmConfigs(LlmConfigOptions? options = null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
namespace BotSharp.Abstraction.MLTasks.Settings;
|
||||
|
||||
public class LlmConfigOptions
|
||||
{
|
||||
public LlmModelType? Type { get; set; }
|
||||
public bool? MultiModal { get; set; }
|
||||
public bool? RealTime { get; set; }
|
||||
public bool? ImageGeneration { get; set; }
|
||||
}
|
||||
|
|
@ -2,11 +2,9 @@ namespace BotSharp.Abstraction.MLTasks.Settings;
|
|||
|
||||
public class LlmProviderSetting
|
||||
{
|
||||
public string Provider { get; set; }
|
||||
= "azure-openai";
|
||||
public string Provider { get; set; } = "azure-openai";
|
||||
|
||||
public List<LlmModelSetting> Models { get; set; }
|
||||
= new List<LlmModelSetting>();
|
||||
public List<LlmModelSetting> Models { get; set; } = [];
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(TargetFramework)</TargetFramework>
|
||||
|
|
|
|||
|
|
@ -103,4 +103,50 @@ public class LlmProviderService : ILlmProviderService
|
|||
|
||||
return modelSetting;
|
||||
}
|
||||
|
||||
|
||||
public List<LlmProviderSetting> GetLlmConfigs(LlmConfigOptions? options = null)
|
||||
{
|
||||
var settingService = _services.GetRequiredService<ISettingService>();
|
||||
var providers = settingService.Bind<List<LlmProviderSetting>>($"LlmProviders");
|
||||
var configs = new List<LlmProviderSetting>();
|
||||
|
||||
if (providers.IsNullOrEmpty()) return configs;
|
||||
|
||||
if (options == null) return providers ?? [];
|
||||
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
var models = provider.Models ?? [];
|
||||
if (options.Type.HasValue)
|
||||
{
|
||||
models = models.Where(x => x.Type == options.Type.Value).ToList();
|
||||
}
|
||||
|
||||
if (options.MultiModal.HasValue)
|
||||
{
|
||||
models = models.Where(x => x.MultiModal == options.MultiModal.Value).ToList();
|
||||
}
|
||||
|
||||
if (options.ImageGeneration.HasValue)
|
||||
{
|
||||
models = models.Where(x => x.ImageGeneration == options.ImageGeneration.Value).ToList();
|
||||
}
|
||||
|
||||
if (options.RealTime.HasValue)
|
||||
{
|
||||
models = models.Where(x => x.RealTime == options.RealTime.Value).ToList();
|
||||
}
|
||||
|
||||
if (models.IsNullOrEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
provider.Models = models;
|
||||
configs.Add(provider);
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
using BotSharp.Abstraction.Plugins.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BotSharp.Core.Instructs;
|
||||
|
||||
public class InsturctionPlugin : IBotSharpPlugin
|
||||
{
|
||||
public string Id => "8189e133-819c-4505-9f82-84f793bc1be0";
|
||||
public string Name => "Instruction";
|
||||
public string Description => "Handle agent instruction request";
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool AttachMenu(List<PluginMenuDef> menu)
|
||||
{
|
||||
var section = menu.First(x => x.Label == "Apps");
|
||||
menu.Add(new PluginMenuDef("Instruction", link: "page/instruction", icon: "bx bx-book-content", weight: section.Weight + 5));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ public class InstructModeController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("/instruct/text-completion")]
|
||||
public async Task<string> TextCompletion([FromBody] IncomingMessageModel input)
|
||||
public async Task<string> TextCompletion([FromBody] IncomingInstructRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -53,12 +53,12 @@ public class InstructModeController : ControllerBase
|
|||
.SetState("model_id", input.ModelId, source: StateSource.External);
|
||||
|
||||
var textCompletion = CompletionProvider.GetTextCompletion(_services);
|
||||
return await textCompletion.GetCompletion(input.Text, Guid.Empty.ToString(), Guid.NewGuid().ToString());
|
||||
return await textCompletion.GetCompletion(input.Text, input.AgentId ?? Guid.Empty.ToString(), Guid.NewGuid().ToString());
|
||||
}
|
||||
|
||||
#region Chat
|
||||
[HttpPost("/instruct/chat-completion")]
|
||||
public async Task<string> ChatCompletion([FromBody] IncomingMessageModel input)
|
||||
public async Task<string> ChatCompletion([FromBody] IncomingInstructRequest input)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
|
||||
|
|
@ -66,10 +66,11 @@ public class InstructModeController : ControllerBase
|
|||
.SetState("model", input.Model, source: StateSource.External)
|
||||
.SetState("model_id", input.ModelId, source: StateSource.External);
|
||||
|
||||
var textCompletion = CompletionProvider.GetChatCompletion(_services);
|
||||
var message = await textCompletion.GetChatCompletions(new Agent()
|
||||
var completion = CompletionProvider.GetChatCompletion(_services);
|
||||
var message = await completion.GetChatCompletions(new Agent()
|
||||
{
|
||||
Id = Guid.Empty.ToString(),
|
||||
Id = input.AgentId ?? Guid.Empty.ToString(),
|
||||
Instruction = input.Instruction
|
||||
}, new List<RoleDialogModel>
|
||||
{
|
||||
new RoleDialogModel(AgentRole.User, input.Text)
|
||||
|
|
|
|||
|
|
@ -27,4 +27,11 @@ public class LlmProviderController : ControllerBase
|
|||
var list = _llmProvider.GetProviderModels(provider);
|
||||
return list.Where(x => x.Type == LlmModelType.Chat);
|
||||
}
|
||||
|
||||
[HttpGet("/llm-configs")]
|
||||
public List<LlmProviderSetting> GetLlmConfigs([FromQuery] LlmConfigOptions options)
|
||||
{
|
||||
var configs = _llmProvider.GetLlmConfigs(options);
|
||||
return configs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,3 +9,10 @@ public class InstructMessageModel : IncomingMessageModel
|
|||
public override string Channel { get; set; } = ConversationChannel.OpenAPI;
|
||||
public string? Template { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class IncomingInstructRequest : IncomingMessageModel
|
||||
{
|
||||
public string? AgentId { get; set; }
|
||||
public string? Instruction { get; set; }
|
||||
}
|
||||
Loading…
Reference in a new issue