Skip to content

Commit bd4ec13

Browse files
author
Jicheng Lu
committed
revert change
1 parent e3b0a7f commit bd4ec13

File tree

8 files changed

+22
-18
lines changed

8 files changed

+22
-18
lines changed

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ public interface IConversationService
1616
/// Send message to LLM
1717
/// </summary>
1818
/// <param name="agentId"></param>
19-
/// <param name="channel"></param>
20-
/// <param name="conversationId"></param>
2119
/// <param name="lastDalog"></param>
2220
/// <param name="onMessageReceived"></param>
2321
/// <param name="onFunctionExecuting">This delegate is useful when you want to report progress on UI</param>
2422
/// <param name="onFunctionExecuted">This delegate is useful when you want to report progress on UI</param>
2523
/// <returns></returns>
2624
Task<bool> SendMessage(string agentId,
27-
string channel,
2825
RoleDialogModel lastDalog,
2926
Func<RoleDialogModel, Task> onMessageReceived,
3027
Func<RoleDialogModel, Task> onFunctionExecuting,

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ namespace BotSharp.Core.Conversations.Services;
1010
public partial class ConversationService
1111
{
1212
public async Task<bool> SendMessage(string agentId,
13-
string channel,
1413
RoleDialogModel message,
1514
Func<RoleDialogModel, Task> onMessageReceived,
1615
Func<RoleDialogModel, Task> onFunctionExecuting,
1716
Func<RoleDialogModel, Task> onFunctionExecuted)
1817
{
19-
var conversation = await GetConversationRecord(agentId, channel);
18+
var conversation = await GetConversationRecord(agentId);
2019

2120
var agentService = _services.GetRequiredService<IAgentService>();
2221
Agent agent = await agentService.LoadAgent(agentId);
@@ -70,13 +69,15 @@ await routing.InstructLoop(message) :
7069
return true;
7170
}
7271

73-
private async Task<Conversation> GetConversationRecord(string agentId, string channel)
72+
private async Task<Conversation> GetConversationRecord(string agentId)
7473
{
7574
var converation = await GetConversation(_conversationId);
7675

7776
// Create conversation if this conversation does not exist
7877
if (converation == null)
7978
{
79+
var state = _services.GetRequiredService<IConversationStateService>();
80+
var channel = state.GetState("channel");
8081
var sess = new Conversation
8182
{
8283
Id = _conversationId,

src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ public async Task<EvaluationResult> Evaluate(string conversationId, EvaluationRe
8888
private async Task<RoleDialogModel> SendMessage(string agentId, string conversationId, string text)
8989
{
9090
var conv = _services.GetRequiredService<IConversationService>();
91-
conv.SetConversationId(conversationId, new List<string>());
91+
conv.SetConversationId(conversationId, new List<string>
92+
{
93+
$"channel={ConversationChannel.OpenAPI}"
94+
});
9295

9396
RoleDialogModel response = default;
9497

9598
await conv.SendMessage(agentId,
96-
ConversationChannel.OpenAPI,
9799
new RoleDialogModel(AgentRole.User, text),
98100
async msg => response = msg,
99101
fnExecuting => Task.CompletedTask,

src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ protected RoutingRule[] GetRoutingRecords()
143143

144144
// Filter agents by profile
145145
var state = _services.GetRequiredService<IConversationStateService>();
146-
var conversation = db.GetConversation(state.GetConversationId());
147-
var channel = conversation?.Channel;
146+
var channel = state.GetState("channel");
148147
var specifiedProfile = agents.FirstOrDefault(x => x.Profiles.Contains(channel));
149148
if (specifiedProfile != null)
150149
{

src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Agents.Enums;
12
using BotSharp.Abstraction.ApiAdapters;
23
using BotSharp.Abstraction.Conversations.Enums;
34
using BotSharp.Abstraction.Conversations.Models;
@@ -99,14 +100,15 @@ public async Task<ChatResponseModel> SendMessage([FromRoute] string agentId,
99100
{
100101
var conv = _services.GetRequiredService<IConversationService>();
101102
conv.SetConversationId(conversationId, input.States);
102-
conv.States.SetState("provider", input.Provider)
103+
conv.States.SetState("channel", input.Channel)
104+
.SetState("provider", input.Provider)
103105
.SetState("model", input.Model)
104106
.SetState("temperature", input.Temperature)
105107
.SetState("sampling_factor", input.SamplingFactor);
106108

107109
var response = new ChatResponseModel();
108-
var inputMsg = new RoleDialogModel("user", input.Text);
109-
await conv.SendMessage(agentId, input.Channel, inputMsg,
110+
var inputMsg = new RoleDialogModel(AgentRole.User, input.Text);
111+
await conv.SendMessage(agentId, inputMsg,
110112
async msg =>
111113
{
112114
response.Text = msg.Content;

src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public async Task SendMessage([FromBody] OpenAiMessageInput input)
7676

7777
var conv = _services.GetRequiredService<IConversationService>();
7878
conv.SetConversationId(input.ConversationId, input.States);
79-
conv.States.SetState("provider", input.Provider)
79+
conv.States.SetState("channel", input.Channel)
80+
.SetState("provider", input.Provider)
8081
.SetState("model", input.Model)
8182
.SetState("temperature", input.Temperature)
8283
.SetState("sampling_factor", input.SamplingFactor);
8384

8485
var result = await conv.SendMessage(input.AgentId,
85-
input.Channel,
8686
message,
8787
async msg =>
8888
await OnChunkReceived(outputStream, msg),

src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ await messenger.SendMessage(setting.ApiVersion, setting.PageId,
4848

4949
// Go to LLM
5050
var conv = _services.GetRequiredService<IConversationService>();
51-
conv.SetConversationId(sender, new List<string>());
51+
conv.SetConversationId(sender, new List<string>
52+
{
53+
$"channel={ConversationChannel.Messenger}"
54+
});
5255

5356
var replies = new List<IRichMessage>();
54-
var result = await conv.SendMessage(agentId, ConversationChannel.Messenger,
57+
var result = await conv.SendMessage(agentId,
5558
new RoleDialogModel(AgentRole.User, message), async msg =>
5659
{
5760
if (msg.RichContent != null)

src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public async Task<TwiMLResult> ReceivedVoiceMessage([FromRoute] string agentId,
4747
var conv = _services.GetRequiredService<IConversationService>();
4848
conv.SetConversationId(sessionId, new List<string>
4949
{
50+
$"channel={ConversationChannel.Phone}",
5051
$"calling_phone={input.DialCallSid}"
5152
});
5253

5354
VoiceResponse response = default;
5455

5556
var result = await conv.SendMessage(agentId,
56-
ConversationChannel.Phone,
5757
new RoleDialogModel(AgentRole.User, input.SpeechResult),
5858
async msg =>
5959
{

0 commit comments

Comments
 (0)