Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/refine-function-indication
This commit is contained in:
commit
c89ef9df70
11
BotSharp.sln
11
BotSharp.sln
|
|
@ -143,6 +143,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.LLM.Tests", "tests
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Test.RealtimeVoice", "tests\BotSharp.Test.RealtimeVoice\BotSharp.Test.RealtimeVoice.csproj", "{B067B126-88CD-4282-BEEF-7369B64423EF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.ChartHandler", "src\Plugins\BotSharp.Plugin.ChartHandler\BotSharp.Plugin.ChartHandler.csproj", "{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -599,6 +601,14 @@ Global
|
|||
{B067B126-88CD-4282-BEEF-7369B64423EF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B067B126-88CD-4282-BEEF-7369B64423EF}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B067B126-88CD-4282-BEEF-7369B64423EF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -668,6 +678,7 @@ Global
|
|||
{7D0DB012-9798-4BB9-B15B-A5B0B7B3B094} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||
{7C0C7D13-D161-4AB0-9C29-83A0F1FF990E} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||
{B067B126-88CD-4282-BEEF-7369B64423EF} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||
{0428DEAA-E4FE-4259-A6D8-6EDD1A9D0702} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
using System.Text.Json;
|
||||
using System.Reflection;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
|
||||
namespace BotSharp.Abstraction.Messaging;
|
||||
|
||||
|
|
@ -38,6 +38,10 @@ public static class BotSharpMessageParser
|
|||
{
|
||||
targetType = typeof(TextMessage);
|
||||
}
|
||||
else if (richType == RichTypeEnum.ProgramCode)
|
||||
{
|
||||
targetType = typeof(ProgramCodeTemplateMessage);
|
||||
}
|
||||
else if (richType == RichTypeEnum.GenericTemplate)
|
||||
{
|
||||
if (root.TryGetProperty("element_type", out element))
|
||||
|
|
@ -84,9 +88,9 @@ public static class BotSharpMessageParser
|
|||
{
|
||||
targetType = typeof(CouponTemplateMessage);
|
||||
}
|
||||
else if (templateType == TemplateTypeEnum.Product)
|
||||
else if (templateType == TemplateTypeEnum.ProgramCode)
|
||||
{
|
||||
targetType = typeof(ProductTemplateMessage);
|
||||
targetType = typeof(ProgramCodeTemplateMessage);
|
||||
}
|
||||
else if (templateType == TemplateTypeEnum.Generic)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ public static class RichTypeEnum
|
|||
public const string QuickReply = "quick_reply";
|
||||
public const string Text = "text";
|
||||
public const string Attachment = "attachment";
|
||||
public const string ProgramCode = "program_code";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ public static class TemplateTypeEnum
|
|||
public const string Coupon = "coupon";
|
||||
public const string Generic = "generic";
|
||||
public const string MultiSelect = "multi-select";
|
||||
public const string Product = "product";
|
||||
public const string ProgramCode = "program_code";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
|
||||
public class ProductTemplateMessage : IRichMessage, ITemplateMessage
|
||||
{
|
||||
[JsonPropertyName("rich_type")]
|
||||
public string RichType => RichTypeEnum.GenericTemplate;
|
||||
|
||||
[JsonPropertyName("text")]
|
||||
[Translate]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("template_type")]
|
||||
public string TemplateType => TemplateTypeEnum.Product;
|
||||
}
|
||||
|
||||
public class ProductElement
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
|
||||
public class ProgramCodeTemplateMessage : IRichMessage, ITemplateMessage
|
||||
{
|
||||
[JsonPropertyName("rich_type")]
|
||||
public string RichType => RichTypeEnum.ProgramCode;
|
||||
|
||||
[JsonPropertyName("text")]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("template_type")]
|
||||
public virtual string TemplateType { get; set; } = TemplateTypeEnum.ProgramCode;
|
||||
|
||||
[JsonPropertyName("language")]
|
||||
public string Language { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
@ -3,6 +3,4 @@ namespace BotSharp.Abstraction.Plugins;
|
|||
public class PluginSettings
|
||||
{
|
||||
public string[] Assemblies { get; set; } = new string[0];
|
||||
|
||||
public string[] ExcludedFunctions { get; set; } = new string[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@
|
|||
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\conversation.summary.liquid" />
|
||||
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\response_with_function.liquid" />
|
||||
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\translation_prompt.liquid" />
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\select_file_prompt.liquid" />
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-routing-fallback_to_router.fn.liquid" />
|
||||
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\agent.json" />
|
||||
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\instructions\instruction.liquid" />
|
||||
|
|
@ -97,6 +96,7 @@
|
|||
<None Remove="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.simulator.liquid" />
|
||||
<None Remove="data\plugins\config.json" />
|
||||
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-file-select_file_instruction.liquid" />
|
||||
<None Remove="data\agents\01e2fc5c-2c89-4ec7-8470-7688608b496c\functions\get_weather.json" />
|
||||
<None Remove="data\agents\01e2fc5c-2c89-4ec7-8470-7688608b496c\functions\get_fun_events.json" />
|
||||
</ItemGroup>
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\instructions\instruction.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\select_file_prompt.liquid">
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-file-select_file_instruction.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\dfd9b46d-d00c-40af-8a75-3fbdc2b89869\templates\instruction.simulator.liquid">
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ public static class BotSharpCoreExtensions
|
|||
{
|
||||
var pluginSettings = new PluginSettings();
|
||||
config.Bind("PluginLoader", pluginSettings);
|
||||
var excludedFunctions = pluginSettings.ExcludedFunctions ?? [];
|
||||
|
||||
services.AddScoped(provider =>
|
||||
{
|
||||
|
|
@ -143,8 +142,7 @@ public static class BotSharpCoreExtensions
|
|||
// Register function callback
|
||||
var functions = assembly.GetTypes()
|
||||
.Where(x => x.IsClass
|
||||
&& x.GetInterface(nameof(IFunctionCallback)) != null
|
||||
&& !excludedFunctions.Contains(x.Name))
|
||||
&& x.GetInterface(nameof(IFunctionCallback)) != null)
|
||||
.ToArray();
|
||||
|
||||
foreach (var function in functions)
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public partial class FileInstructService
|
|||
}).ToList();
|
||||
|
||||
var agentId = !string.IsNullOrWhiteSpace(options.AgentId) ? options.AgentId : BuiltInAgentId.UtilityAssistant;
|
||||
var template = !string.IsNullOrWhiteSpace(options.Template) ? options.Template : "select_file_prompt";
|
||||
var template = !string.IsNullOrWhiteSpace(options.Template) ? options.Template : "util-file-select_file_instruction";
|
||||
|
||||
var foundAgent = db.GetAgent(agentId);
|
||||
var prompt = db.GetAgentTemplate(BuiltInAgentId.UtilityAssistant, template);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-chart-plot_chart.json" />
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-chart-plot_chart.fn.liquid" />
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-chart-plot_instruction.liquid" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-chart-plot_chart.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-chart-plot_chart.fn.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-chart-plot_instruction.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BotSharp.Plugin.ChartHandler;
|
||||
|
||||
public class ChartHandlerPlugin : IBotSharpPlugin
|
||||
{
|
||||
public string Id => "9dacac1d-2e29-4f01-9d66-b0201f05a9fa";
|
||||
public string Name => "Chart Plotter";
|
||||
public string Description => "AI plots chart";
|
||||
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/423/423786.png";
|
||||
public string[] AgentIds => [];
|
||||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddScoped<IAgentUtilityHook, ChartHandlerUtilityHook>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Plugin.ChartHandler.Enums;
|
||||
|
||||
public class UtilityName
|
||||
{
|
||||
public const string ChartPlotter = "chart-plotter";
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
|
||||
namespace BotSharp.Plugin.ChartHandler.Functions;
|
||||
|
||||
public class PlotChartFn : IFunctionCallback
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger<PlotChartFn> _logger;
|
||||
|
||||
public string Name => "util-chart-plot_chart";
|
||||
public string Indication => "Plotting chart";
|
||||
|
||||
|
||||
public PlotChartFn(
|
||||
IServiceProvider services,
|
||||
ILogger<PlotChartFn> logger)
|
||||
{
|
||||
_services = services;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
|
||||
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
|
||||
var agent = await agentService.GetAgent(message.CurrentAgentId);
|
||||
var inst = db.GetAgentTemplate(BuiltInAgentId.UtilityAssistant, "util-chart-plot_instruction");
|
||||
var innerAgent = new Agent
|
||||
{
|
||||
Id = agent.Id,
|
||||
Name = agent.Name,
|
||||
Instruction = inst,
|
||||
TemplateDict = new Dictionary<string, object>
|
||||
{
|
||||
{ "plotting_requirement", args?.PlottingRequirement ?? string.Empty },
|
||||
{ "chart_element_id", $"chart-{message.MessageId}" }
|
||||
}
|
||||
};
|
||||
|
||||
var response = await GetChatCompletion(innerAgent, [
|
||||
new RoleDialogModel(AgentRole.User, "Please follow the instruction to generate the javascript code.")
|
||||
{
|
||||
CurrentAgentId = message.CurrentAgentId,
|
||||
MessageId = message.MessageId
|
||||
}
|
||||
]);
|
||||
|
||||
var obj = response.JsonContent<LlmContextOut>();
|
||||
message.Content = obj?.GreetingMessage ?? "Here is the chart you ask for:";
|
||||
message.RichContent = new RichContent<IRichMessage>
|
||||
{
|
||||
Recipient = new Recipient { Id = convService.ConversationId },
|
||||
Message = new ProgramCodeTemplateMessage
|
||||
{
|
||||
Text = obj?.JsCode ?? string.Empty,
|
||||
Language = "javascript"
|
||||
}
|
||||
};
|
||||
message.StopCompletion = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<string> GetChatCompletion(Agent agent, List<RoleDialogModel> dialogs)
|
||||
{
|
||||
try
|
||||
{
|
||||
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
|
||||
var completion = CompletionProvider.GetChatCompletion(_services, provider: "openai", model: "gpt-4.1");
|
||||
var response = await completion.GetChatCompletions(agent, dialogs);
|
||||
return response.Content;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var error = $"Error when plotting chart. {ex.Message}";
|
||||
_logger.LogWarning(ex, error);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
namespace BotSharp.Plugin.ChartHandler.Hooks;
|
||||
|
||||
public class ChartHandlerUtilityHook : IAgentUtilityHook
|
||||
{
|
||||
private const string PLOT_CHART_FN = "util-chart-plot_chart";
|
||||
|
||||
public void AddUtilities(List<AgentUtility> utilities)
|
||||
{
|
||||
var item = new AgentUtility
|
||||
{
|
||||
Category = "chart",
|
||||
Name = UtilityName.ChartPlotter,
|
||||
Items = [
|
||||
new UtilityItem
|
||||
{
|
||||
FunctionName = PLOT_CHART_FN,
|
||||
TemplateName = $"{PLOT_CHART_FN}.fn"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
utilities.Add(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Plugin.ChartHandler.LlmContext;
|
||||
|
||||
public class LlmContextIn
|
||||
{
|
||||
[JsonPropertyName("plotting_requirement")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? PlottingRequirement { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Plugin.ChartHandler.LlmContext;
|
||||
|
||||
public class LlmContextOut
|
||||
{
|
||||
[JsonPropertyName("greeting_message")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? GreetingMessage { get; set; }
|
||||
|
||||
[JsonPropertyName("js_code")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? JsCode { get; set; }
|
||||
}
|
||||
32
src/Plugins/BotSharp.Plugin.ChartHandler/Using.cs
Normal file
32
src/Plugins/BotSharp.Plugin.ChartHandler/Using.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Text;
|
||||
global using System.Linq;
|
||||
global using System.Text.Json;
|
||||
global using System.Net.Mime;
|
||||
global using System.Threading.Tasks;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
global using BotSharp.Abstraction.Agents;
|
||||
global using BotSharp.Abstraction.Conversations;
|
||||
global using BotSharp.Abstraction.Plugins;
|
||||
global using BotSharp.Abstraction.Conversations.Models;
|
||||
global using BotSharp.Abstraction.Functions;
|
||||
global using BotSharp.Abstraction.Agents.Models;
|
||||
global using BotSharp.Abstraction.Agents.Enums;
|
||||
global using BotSharp.Abstraction.Files.Enums;
|
||||
global using BotSharp.Abstraction.Files.Models;
|
||||
global using BotSharp.Abstraction.Files;
|
||||
global using BotSharp.Abstraction.MLTasks;
|
||||
global using BotSharp.Abstraction.Utilities;
|
||||
global using BotSharp.Abstraction.Agents.Settings;
|
||||
global using BotSharp.Abstraction.Functions.Models;
|
||||
global using BotSharp.Abstraction.Repositories;
|
||||
global using BotSharp.Abstraction.Settings;
|
||||
global using BotSharp.Abstraction.Messaging;
|
||||
global using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
global using BotSharp.Abstraction.Options;
|
||||
global using BotSharp.Core.Infrastructures;
|
||||
global using BotSharp.Plugin.ChartHandler.Enums;
|
||||
global using BotSharp.Plugin.ChartHandler.LlmContext;
|
||||
global using BotSharp.Plugin.ChartHandler.Hooks;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "util-chart-plot_chart",
|
||||
"description": "If the user requests you plotting or generating charts, you can call this function to generate charts in any format that user requested.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"plotting_requirement": {
|
||||
"type": "string",
|
||||
"description": "The requirement that user posted for plotting or generating charts."
|
||||
}
|
||||
},
|
||||
"required": [ "plotting_requirement" ]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Please call function util-chart-plot_chart if user wants to plot or generate charts.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Please take a look at "Plotting Requirement" and generate a javascript code that can be used to render the charts on an html element.
|
||||
|
||||
|
||||
=== Plotting Requirement ===
|
||||
{{ plotting_requirement }}
|
||||
|
||||
|
||||
***** Important *****
|
||||
** Your output must be a single <script>...</script> block with everything needed inside.
|
||||
** You need to import Plotly.js to plot the charts. The script source should be "https://cdn.plot.ly/plotly-3.0.1.min.js".
|
||||
** You need to add the MODE bar for each chart you plot.
|
||||
** You must render the charts on the div html element with id {{ chart_element_id }}.
|
||||
** You must not create any new html element.
|
||||
** You must not apply any styles on any html element.
|
||||
** You must generate as less token as possible.
|
||||
|
||||
*** Response Format ***
|
||||
You must output the response in the following JSON format:
|
||||
{
|
||||
"greeting_message": "A short polite message that informs user that the charts have been generated.",
|
||||
"js_code": "The javascript code that can generate the charts as requested."
|
||||
}
|
||||
|
|
@ -45,7 +45,6 @@ public class ChatHubConversationHook : ConversationHookBase
|
|||
var user = await userService.GetUser(conv.User.Id);
|
||||
conv.User = UserDto.FromUser(user);
|
||||
|
||||
//await InitClientConversation(conv.Id, conv);
|
||||
await SendEvent(ChatEvent.OnConversationInitFromClient, conv.Id, conv);
|
||||
await base.OnConversationInitialized(conversation);
|
||||
}
|
||||
|
|
@ -172,7 +171,8 @@ public class ChatHubConversationHook : ConversationHookBase
|
|||
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
|
||||
{
|
||||
var user = _services.GetRequiredService<IUserIdentity>();
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubConversationHook), callerName);
|
||||
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubConversationHook), callerName);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ public class ChatHubCrontabHook : ICrontabHook
|
|||
{
|
||||
try
|
||||
{
|
||||
await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, data);
|
||||
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
|
||||
await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, json);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.UserInput,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +79,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.UserInput,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +108,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.Prompt,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +130,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.HardRule,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +158,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.FunctionCall,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +179,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.FunctionCall,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +206,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
Source = ContentLogSource.Prompt,
|
||||
Log = log
|
||||
};
|
||||
//await SendContentLog(conversationId, input);
|
||||
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
|
||||
}
|
||||
|
||||
|
|
@ -477,7 +470,8 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
|
||||
{
|
||||
var user = _services.GetRequiredService<IUserIdentity>();
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(StreamingLogHook), callerName);
|
||||
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(StreamingLogHook), callerName);
|
||||
}
|
||||
|
||||
private ContentLogOutputModel BuildContentLog(ContentLogInputModel input)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public class WelcomeHook : ConversationHookBase
|
|||
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
|
||||
{
|
||||
var user = _services.GetRequiredService<IUserIdentity>();
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(WelcomeHook), callerName);
|
||||
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
|
||||
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(WelcomeHook), callerName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,17 @@ namespace BotSharp.Plugin.ChatHub.Observers;
|
|||
|
||||
public class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogModel>>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly BotSharpOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ChatHubObserver(
|
||||
IServiceProvider services,
|
||||
BotSharpOptions options,
|
||||
ILogger<ChatHubObserver> logger) : base()
|
||||
{
|
||||
_services = services;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +136,8 @@ public class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogMod
|
|||
private void SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
|
||||
{
|
||||
var user = _services.GetRequiredService<IUserIdentity>();
|
||||
EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubObserver), callerName)
|
||||
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
|
||||
EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubObserver), callerName)
|
||||
.ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(TargetFramework)</TargetFramework>
|
||||
|
|
@ -9,10 +9,6 @@
|
|||
<GenerateDocumentationFile>$(GenerateDocumentationFile)</GenerateDocumentationFile>
|
||||
<OutputPath>$(SolutionDir)packages</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\select_edit_image_prompt.liquid" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-file-generate_image.json" />
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@ public class LlmContextIn
|
|||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? ImageDescription { get; set; }
|
||||
|
||||
//[JsonPropertyName("image_url")]
|
||||
//[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
//public string? ImageUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("image_urls")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public IEnumerable<string>? ImageUrls { get; set; }
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj" />
|
||||
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="$(SolutionName)==BotSharp">
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Rules\BotSharp.Core.Rules.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.Crontab\BotSharp.Core.Crontab.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core.SideCar\BotSharp.Core.SideCar.csproj" />
|
||||
|
|
@ -75,6 +75,7 @@
|
|||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.FileHandler\BotSharp.Plugin.FileHandler.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.EmailHandler\BotSharp.Plugin.EmailHandler.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.AudioHandler\BotSharp.Plugin.AudioHandler.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.ChartHandler\BotSharp.Plugin.ChartHandler.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MetaGLM\BotSharp.Plugin.MetaGLM.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.Planner\BotSharp.Plugin.Planner.csproj" />
|
||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.TencentCos\BotSharp.Plugin.TencentCos.csproj" />
|
||||
|
|
|
|||
|
|
@ -539,10 +539,8 @@
|
|||
"BotSharp.Plugin.FileHandler",
|
||||
"BotSharp.Plugin.EmailHandler",
|
||||
"BotSharp.Plugin.AudioHandler",
|
||||
"BotSharp.Plugin.ChartHandler",
|
||||
"BotSharp.Plugin.TencentCos"
|
||||
],
|
||||
"ExcludedFunctions": [
|
||||
"McpToolAdapter"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue