Skip to content

refine code #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public async Task<bool> Execute(RoleDialogModel message)
var ddlStatements = string.Empty;
var relevantKnowledge = states.GetState("planning_result");
var dictionaryItems = states.GetState("dictionary_items");
var items = new List<string>();
if (!string.IsNullOrWhiteSpace(dictionaryItems))
{
items = JsonSerializer.Deserialize<List<string>>(dictionaryItems);
}

foreach (var step in steps)
{
Expand All @@ -60,7 +55,7 @@ public async Task<bool> Execute(RoleDialogModel message)
}

// Summarize and generate query
var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, items, ddlStatements);
var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, dictionaryItems, ddlStatements);
_logger.LogInformation($"Summary plan prompt:\r\n{summaryPlanPrompt}");

var plannerAgent = new Agent
Expand All @@ -80,7 +75,7 @@ await HookEmitter.Emit<IPlanningHook>(_services, x =>
return true;
}

private async Task<string> GetSummaryPlanPrompt(string taskDescription, string relevantKnowledge, IEnumerable<string> dictionaryItems, string ddlStatement)
private async Task<string> GetSummaryPlanPrompt(string taskDescription, string relevantKnowledge, string dictionaryItems, string ddlStatement)
{
var agentService = _services.GetRequiredService<IAgentService>();
var render = _services.GetRequiredService<ITemplateRender>();
Expand All @@ -100,7 +95,7 @@ await HookEmitter.Emit<IPlanningHook>(_services, async x =>
{ "task_description", taskDescription },
{ "summary_requirements", string.Join("\r\n", additionalRequirements) },
{ "relevant_knowledges", relevantKnowledge },
{ "dictionary_items", string.Join("\r\n\r\n", dictionaryItems) },
{ "dictionary_items", dictionaryItems },
{ "table_structure", ddlStatement },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,10 @@ public async Task<bool> Execute(RoleDialogModel message)
}

var states = _services.GetRequiredService<IConversationStateService>();
var dictionaryItems = states.GetState("dictionary_items");
var dictionaryItems = states.GetState("dictionary_items", "");
var newItem = BuildDictionaryItem(args.Table, args.Reason, message.Content);

var items = new List<string>();
if (!string.IsNullOrWhiteSpace(dictionaryItems))
{
items = JsonSerializer.Deserialize<List<string>>(dictionaryItems);
}

items.Add(newItem);
//dictionaryItems += "\r\n\r\n" + args.Table + ":\r\n" + args.Reason + ":\r\n" + message.Content + "\r\n";
states.SetState("dictionary_items", JsonSerializer.Serialize(items));
dictionaryItems += !string.IsNullOrWhiteSpace(newItem) ? $"\r\n{newItem}\r\n" : string.Empty;
states.SetState("dictionary_items", dictionaryItems);

return true;
}
Expand Down Expand Up @@ -105,24 +97,30 @@ private async Task<RoleDialogModel> GetAiResponse(Agent agent)

private string BuildDictionaryItem(string? table, string? reason, string? result)
{
var res = new List<string>();
var res = string.Empty;
if (!string.IsNullOrWhiteSpace(table))
{
res.Add($"Table: {table}");
res += $"Table: {table}";
}

if (!string.IsNullOrWhiteSpace(reason))
{
res.Add($"Reason: {reason}");
if (!string.IsNullOrWhiteSpace(res))
{
res += "\r\n";
}
res += $"Reason: {reason}";
}

if (!string.IsNullOrWhiteSpace(result))
{
res.Add($"Result: {result}");
if (!string.IsNullOrWhiteSpace(res))
{
res += "\r\n";
}
res += $"Result: {result}";
}

if (res.IsNullOrEmpty()) return string.Empty;

return string.Join("\r\n", res);
return res;
}
}