add chat context to chart
This commit is contained in:
parent
c00391c18c
commit
c736186a9b
|
|
@ -1,4 +1,6 @@
|
|||
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using System.Linq;
|
||||
|
||||
namespace BotSharp.Plugin.ChartHandler.Functions;
|
||||
|
||||
|
|
@ -26,6 +28,7 @@ public class PlotChartFn : IFunctionCallback
|
|||
{
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
||||
|
||||
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
|
||||
|
||||
|
|
@ -44,15 +47,21 @@ public class PlotChartFn : IFunctionCallback
|
|||
}
|
||||
};
|
||||
|
||||
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 dialogs = routingCtx.GetDialogs();
|
||||
if (dialogs.IsNullOrEmpty())
|
||||
{
|
||||
dialogs = convService.GetDialogHistory();
|
||||
}
|
||||
|
||||
var messageLimit = _settings.ChartPlot?.MessageLimit > 0 ? _settings.ChartPlot.MessageLimit.Value : 50;
|
||||
dialogs = dialogs.TakeLast(messageLimit).ToList();
|
||||
dialogs.Add(new RoleDialogModel(AgentRole.User, "Please follow the instruction and chat context to generate valid javascript code.")
|
||||
{
|
||||
CurrentAgentId = message.CurrentAgentId,
|
||||
MessageId = message.MessageId
|
||||
});
|
||||
|
||||
var response = await GetChatCompletion(innerAgent, dialogs);
|
||||
var obj = response.JsonContent<LlmContextOut>();
|
||||
message.Content = obj?.GreetingMessage ?? "Here is the chart you ask for:";
|
||||
message.RichContent = new RichContent<IRichMessage>
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ public class ChartPlotSetting
|
|||
public string? LlmModel { get; set; }
|
||||
public int? MaxOutputTokens { get; set; }
|
||||
public string? ReasoningEffortLevel { get; set; }
|
||||
public int? MessageLimit { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,5 +42,5 @@ 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.",
|
||||
"report_summary": "Generate an insightful summary report in markdown format based on the data. Bold all key findings and use level-4 headings or smaller (####, #####, etc.) to structure the content with clear titles."
|
||||
"report_summary": "Generate an insightful summary report in markdown format based on the data. You can summarize using one or multiple titles and list the key findings under each title. Bold all key findings and use level-4 headings or smaller (####, #####, etc.). DO NOT make everything in one line."
|
||||
}
|
||||
Loading…
Reference in a new issue