Skip to content

Commit 6fab3e0

Browse files
authored
Merge pull request #1162 from iceljc/master
add chat context
2 parents e32399f + e8c3c93 commit 6fab3e0

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
2+
using BotSharp.Abstraction.Routing;
23

34
namespace BotSharp.Plugin.ChartHandler.Functions;
45

@@ -26,6 +27,7 @@ public async Task<bool> Execute(RoleDialogModel message)
2627
{
2728
var agentService = _services.GetRequiredService<IAgentService>();
2829
var convService = _services.GetRequiredService<IConversationService>();
30+
var routingCtx = _services.GetRequiredService<IRoutingContext>();
2931

3032
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
3133

@@ -44,15 +46,21 @@ public async Task<bool> Execute(RoleDialogModel message)
4446
}
4547
};
4648

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

63+
var response = await GetChatCompletion(innerAgent, dialogs);
5664
var obj = response.JsonContent<LlmContextOut>();
5765
message.Content = obj?.GreetingMessage ?? "Here is the chart you ask for:";
5866
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)