Fix instruction mode.

This commit is contained in:
hchen 2023-09-19 13:05:51 -05:00
parent 73ead13d7f
commit ba49e672ce
2 changed files with 8 additions and 4 deletions

View file

@ -20,7 +20,7 @@ public class InstructModeController : ControllerBase, IApiAdapter
}
[HttpPost("/instruct/{agentId}")]
public async Task<InstructResult> NewConversation([FromRoute] string agentId,
public async Task<InstructResult> InstructCompletion([FromRoute] string agentId,
[FromBody] InstructMessageModel input)
{
var instructor = _services.GetRequiredService<IInstructService>();
@ -28,13 +28,17 @@ public class InstructModeController : ControllerBase, IApiAdapter
Agent agent = await agentService.LoadAgent(agentId);
// switch to different instruction template
if (!string.IsNullOrEmpty(input.TemplateName))
if (!string.IsNullOrEmpty(input.Template))
{
var agentSettings = _services.GetRequiredService<AgentSettings>();
var filePath = Path.Combine(agentService.GetAgentDataDir(agentId), $"{input.TemplateName}.{agentSettings.TemplateFormat}");
var filePath = Path.Combine(agentService.GetAgentDataDir(agentId), $"{input.Template}.{agentSettings.TemplateFormat}");
agent.Instruction = System.IO.File.ReadAllText(filePath);
}
var conv = _services.GetRequiredService<IConversationService>();
conv.States.SetState("provider", input.Provider)
.SetState("model", input.Model);
return await instructor.ExecuteInstruction(agent,
new RoleDialogModel(AgentRole.User, input.Text),
fn => Task.CompletedTask,

View file

@ -4,5 +4,5 @@ namespace BotSharp.OpenAPI.ViewModels.Instructs;
public class InstructMessageModel : IncomingMessageModel
{
public override string Channel { get; set; } = "openapi";
public string? TemplateName { get; set; }
public string? Template { get; set; }
}