refine code
This commit is contained in:
parent
a0e7117e29
commit
e73374f563
|
|
@ -36,11 +36,6 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
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)
|
||||
{
|
||||
|
|
@ -60,7 +55,7 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
@ -80,7 +75,7 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
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>();
|
||||
|
|
@ -100,7 +95,7 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
{ "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 },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,18 +57,10 @@ public class LookupDictionaryFn : IFunctionCallback
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -105,24 +97,30 @@ public class LookupDictionaryFn : IFunctionCallback
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue