revert change
This commit is contained in:
parent
e3b0a7f075
commit
bd4ec132d5
|
|
@ -16,15 +16,12 @@ public interface IConversationService
|
|||
/// Send message to LLM
|
||||
/// </summary>
|
||||
/// <param name="agentId"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="lastDalog"></param>
|
||||
/// <param name="onMessageReceived"></param>
|
||||
/// <param name="onFunctionExecuting">This delegate is useful when you want to report progress on UI</param>
|
||||
/// <param name="onFunctionExecuted">This delegate is useful when you want to report progress on UI</param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SendMessage(string agentId,
|
||||
string channel,
|
||||
RoleDialogModel lastDalog,
|
||||
Func<RoleDialogModel, Task> onMessageReceived,
|
||||
Func<RoleDialogModel, Task> onFunctionExecuting,
|
||||
|
|
|
|||
|
|
@ -10,13 +10,12 @@ namespace BotSharp.Core.Conversations.Services;
|
|||
public partial class ConversationService
|
||||
{
|
||||
public async Task<bool> SendMessage(string agentId,
|
||||
string channel,
|
||||
RoleDialogModel message,
|
||||
Func<RoleDialogModel, Task> onMessageReceived,
|
||||
Func<RoleDialogModel, Task> onFunctionExecuting,
|
||||
Func<RoleDialogModel, Task> onFunctionExecuted)
|
||||
{
|
||||
var conversation = await GetConversationRecord(agentId, channel);
|
||||
var conversation = await GetConversationRecord(agentId);
|
||||
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
Agent agent = await agentService.LoadAgent(agentId);
|
||||
|
|
@ -70,13 +69,15 @@ public partial class ConversationService
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<Conversation> GetConversationRecord(string agentId, string channel)
|
||||
private async Task<Conversation> GetConversationRecord(string agentId)
|
||||
{
|
||||
var converation = await GetConversation(_conversationId);
|
||||
|
||||
// Create conversation if this conversation does not exist
|
||||
if (converation == null)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var channel = state.GetState("channel");
|
||||
var sess = new Conversation
|
||||
{
|
||||
Id = _conversationId,
|
||||
|
|
|
|||
|
|
@ -88,12 +88,14 @@ public class EvaluatingService : IEvaluatingService
|
|||
private async Task<RoleDialogModel> SendMessage(string agentId, string conversationId, string text)
|
||||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(conversationId, new List<string>());
|
||||
conv.SetConversationId(conversationId, new List<string>
|
||||
{
|
||||
$"channel={ConversationChannel.OpenAPI}"
|
||||
});
|
||||
|
||||
RoleDialogModel response = default;
|
||||
|
||||
await conv.SendMessage(agentId,
|
||||
ConversationChannel.OpenAPI,
|
||||
new RoleDialogModel(AgentRole.User, text),
|
||||
async msg => response = msg,
|
||||
fnExecuting => Task.CompletedTask,
|
||||
|
|
|
|||
|
|
@ -143,8 +143,7 @@ public partial class RoutingService : IRoutingService
|
|||
|
||||
// Filter agents by profile
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var conversation = db.GetConversation(state.GetConversationId());
|
||||
var channel = conversation?.Channel;
|
||||
var channel = state.GetState("channel");
|
||||
var specifiedProfile = agents.FirstOrDefault(x => x.Profiles.Contains(channel));
|
||||
if (specifiedProfile != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using BotSharp.Abstraction.Agents.Enums;
|
||||
using BotSharp.Abstraction.ApiAdapters;
|
||||
using BotSharp.Abstraction.Conversations.Enums;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
|
|
@ -99,14 +100,15 @@ public class ConversationController : ControllerBase, IApiAdapter
|
|||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(conversationId, input.States);
|
||||
conv.States.SetState("provider", input.Provider)
|
||||
conv.States.SetState("channel", input.Channel)
|
||||
.SetState("provider", input.Provider)
|
||||
.SetState("model", input.Model)
|
||||
.SetState("temperature", input.Temperature)
|
||||
.SetState("sampling_factor", input.SamplingFactor);
|
||||
|
||||
var response = new ChatResponseModel();
|
||||
var inputMsg = new RoleDialogModel("user", input.Text);
|
||||
await conv.SendMessage(agentId, input.Channel, inputMsg,
|
||||
var inputMsg = new RoleDialogModel(AgentRole.User, input.Text);
|
||||
await conv.SendMessage(agentId, inputMsg,
|
||||
async msg =>
|
||||
{
|
||||
response.Text = msg.Content;
|
||||
|
|
|
|||
|
|
@ -76,13 +76,13 @@ public class ChatbotUiController : ControllerBase, IApiAdapter
|
|||
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(input.ConversationId, input.States);
|
||||
conv.States.SetState("provider", input.Provider)
|
||||
conv.States.SetState("channel", input.Channel)
|
||||
.SetState("provider", input.Provider)
|
||||
.SetState("model", input.Model)
|
||||
.SetState("temperature", input.Temperature)
|
||||
.SetState("sampling_factor", input.SamplingFactor);
|
||||
|
||||
var result = await conv.SendMessage(input.AgentId,
|
||||
input.Channel,
|
||||
message,
|
||||
async msg =>
|
||||
await OnChunkReceived(outputStream, msg),
|
||||
|
|
|
|||
|
|
@ -48,10 +48,13 @@ public class MessageHandleService
|
|||
|
||||
// Go to LLM
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(sender, new List<string>());
|
||||
conv.SetConversationId(sender, new List<string>
|
||||
{
|
||||
$"channel={ConversationChannel.Messenger}"
|
||||
});
|
||||
|
||||
var replies = new List<IRichMessage>();
|
||||
var result = await conv.SendMessage(agentId, ConversationChannel.Messenger,
|
||||
var result = await conv.SendMessage(agentId,
|
||||
new RoleDialogModel(AgentRole.User, message), async msg =>
|
||||
{
|
||||
if (msg.RichContent != null)
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ public class TwilioVoiceController : TwilioController
|
|||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
conv.SetConversationId(sessionId, new List<string>
|
||||
{
|
||||
$"channel={ConversationChannel.Phone}",
|
||||
$"calling_phone={input.DialCallSid}"
|
||||
});
|
||||
|
||||
VoiceResponse response = default;
|
||||
|
||||
var result = await conv.SendMessage(agentId,
|
||||
ConversationChannel.Phone,
|
||||
new RoleDialogModel(AgentRole.User, input.SpeechResult),
|
||||
async msg =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue