Merge pull request #639 from Joannall/master
update data assistant - DDL and execution hook
This commit is contained in:
commit
b5f7062ce6
|
|
@ -30,18 +30,23 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
// Get table names
|
||||
var steps = message.Content.JsonArrayContent<SecondStagePlan>();
|
||||
var allTables = new List<string>();
|
||||
var ddlStatements = "";
|
||||
var relevantKnowledge = message.Content;
|
||||
foreach (var step in steps)
|
||||
{
|
||||
allTables.AddRange(step.Tables);
|
||||
}
|
||||
message.Data = allTables.Distinct().ToList();
|
||||
|
||||
// Get table DDL statements
|
||||
var msgCopy = RoleDialogModel.From(message);
|
||||
await fn.InvokeFunction("get_table_definition", msgCopy);
|
||||
var ddlStatements = msgCopy.Content;
|
||||
var relevantKnowledge = message.Content;
|
||||
message.Data = null;
|
||||
var distinctTables = allTables.Distinct().ToList();
|
||||
foreach (var table in distinctTables)
|
||||
{
|
||||
var msgCopy = RoleDialogModel.From(message);
|
||||
msgCopy.FunctionArgs = JsonSerializer.Serialize(new
|
||||
{
|
||||
table = table,
|
||||
});
|
||||
await fn.InvokeFunction("get_table_definition", msgCopy);
|
||||
ddlStatements += "\r\n" + msgCopy.Content;
|
||||
}
|
||||
|
||||
// Summarize and generate query
|
||||
var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, ddlStatements);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
Use the TwoStagePlanner approach to plan the overall implementation steps, call plan_primary_stage.
|
||||
If need_additional_information is true, call plan_secondary_stage for the specific primary stage.
|
||||
You must call plan_summary as the last planning step to summarize the final query.
|
||||
You must generate the final sql statement from function of plan_summary.
|
||||
Use the TwoStagePlanner approach to plan the overall implementation steps, follow the below steps strictly.
|
||||
1. call plan_primary_stage to generate the primary plan.
|
||||
2. If need_additional_information is true, call plan_secondary_stage for the specific primary stage.
|
||||
3. You must call plan_summary as the last planning step to summarize the final query.
|
||||
|
||||
{% if global_knowledges != empty -%}
|
||||
=====
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Thinking process:
|
|||
- You should find the relationships between data structure based on the task knowledge strictly. If lack of information, set the need_additional_information to true.
|
||||
3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@';
|
||||
4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}]
|
||||
5. Don't organize and format the extracted data with any other language rather than sql
|
||||
5. You can NOT generate the final query before calling function plan_summary.
|
||||
|
||||
Note:If the task includes repeat steps,e.g.same steps for multiple elements, only generate a single detailed solution without repeating steps for each elements. You can add multiple items in the input and output args.
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\get_table_definition.fn.liquid" />
|
||||
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\sql_executor.fn.liquid" />
|
||||
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\agent.json" />
|
||||
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_columns.json" />
|
||||
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\lookup_dictionary.json" />
|
||||
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json" />
|
||||
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_select.json" />
|
||||
|
|
@ -25,7 +24,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\get_table_definition.json">
|
||||
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_definition.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\get_table_definition.fn.liquid">
|
||||
|
|
@ -40,10 +39,7 @@
|
|||
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\lookup_dictionary.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_columns.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\lookup_dictionary.json">
|
||||
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\lookup_dictionary.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json">
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
using BotSharp.Abstraction.Repositories;
|
||||
using BotSharp.Plugin.SqlDriver.Models;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Plugin.SqlDriver.Functions;
|
||||
|
||||
public class GetTableColumnsFn : IFunctionCallback
|
||||
{
|
||||
public string Name => "get_table_columns";
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public GetTableColumnsFn(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
{
|
||||
var args = JsonSerializer.Deserialize<GetTableColumnsArgs>(message.FunctionArgs);
|
||||
message.Content = "";
|
||||
|
||||
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
|
||||
var dir = Path.Combine(dbSettings.FileRepository, "agents", "beda4c12-e1ec-4b4b-b328-3df4a6687c4f", "schemas");
|
||||
|
||||
// Search related document by message.Content + args.Description
|
||||
var files = Directory.GetFiles(dir);
|
||||
foreach (var file in files)
|
||||
{
|
||||
var fileName = file.Split(Path.DirectorySeparatorChar).Last();
|
||||
if (fileName.Split('.').First() == args.Table)
|
||||
{
|
||||
message.Content += File.ReadAllText(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "beda4c12-e1ec-4b4b-b328-3df4a6687c4f",
|
||||
"name": "SQL Driver",
|
||||
"description": "Runs the specified SQL statement and returns the result.",
|
||||
"description": "Execute the sql query in database from the latest dialog.",
|
||||
"type": "task",
|
||||
"createdDateTime": "2023-11-15T13:49:00Z",
|
||||
"updatedDateTime": "2023-11-15T13:49:00Z",
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "get_table_columns",
|
||||
"description": "Get related table columns and foreign key informations",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"table": {
|
||||
"type": "string",
|
||||
"description": "table name"
|
||||
}
|
||||
},
|
||||
"required": [ "table" ]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
You're a SQL driver who knows how to translate text into SQL query.
|
||||
Think step by step, analyze the user requirement, you must get table schema first, breakdown into multiple sql statements if user need to insert mulitple records.
|
||||
Output the next step smartly.
|
||||
You're a SQL driver who can find the database information or query the data.
|
||||
|
||||
Your response must meet below requirements:
|
||||
* Walk through the provided information, don't run query if there is already related information;
|
||||
* Make sure you have the corresponding table columns information before generating SQL;
|
||||
* You can only execute the SQL from the conversation. You can't generate one by yourself;
|
||||
* The return field alias should be meaningful, you can use the combination of column and value as the alias name;
|
||||
* Use "Unique Index" to help check record existence;
|
||||
|
|
|
|||
Loading…
Reference in a new issue