Skip to content

Commit b5f7062

Browse files
authored
Merge pull request #639 from Joannall/master
update data assistant - DDL and execution hook
2 parents e968627 + e8f8691 commit b5f7062

File tree

10 files changed

+23
-77
lines changed

10 files changed

+23
-77
lines changed

src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ public async Task<bool> Execute(RoleDialogModel message)
3030
// Get table names
3131
var steps = message.Content.JsonArrayContent<SecondStagePlan>();
3232
var allTables = new List<string>();
33+
var ddlStatements = "";
34+
var relevantKnowledge = message.Content;
3335
foreach (var step in steps)
3436
{
3537
allTables.AddRange(step.Tables);
3638
}
37-
message.Data = allTables.Distinct().ToList();
38-
39-
// Get table DDL statements
40-
var msgCopy = RoleDialogModel.From(message);
41-
await fn.InvokeFunction("get_table_definition", msgCopy);
42-
var ddlStatements = msgCopy.Content;
43-
var relevantKnowledge = message.Content;
44-
message.Data = null;
39+
var distinctTables = allTables.Distinct().ToList();
40+
foreach (var table in distinctTables)
41+
{
42+
var msgCopy = RoleDialogModel.From(message);
43+
msgCopy.FunctionArgs = JsonSerializer.Serialize(new
44+
{
45+
table = table,
46+
});
47+
await fn.InvokeFunction("get_table_definition", msgCopy);
48+
ddlStatements += "\r\n" + msgCopy.Content;
49+
}
4550

4651
// Summarize and generate query
4752
var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, ddlStatements);

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Use the TwoStagePlanner approach to plan the overall implementation steps, call plan_primary_stage.
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.
4-
You must generate the final sql statement from function of plan_summary.
1+
Use the TwoStagePlanner approach to plan the overall implementation steps, follow the below steps strictly.
2+
1. call plan_primary_stage to generate the primary plan.
3+
2. If need_additional_information is true, call plan_secondary_stage for the specific primary stage.
4+
3. You must call plan_summary as the last planning step to summarize the final query.
55

66
{% if global_knowledges != empty -%}
77
=====

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Thinking process:
1010
- 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.
1111
3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@';
1212
4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}]
13-
5. Don't organize and format the extracted data with any other language rather than sql
13+
5. You can NOT generate the final query before calling function plan_summary.
1414

1515
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.
1616

src/Plugins/BotSharp.Plugin.SqlDriver/BotSharp.Plugin.SqlDriver.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\get_table_definition.fn.liquid" />
1717
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\sql_executor.fn.liquid" />
1818
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\agent.json" />
19-
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_columns.json" />
2019
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\lookup_dictionary.json" />
2120
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json" />
2221
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_select.json" />
@@ -25,7 +24,7 @@
2524
</ItemGroup>
2625

2726
<ItemGroup>
28-
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\get_table_definition.json">
27+
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_definition.json">
2928
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3029
</Content>
3130
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\get_table_definition.fn.liquid">
@@ -40,10 +39,7 @@
4039
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\lookup_dictionary.liquid">
4140
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4241
</Content>
43-
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_columns.json">
44-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45-
</Content>
46-
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\lookup_dictionary.json">
42+
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\lookup_dictionary.json">
4743
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4844
</Content>
4945
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json">

src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableColumnsFn.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/agent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "beda4c12-e1ec-4b4b-b328-3df4a6687c4f",
33
"name": "SQL Driver",
4-
"description": "Runs the specified SQL statement and returns the result.",
4+
"description": "Execute the sql query in database from the latest dialog.",
55
"type": "task",
66
"createdDateTime": "2023-11-15T13:49:00Z",
77
"updatedDateTime": "2023-11-15T13:49:00Z",

src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/functions/get_table_columns.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
You're a SQL driver who knows how to translate text into SQL query.
2-
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.
3-
Output the next step smartly.
1+
You're a SQL driver who can find the database information or query the data.
42

53
Your response must meet below requirements:
6-
* Walk through the provided information, don't run query if there is already related information;
7-
* Make sure you have the corresponding table columns information before generating SQL;
4+
* You can only execute the SQL from the conversation. You can't generate one by yourself;
85
* The return field alias should be meaningful, you can use the combination of column and value as the alias name;
96
* Use "Unique Index" to help check record existence;

0 commit comments

Comments
 (0)