refine chat instruction
This commit is contained in:
parent
29a3565a52
commit
37aa85af36
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(TargetFramework)</TargetFramework>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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