Skip to content

Commit c736186

Browse files
committed
add chat context to chart
1 parent c00391c commit c736186

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
2+
using BotSharp.Abstraction.Routing;
3+
using System.Linq;
24

35
namespace BotSharp.Plugin.ChartHandler.Functions;
46

@@ -26,6 +28,7 @@ public async Task<bool> Execute(RoleDialogModel message)
2628
{
2729
var agentService = _services.GetRequiredService<IAgentService>();
2830
var convService = _services.GetRequiredService<IConversationService>();
31+
var routingCtx = _services.GetRequiredService<IRoutingContext>();
2932

3033
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
3134

@@ -44,15 +47,21 @@ public async Task<bool> Execute(RoleDialogModel message)
4447
}
4548
};
4649

47-
var response = await GetChatCompletion(innerAgent,
48-
[
49-
new RoleDialogModel(AgentRole.User, "Please follow the instruction to generate the javascript code.")
50-
{
51-
CurrentAgentId = message.CurrentAgentId,
52-
MessageId = message.MessageId
53-
}
54-
]);
50+
var dialogs = routingCtx.GetDialogs();
51+
if (dialogs.IsNullOrEmpty())
52+
{
53+
dialogs = convService.GetDialogHistory();
54+
}
55+
56+
var messageLimit = _settings.ChartPlot?.MessageLimit > 0 ? _settings.ChartPlot.MessageLimit.Value : 50;
57+
dialogs = dialogs.TakeLast(messageLimit).ToList();
58+
dialogs.Add(new RoleDialogModel(AgentRole.User, "Please follow the instruction and chat context to generate valid javascript code.")
59+
{
60+
CurrentAgentId = message.CurrentAgentId,
61+
MessageId = message.MessageId
62+
});
5563

64+
var response = await GetChatCompletion(innerAgent, dialogs);
5665
var obj = response.JsonContent<LlmContextOut>();
5766
message.Content = obj?.GreetingMessage ?? "Here is the chart you ask for:";
5867
message.RichContent = new RichContent<IRichMessage>

src/Plugins/BotSharp.Plugin.ChartHandler/Settings/ChartHandlerSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public class ChartPlotSetting
1111
public string? LlmModel { get; set; }
1212
public int? MaxOutputTokens { get; set; }
1313
public string? ReasoningEffortLevel { get; set; }
14+
public int? MessageLimit { get; set; }
1415
}

src/Plugins/BotSharp.Plugin.ChartHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-chart-plot_instruction.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ You must output the response in the following JSON format:
4242
{
4343
"greeting_message": "A short polite message that informs user that the charts have been generated.",
4444
"js_code": "The javascript code that can generate the charts as requested.",
45-
"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."
45+
"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."
4646
}

0 commit comments

Comments
 (0)