Skip to content

Commit 14bbb3c

Browse files
authored
Merge pull request #822 from hchen2020/master
Generate Indication from LLM
2 parents 5473713 + 48d2e43 commit 14bbb3c

File tree

14 files changed

+21
-14
lines changed

14 files changed

+21
-14
lines changed

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public static RoleDialogModel From(RoleDialogModel source,
146146
FunctionArgs = source.FunctionArgs,
147147
FunctionName = source.FunctionName,
148148
ToolCallId = source.ToolCallId,
149+
Indication = source.Indication,
149150
PostbackFunctionName = source.PostbackFunctionName,
150151
RichContent = source.RichContent,
151152
Payload = source.Payload,

src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IFunctionCallback
99
/// </summary>
1010
string Indication => string.Empty;
1111

12-
Task<string> GetIndication(RoleDialogModel message) => Task.FromResult(Indication);
12+
Task<string> GetIndication(RoleDialogModel message) => Task.FromResult(message.Indication ?? Indication);
1313

1414
Task<bool> Execute(RoleDialogModel message);
1515
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public bool RenderFunction(Agent agent, FunctionDef def)
111111

112112
parameterDef.Properties = JsonSerializer.Deserialize<JsonDocument>(clonedRoot.ToString());
113113
parameterDef.Required = required;
114-
return parameterDef; ;
114+
return parameterDef;
115115
}
116116

117117
public string RenderedTemplate(Agent agent, string templateName)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
4343
message.ToolCallId = response.ToolCallId;
4444
message.FunctionName = response.FunctionName;
4545
message.FunctionArgs = response.FunctionArgs;
46+
message.Indication = response.Indication;
4647
message.CurrentAgentId = agent.Id;
4748

4849
await InvokeFunction(message, dialogs);

src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public override async Task OnMessageReceived(RoleDialogModel message)
5252
var channel = states.GetState("channel");
5353

5454
// Check the number of conversations
55-
if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email)
55+
if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email && channel != ConversationChannel.Database)
5656
{
5757
var user = _services.GetRequiredService<IUserIdentity>();
5858
var convService = _services.GetRequiredService<IConversationService>();

src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS
4141
var agent = await agentService.LoadAgent(message.CurrentAgentId);
4242

4343
var log = message.Role == AgentRole.Function ?
44-
$"[{agent?.Name}]: {message.FunctionName}({message.FunctionArgs})" :
44+
$"[{agent?.Name}]: {message.Indication} {message.FunctionName}({message.FunctionArgs})" :
4545
$"[{agent?.Name}]: {message.Content}" + $" <== [msg_id: {message.MessageId}]";
4646

4747
_logger.LogInformation(tokenStats.Prompt);

src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Anthropic.SDK" Version="4.3.0" />
14+
<PackageReference Include="Anthropic.SDK" Version="4.4.2" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Anthropic.SDK.Common;
22
using BotSharp.Abstraction.Conversations;
33
using BotSharp.Abstraction.MLTasks.Settings;
4-
using System.Text.Json;
54
using System.Text.Json.Nodes;
65
using System.Text.Json.Serialization;
76

@@ -48,15 +47,16 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
4847

4948
if (response.StopReason == "tool_use")
5049
{
50+
var content = response.Content.OfType<TextContent>().FirstOrDefault();
5151
var toolResult = response.Content.OfType<ToolUseContent>().First();
5252

53-
responseMessage = new RoleDialogModel(AgentRole.Function, response.FirstMessage?.Text ?? string.Empty)
53+
responseMessage = new RoleDialogModel(AgentRole.Function, content?.Text ?? string.Empty)
5454
{
5555
CurrentAgentId = agent.Id,
5656
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
5757
ToolCallId = toolResult.Id,
5858
FunctionName = toolResult.Name,
59-
FunctionArgs = JsonSerializer.Serialize(toolResult.Input)
59+
FunctionArgs = JsonSerializer.Serialize(toolResult.Input),
6060
};
6161
}
6262
else
@@ -161,7 +161,7 @@ public Task<bool> GetChatCompletionsStreamingAsync(Agent agent, List<RoleDialogM
161161
new ToolResultContent()
162162
{
163163
ToolUseId = conv.ToolCallId,
164-
Content = conv.Content
164+
Content = [new TextContent() { Text = conv.Content }]
165165
}
166166
}
167167
});

src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
14+
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
1515
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
1616
</ItemGroup>
1717

src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public async Task<bool> GetChatCompletionsAsync(Agent agent,
160160
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
161161
{
162162
CurrentAgentId = agent.Id,
163+
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
163164
FunctionName = toolCall?.FunctionName,
164165
FunctionArgs = toolCall?.FunctionArguments?.ToString()
165166
};

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public override async Task OnFunctionExecuting(RoleDialogModel message)
116116
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
117117
message.FunctionArgs = message.FunctionArgs ?? "{}";
118118
var args = message.FunctionArgs.FormatJson();
119-
var log = $"{message.FunctionName} <u>executing</u>\r\n```json\r\n{args}\r\n```";
119+
var log = $"*{message.Indication.Replace("\r", string.Empty).Replace("\n", string.Empty)}* \r\n\r\n **{message.FunctionName}**()";
120+
log += args.Length > 5 ? $" \r\n```json\r\n{args}\r\n```" : string.Empty;
120121

121122
var input = new ContentLogInputModel(conversationId, message)
122123
{

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Agents;
22
using BotSharp.Abstraction.Agents.Enums;
33
using BotSharp.Abstraction.Loggers;
4+
using Google.Protobuf.WellKnownTypes;
45
using Microsoft.Extensions.Logging;
56
using Mscc.GenerativeAI;
67

@@ -125,15 +126,16 @@ public void SetModelName(string model)
125126
if (!agentService.RenderFunction(agent, function)) continue;
126127

127128
var def = agentService.RenderFunctionProperty(agent, function);
129+
var str = JsonSerializer.Serialize(def.Properties);
128130

129131
funcDeclarations.Add(new FunctionDeclaration
130132
{
131133
Name = function.Name,
132134
Description = function.Description,
133135
Parameters = new()
134136
{
135-
Type = ParameterType.Object,
136-
Properties = def.Properties,
137+
Type = str != "{}" ? ParameterType.Object : ParameterType.TypeUnspecified,
138+
Properties = str != "{}" ? JsonSerializer.Deserialize<dynamic>(str) : null,
137139
Required = def.Required
138140
}
139141
});

src/Plugins/BotSharp.Plugin.OpenAI/BotSharp.Plugin.OpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="OpenAI" Version="2.0.0" />
14+
<PackageReference Include="OpenAI" Version="2.1.0" />
1515
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
1616
</ItemGroup>
1717

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public async Task<bool> GetChatCompletionsAsync(Agent agent,
138138
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
139139
{
140140
CurrentAgentId = agent.Id,
141+
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
141142
ToolCallId = toolCall?.Id,
142143
FunctionName = toolCall?.FunctionName,
143144
FunctionArgs = toolCall?.FunctionArguments?.ToString()

0 commit comments

Comments
 (0)