minor change
This commit is contained in:
parent
a89f8febe6
commit
797b8abeba
|
|
@ -1,4 +1,3 @@
|
|||
using BotSharp.Abstraction.Knowledges.Models;
|
||||
using BotSharp.Plugin.Planner.TwoStaging.Models;
|
||||
|
||||
namespace BotSharp.Plugin.Planner.Functions;
|
||||
|
|
@ -26,21 +25,18 @@ public class PrimaryStagePlanFn : IFunctionCallback
|
|||
|
||||
state.SetState("max_tokens", "4096");
|
||||
var task = JsonSerializer.Deserialize<PrimaryRequirementRequest>(message.FunctionArgs);
|
||||
var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp;
|
||||
|
||||
//get knowledge from vectordb
|
||||
// Get knowledge from vectordb
|
||||
var knowledges = new List<string>();
|
||||
foreach (var question in task.Questions)
|
||||
{
|
||||
var retrievalMessage = new RoleDialogModel(AgentRole.User, question)
|
||||
var list = await knowledgeService.SearchVectorKnowledge(question, collectionName, new VectorSearchOptions
|
||||
{
|
||||
FunctionArgs = JsonSerializer.Serialize(new ExtractedKnowledge
|
||||
{
|
||||
Question = question
|
||||
}),
|
||||
Content = ""
|
||||
};
|
||||
await fn.InvokeFunction("knowledge_retrieval", retrievalMessage);
|
||||
knowledges.Add(retrievalMessage.Content);
|
||||
Confidence = 0.2f
|
||||
});
|
||||
|
||||
knowledges.Add(string.Join("\r\n\r\n=====\r\n", list.Select(x => x.ToQuestionAnswer())));
|
||||
}
|
||||
|
||||
// Get first stage planning prompt
|
||||
|
|
@ -66,8 +62,8 @@ public class PrimaryStagePlanFn : IFunctionCallback
|
|||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
var knowledgeHooks = _services.GetServices<IKnowledgeHook>();
|
||||
|
||||
var aiAssistant = await agentService.GetAgent(BuiltInAgentId.Planner);
|
||||
var template = aiAssistant.Templates.FirstOrDefault(x => x.Name == "two_stage.1st.plan")?.Content ?? string.Empty;
|
||||
var agent = await agentService.GetAgent(BuiltInAgentId.Planner);
|
||||
var template = agent.Templates.FirstOrDefault(x => x.Name == "two_stage.1st.plan")?.Content ?? string.Empty;
|
||||
var responseFormat = JsonSerializer.Serialize(new FirstStagePlan
|
||||
{
|
||||
Parameters = [ JsonDocument.Parse("{}") ],
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ public class SecondaryStagePlanFn : IFunctionCallback
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var knowledgeService = _services.GetRequiredService<IKnowledgeService>();
|
||||
var knowledgeSettings = _services.GetRequiredService<KnowledgeBaseSettings>();
|
||||
var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp;
|
||||
|
||||
|
||||
var msgSecondary = RoleDialogModel.From(message);
|
||||
var taskPrimary = JsonSerializer.Deserialize<PrimaryRequirementRequest>(message.FunctionArgs);
|
||||
var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp;
|
||||
|
||||
msgSecondary.FunctionArgs = JsonSerializer.Serialize(new SecondaryBreakdownTask
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
||||
var currentAgent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||
state.SetState("max_tokens", "4096");
|
||||
|
||||
var currentAgent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||
var taskRequirement = state.GetState("requirement_detail");
|
||||
|
||||
// Get table names
|
||||
|
|
@ -45,7 +44,7 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
message.Data = null;
|
||||
|
||||
// Summarize and generate query
|
||||
var summaryPlanPrompt = await GetPlanSummaryPrompt(taskRequirement, relevantKnowledge, ddlStatements);
|
||||
var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, ddlStatements);
|
||||
_logger.LogInformation($"Summary plan prompt:\r\n{summaryPlanPrompt}");
|
||||
|
||||
var plannerAgent = new Agent
|
||||
|
|
@ -63,7 +62,7 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<string> GetPlanSummaryPrompt(string taskDescription, string relevantKnowledge, string ddlStatement)
|
||||
private async Task<string> GetSummaryPlanPrompt(string taskDescription, string relevantKnowledge, string ddlStatement)
|
||||
{
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class GetTableDefinitionFn : IFunctionCallback
|
|||
var settings = _services.GetRequiredService<SqlDriverSetting>();
|
||||
|
||||
// Get table DDL from database
|
||||
var tables = message.Data as List<string>;
|
||||
var tables = message.Data as IEnumerable<string>;
|
||||
if (tables.IsNullOrEmpty()) return false;
|
||||
|
||||
var tableDdls = new List<string>();
|
||||
|
|
@ -36,9 +36,9 @@ public class GetTableDefinitionFn : IFunctionCallback
|
|||
{
|
||||
try
|
||||
{
|
||||
var sql = $"select * from information_schema.tables where table_name = @tableName";
|
||||
var escapedTableName = MySqlHelper.EscapeString(table);
|
||||
|
||||
var sql = $"select * from information_schema.tables where table_name = @tableName";
|
||||
var result = connection.QueryFirstOrDefault(sql, new
|
||||
{
|
||||
tableName = escapedTableName
|
||||
|
|
@ -60,7 +60,7 @@ public class GetTableDefinitionFn : IFunctionCallback
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Error when getting ddl statement of table {table}.");
|
||||
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue