Allow override model for ExecutingDirectly.

This commit is contained in:
Haiping Chen 2023-11-20 09:51:57 -06:00
parent 4c1af4c710
commit ab70a4d447
10 changed files with 26 additions and 9 deletions

View file

@ -0,0 +1,9 @@
namespace BotSharp.Abstraction.Conversations.Enums;
public class ConversationChannel
{
public const string WebChat = "webchat";
public const string OpenAPI = "openapi";
public const string Phone = "phone";
public const string Messenger = "messenger";
}

View file

@ -17,6 +17,8 @@ public class Conversation
public string Status { get; set; } = ConversationStatus.Open;
public string Channel { get; set; } = ConversationChannel.OpenAPI;
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}

View file

@ -13,7 +13,7 @@ public class FunctionCallFromLlm : RoutingArgs
public JsonDocument? Arguments { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool IsExecutionOnce { get; set; }
public bool ExecutingDirectly { get; set; }
public override string ToString()
{

View file

@ -19,5 +19,5 @@ public interface IRoutingService
/// <param name="agent"></param>
/// <param name="message"></param>
/// <returns></returns>
Task<RoleDialogModel> ExecuteOnce(Agent agent, RoleDialogModel message);
Task<RoleDialogModel> ExecuteDirectly(Agent agent, RoleDialogModel message);
}

View file

@ -57,7 +57,7 @@ public partial class ConversationService
var response = agentId == settings.RouterId ?
await routing.InstructLoop(message) :
await routing.ExecuteOnce(agent, message);
await routing.ExecuteDirectly(agent, message);
await HandleAssistantMessage(response, onMessageReceived);

View file

@ -3,6 +3,7 @@ using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Planning;
using BotSharp.Abstraction.Repositories;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Routing.Settings;
using BotSharp.Abstraction.Templating;
namespace BotSharp.Core.Planning;
@ -28,7 +29,10 @@ public class HFPlanner : IPlaner
RoleDialogModel response = default;
var inst = new FunctionCallFromLlm();
var completion = CompletionProvider.GetChatCompletion(_services);
var routerSetting = _services.GetRequiredService<RoutingSettings>();
var completion = CompletionProvider.GetChatCompletion(_services,
provider: routerSetting.Provider,
model: routerSetting.Model);
int retryCount = 0;
while (retryCount < 3)

View file

@ -42,7 +42,7 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
var agent = await agentService.LoadAgent(agentId);
inst.AgentName = agent.Name;
if (inst.IsExecutionOnce)
if (inst.ExecutingDirectly)
{
message.Content = inst.Question;
}

View file

@ -21,8 +21,7 @@ public partial class RoutingService
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(agentId);
var settings = _services.GetRequiredService<ChatCompletionSetting>();
var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider: settings.Provider, model: settings.Model);
var chatCompletion = CompletionProvider.GetChatCompletion(_services);
var message = dialogs.Last();
var response = chatCompletion.GetChatCompletions(agent, dialogs);

View file

@ -31,7 +31,7 @@ public partial class RoutingService : IRoutingService
_logger = logger;
}
public async Task<RoleDialogModel> ExecuteOnce(Agent agent, RoleDialogModel message)
public async Task<RoleDialogModel> ExecuteDirectly(Agent agent, RoleDialogModel message)
{
var handlers = _services.GetServices<IRoutingHandler>();
@ -48,7 +48,7 @@ public partial class RoutingService : IRoutingService
Reason = message.Content,
AgentName = agent.Name,
OriginalAgent = agent.Name,
IsExecutionOnce = true
ExecutingDirectly = true
};
var result = await handler.Handle(this, inst, message);

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Conversations.Enums;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.OpenAPI.ViewModels.Users;
using System.Text.Json.Serialization;
@ -20,6 +21,7 @@ public class ConversationViewModel
public string Event { get; set; }
public string Channel { get; set; } = ConversationChannel.OpenAPI;
public string Status { get; set; }
[JsonPropertyName("updated_time")]
@ -38,6 +40,7 @@ public class ConversationViewModel
},
AgentId = sess.AgentId,
Title = sess.Title,
Channel = sess.Channel,
Status = sess.Status,
CreatedTime = sess.CreatedTime,
UpdatedTime = sess.UpdatedTime