Merge pull request #822 from hchen2020/master
Generate Indication from LLM
This commit is contained in:
commit
14bbb3cea5
|
|
@ -146,6 +146,7 @@ public class RoleDialogModel : ITrackableMessage
|
||||||
FunctionArgs = source.FunctionArgs,
|
FunctionArgs = source.FunctionArgs,
|
||||||
FunctionName = source.FunctionName,
|
FunctionName = source.FunctionName,
|
||||||
ToolCallId = source.ToolCallId,
|
ToolCallId = source.ToolCallId,
|
||||||
|
Indication = source.Indication,
|
||||||
PostbackFunctionName = source.PostbackFunctionName,
|
PostbackFunctionName = source.PostbackFunctionName,
|
||||||
RichContent = source.RichContent,
|
RichContent = source.RichContent,
|
||||||
Payload = source.Payload,
|
Payload = source.Payload,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ public interface IFunctionCallback
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Indication => string.Empty;
|
string Indication => string.Empty;
|
||||||
|
|
||||||
Task<string> GetIndication(RoleDialogModel message) => Task.FromResult(Indication);
|
Task<string> GetIndication(RoleDialogModel message) => Task.FromResult(message.Indication ?? Indication);
|
||||||
|
|
||||||
Task<bool> Execute(RoleDialogModel message);
|
Task<bool> Execute(RoleDialogModel message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ public partial class AgentService
|
||||||
|
|
||||||
parameterDef.Properties = JsonSerializer.Deserialize<JsonDocument>(clonedRoot.ToString());
|
parameterDef.Properties = JsonSerializer.Deserialize<JsonDocument>(clonedRoot.ToString());
|
||||||
parameterDef.Required = required;
|
parameterDef.Required = required;
|
||||||
return parameterDef; ;
|
return parameterDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RenderedTemplate(Agent agent, string templateName)
|
public string RenderedTemplate(Agent agent, string templateName)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ public partial class RoutingService
|
||||||
message.ToolCallId = response.ToolCallId;
|
message.ToolCallId = response.ToolCallId;
|
||||||
message.FunctionName = response.FunctionName;
|
message.FunctionName = response.FunctionName;
|
||||||
message.FunctionArgs = response.FunctionArgs;
|
message.FunctionArgs = response.FunctionArgs;
|
||||||
|
message.Indication = response.Indication;
|
||||||
message.CurrentAgentId = agent.Id;
|
message.CurrentAgentId = agent.Id;
|
||||||
|
|
||||||
await InvokeFunction(message, dialogs);
|
await InvokeFunction(message, dialogs);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class RateLimitConversationHook : ConversationHookBase
|
||||||
var channel = states.GetState("channel");
|
var channel = states.GetState("channel");
|
||||||
|
|
||||||
// Check the number of conversations
|
// Check the number of conversations
|
||||||
if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email)
|
if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email && channel != ConversationChannel.Database)
|
||||||
{
|
{
|
||||||
var user = _services.GetRequiredService<IUserIdentity>();
|
var user = _services.GetRequiredService<IUserIdentity>();
|
||||||
var convService = _services.GetRequiredService<IConversationService>();
|
var convService = _services.GetRequiredService<IConversationService>();
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public class VerboseLogHook : IContentGeneratingHook
|
||||||
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||||
|
|
||||||
var log = message.Role == AgentRole.Function ?
|
var log = message.Role == AgentRole.Function ?
|
||||||
$"[{agent?.Name}]: {message.FunctionName}({message.FunctionArgs})" :
|
$"[{agent?.Name}]: {message.Indication} {message.FunctionName}({message.FunctionArgs})" :
|
||||||
$"[{agent?.Name}]: {message.Content}" + $" <== [msg_id: {message.MessageId}]";
|
$"[{agent?.Name}]: {message.Content}" + $" <== [msg_id: {message.MessageId}]";
|
||||||
|
|
||||||
_logger.LogInformation(tokenStats.Prompt);
|
_logger.LogInformation(tokenStats.Prompt);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Anthropic.SDK" Version="4.3.0" />
|
<PackageReference Include="Anthropic.SDK" Version="4.4.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using Anthropic.SDK.Common;
|
using Anthropic.SDK.Common;
|
||||||
using BotSharp.Abstraction.Conversations;
|
using BotSharp.Abstraction.Conversations;
|
||||||
using BotSharp.Abstraction.MLTasks.Settings;
|
using BotSharp.Abstraction.MLTasks.Settings;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
|
@ -48,15 +47,16 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
|
|
||||||
if (response.StopReason == "tool_use")
|
if (response.StopReason == "tool_use")
|
||||||
{
|
{
|
||||||
|
var content = response.Content.OfType<TextContent>().FirstOrDefault();
|
||||||
var toolResult = response.Content.OfType<ToolUseContent>().First();
|
var toolResult = response.Content.OfType<ToolUseContent>().First();
|
||||||
|
|
||||||
responseMessage = new RoleDialogModel(AgentRole.Function, response.FirstMessage?.Text ?? string.Empty)
|
responseMessage = new RoleDialogModel(AgentRole.Function, content?.Text ?? string.Empty)
|
||||||
{
|
{
|
||||||
CurrentAgentId = agent.Id,
|
CurrentAgentId = agent.Id,
|
||||||
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
|
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
|
||||||
ToolCallId = toolResult.Id,
|
ToolCallId = toolResult.Id,
|
||||||
FunctionName = toolResult.Name,
|
FunctionName = toolResult.Name,
|
||||||
FunctionArgs = JsonSerializer.Serialize(toolResult.Input)
|
FunctionArgs = JsonSerializer.Serialize(toolResult.Input),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -161,7 +161,7 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
new ToolResultContent()
|
new ToolResultContent()
|
||||||
{
|
{
|
||||||
ToolUseId = conv.ToolCallId,
|
ToolUseId = conv.ToolCallId,
|
||||||
Content = conv.Content
|
Content = [new TextContent() { Text = conv.Content }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
|
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
|
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
|
||||||
{
|
{
|
||||||
CurrentAgentId = agent.Id,
|
CurrentAgentId = agent.Id,
|
||||||
|
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
|
||||||
FunctionName = toolCall?.FunctionName,
|
FunctionName = toolCall?.FunctionName,
|
||||||
FunctionArgs = toolCall?.FunctionArguments?.ToString()
|
FunctionArgs = toolCall?.FunctionArguments?.ToString()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,8 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
||||||
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
|
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
|
||||||
message.FunctionArgs = message.FunctionArgs ?? "{}";
|
message.FunctionArgs = message.FunctionArgs ?? "{}";
|
||||||
var args = message.FunctionArgs.FormatJson();
|
var args = message.FunctionArgs.FormatJson();
|
||||||
var log = $"{message.FunctionName} <u>executing</u>\r\n```json\r\n{args}\r\n```";
|
var log = $"*{message.Indication.Replace("\r", string.Empty).Replace("\n", string.Empty)}* \r\n\r\n **{message.FunctionName}**()";
|
||||||
|
log += args.Length > 5 ? $" \r\n```json\r\n{args}\r\n```" : string.Empty;
|
||||||
|
|
||||||
var input = new ContentLogInputModel(conversationId, message)
|
var input = new ContentLogInputModel(conversationId, message)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using BotSharp.Abstraction.Agents;
|
using BotSharp.Abstraction.Agents;
|
||||||
using BotSharp.Abstraction.Agents.Enums;
|
using BotSharp.Abstraction.Agents.Enums;
|
||||||
using BotSharp.Abstraction.Loggers;
|
using BotSharp.Abstraction.Loggers;
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Mscc.GenerativeAI;
|
using Mscc.GenerativeAI;
|
||||||
|
|
||||||
|
|
@ -125,6 +126,7 @@ public class GeminiChatCompletionProvider : IChatCompletion
|
||||||
if (!agentService.RenderFunction(agent, function)) continue;
|
if (!agentService.RenderFunction(agent, function)) continue;
|
||||||
|
|
||||||
var def = agentService.RenderFunctionProperty(agent, function);
|
var def = agentService.RenderFunctionProperty(agent, function);
|
||||||
|
var str = JsonSerializer.Serialize(def.Properties);
|
||||||
|
|
||||||
funcDeclarations.Add(new FunctionDeclaration
|
funcDeclarations.Add(new FunctionDeclaration
|
||||||
{
|
{
|
||||||
|
|
@ -132,8 +134,8 @@ public class GeminiChatCompletionProvider : IChatCompletion
|
||||||
Description = function.Description,
|
Description = function.Description,
|
||||||
Parameters = new()
|
Parameters = new()
|
||||||
{
|
{
|
||||||
Type = ParameterType.Object,
|
Type = str != "{}" ? ParameterType.Object : ParameterType.TypeUnspecified,
|
||||||
Properties = def.Properties,
|
Properties = str != "{}" ? JsonSerializer.Deserialize<dynamic>(str) : null,
|
||||||
Required = def.Required
|
Required = def.Required
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="OpenAI" Version="2.0.0" />
|
<PackageReference Include="OpenAI" Version="2.1.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ public class ChatCompletionProvider : IChatCompletion
|
||||||
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
|
var funcContextIn = new RoleDialogModel(AgentRole.Function, text)
|
||||||
{
|
{
|
||||||
CurrentAgentId = agent.Id,
|
CurrentAgentId = agent.Id,
|
||||||
|
MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty,
|
||||||
ToolCallId = toolCall?.Id,
|
ToolCallId = toolCall?.Id,
|
||||||
FunctionName = toolCall?.FunctionName,
|
FunctionName = toolCall?.FunctionName,
|
||||||
FunctionArgs = toolCall?.FunctionArguments?.ToString()
|
FunctionArgs = toolCall?.FunctionArguments?.ToString()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue