Skip to content

Commit 363ee51

Browse files
authored
Merge pull request #705 from Joannall/master
Add drop tmp table, Refined kg search
2 parents ad2804c + b4bc506 commit 363ee51

File tree

8 files changed

+52
-8
lines changed

8 files changed

+52
-8
lines changed

src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public IEnumerable<SqlContextOut> WriteExcelDataToDB(IWorkbook workbook)
9090
{
9191
var numTables = workbook.NumberOfSheets;
9292
var commandList = new List<SqlContextOut>();
93+
var state = _services.GetRequiredService<IConversationStateService>();
9394

9495
for (int sheetIdx = 0; sheetIdx < numTables; sheetIdx++)
9596
{
@@ -109,15 +110,17 @@ public IEnumerable<SqlContextOut> WriteExcelDataToDB(IWorkbook workbook)
109110
commandList.Add(commandResult);
110111
continue;
111112
}
112-
var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet);
113113

114114
string table = $"{_database}.{_tableName}";
115+
state.SetState("tmp_table", table);
116+
117+
var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet);
115118
string exampleData = GetInsertExample(table);
116119

117120
commandResult = new SqlContextOut
118121
{
119122
isSuccessful = isInsertSuccess,
120-
Message = $"{insertMessage}\r\nExample Data: {exampleData}",
123+
Message = $"{insertMessage}\r\nExample Data: {exampleData}. \r\n The remaining data contains different values. ",
121124
FileName = _currentFileName
122125
};
123126
commandList.Add(commandResult);

src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.plain.liquid

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ You are a knowledge extractor for knowledge base. Extract the answer in "SQL Ans
33
* Skip the question/answer for tmp table.
44
* Don't include tmp table in the answer.
55
* Include all the explanation comments as additional knowledge.
6+
* Don't replace the parameter in the question.
7+
* Replace the specific id in answer based on the question.
8+
* Don't need multiple set of query solutions for the same question. Only keep one.
69

710
=====
811
User Questions:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ public async Task<bool> Execute(RoleDialogModel message)
2525

2626
state.SetState("max_tokens", "4096");
2727
var task = JsonSerializer.Deserialize<PrimaryRequirementRequest>(message.FunctionArgs);
28+
var searchQuestions = new List<string>(task.Questions);
29+
searchQuestions.AddRange(task.NormQuestions);
30+
searchQuestions = searchQuestions.Distinct().ToList();
2831

2932
// Get knowledge from vectordb
3033
var hooks = _services.GetServices<IKnowledgeHook>();
3134
var knowledges = new List<string>();
32-
foreach (var question in task.Questions)
35+
foreach (var question in searchQuestions)
3336
{
3437
foreach (var hook in hooks)
3538
{

src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/PrimaryRequirementRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ public class PrimaryRequirementRequest
77

88
[JsonPropertyName("questions")]
99
public string[] Questions { get; set; } = [];
10+
11+
[JsonPropertyName("norm_questions")]
12+
public string[] NormQuestions { get; set; } = [];
1013
}

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_primary_stage.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,35 @@
1010
},
1111
"questions": {
1212
"type": "array",
13-
"description": "Rephrase user requirements in details and in multiple ways, don't miss any information especially for those line items, values and numbers.",
13+
"description": "Break down user requirements in details and in multiple ways, don't miss any entity type/value",
1414
"items": {
1515
"type": "string",
16-
"description": "Question converted from requirement in different ways to search in the knowledge base, be short and you can refer to the global knowledge.One question should contain only one main topic."
16+
"description": "Question converted from requirement in different ways to search in the knowledge base, be short and you can refer to the global knowledge.One question should contain only one main topic that with one entity type."
17+
}
18+
},
19+
"norm_questions": {
20+
"type": "array",
21+
"description": "normalize the generated questions, remove specific entity value.",
22+
"items": {
23+
"type": "string",
24+
"description": "Normalized question"
25+
}
26+
},
27+
"entities": {
28+
"type": "array",
29+
"description": "entities with type and value",
30+
"items": {
31+
"type": "object",
32+
"properties": {
33+
"type": {
34+
"type": "string",
35+
"description": "entity type"
36+
},
37+
"value": {
38+
"type": "string",
39+
"description": "entity value"
40+
}
41+
}
1742
}
1843
}
1944
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Thinking process:
88
- If there is extra knowledge or relationship needed between steps, set the need_breakdown_task to true for both steps.
99
- If the solution mentioned "related solutions" is needed, set the need_breakdown_task to true.
1010
- You should find the relationships between data structure based on the task knowledge strictly. If lack of information, set the need_breakdown_task to true.
11-
- If you need to lookup the dictionary to verify or get the enum/term/dictionary value, set the need_lookup_dictionary to true.
11+
- If you need to lookup the dictionary to verify or get the enum/term/dictionary value(exclude example data from attachment), set the need_lookup_dictionary to true.
12+
- Don't set need_lookup_dictionary to true for attachment data.
1213
- Seperate the dictionary lookup and need additional information/knowledge into different subtask.
1314
3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@';
1415
4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}]

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public async Task<bool> Execute(RoleDialogModel message)
4141
_ => throw new NotImplementedException($"Database type {settings.DatabaseType} is not supported.")
4242
};
4343

44+
if (refinedArgs.SqlStatements.Length == 1 && refinedArgs.SqlStatements[0].StartsWith("DROP TABLE"))
45+
{
46+
message.Content = "Drop table successfully";
47+
return true;
48+
}
49+
4450
if (results.Count() == 0)
4551
{
4652
message.Content = "No record found";

src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/verify_dictionary_term.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "verify_dictionary_term",
3-
"description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is true and is_insert is false",
3+
"description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is true and is_insert is false. You can only query one table at a time.",
44
"parameters": {
55
"type": "object",
66
"properties": {
@@ -18,7 +18,7 @@
1818
},
1919
"tables": {
2020
"type": "array",
21-
"description": "all related tables",
21+
"description": "all related dictionary tables",
2222
"items": {
2323
"type": "string",
2424
"description": "table name"

0 commit comments

Comments
 (0)