Skip to content

Commit 927dd47

Browse files
authored
Merge pull request #684 from Joannall/master
Add attachment example and refine dictionary lookup
2 parents 331b931 + 7ef31fc commit 927dd47

File tree

9 files changed

+43
-13
lines changed

9 files changed

+43
-13
lines changed

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public void CreateUser(User user)
5454
File.WriteAllText(path, JsonSerializer.Serialize(user, _options));
5555
}
5656

57+
public void UpdateExistUser(string userId, User user)
58+
{
59+
user.Id = userId;
60+
CreateUser(user);
61+
}
62+
5763
public void UpdateUserVerified(string userId)
5864
{
5965
var user = GetUserById(userId);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using BotSharp.Abstraction.Routing;
33
using BotSharp.Plugin.ExcelHandler.Helpers.MySql;
44
using BotSharp.Plugin.ExcelHandler.Models;
5+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
56
using MySql.Data.MySqlClient;
7+
using Newtonsoft.Json;
68
using NPOI.SS.UserModel;
79

810
namespace BotSharp.Plugin.ExcelHandler.Services
@@ -108,10 +110,14 @@ public IEnumerable<SqlContextOut> WriteExcelDataToDB(IWorkbook workbook)
108110
continue;
109111
}
110112
var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet);
113+
114+
string table = $"{_database}.{_tableName}";
115+
string exampleData = GetInsertExample(table);
116+
111117
commandResult = new SqlContextOut
112118
{
113119
isSuccessful = isInsertSuccess,
114-
Message = $"{insertMessage}\r\n{message}",
120+
Message = $"{insertMessage}\r\nExample Data: {exampleData}",
115121
FileName = _currentFileName
116122
};
117123
commandList.Add(commandResult);
@@ -240,5 +246,18 @@ public void ExecuteSqlQueryForInsertion(string sqlQuery)
240246
cmd.ExecuteNonQuery();
241247
}
242248
}
249+
private string GetInsertExample(string tableName)
250+
{
251+
using var connection = _mySqlDbHelpers.GetDbConnection();
252+
_database = connection.Database;
253+
var sqlQuery = $"SELECT * FROM {tableName} LIMIT 2;";
254+
using var cmd = new MySqlCommand(sqlQuery, connection);
255+
using var reader = cmd.ExecuteReader();
256+
257+
var dataExample = new DataTable();
258+
dataExample.Load(reader);
259+
260+
return JsonConvert.SerializeObject(dataExample);
261+
}
243262
}
244263
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
You are a knowledge generator for knowledge base. Extract the answer in "SQL Answer" to answer the User Questions
2-
Replace alias with the actual table name. Output json array only, formatting as [{"question":"string", "answer":"string/sql statement"}].
3-
Skip the question/answer for tmp table.
4-
Don't include tmp table in the answer.
1+
You are a knowledge generator for knowledge base. Extract the answer in "SQL Answer" to answer the User Questions.
2+
* Replace alias with the actual table name. Output json array only, formatting as [{"question":"string", "answer":""}].
3+
* Skip the question/answer for tmp table.
4+
* Don't include tmp table in the answer.
5+
* Include all the explanation comments as additional knowledge.
56

67
=====
78
User Questions:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"solution_search_question": {
1212
"type": "string",
13-
"description": "Provide solution query text"
13+
"description": "Generate question to find the knowledge for text. Be short"
1414
}
1515
},
1616
"required": [ "task_description", "solution_search_question" ]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Use the TwoStagePlanner approach to plan the overall implementation steps, follo
44
1. Call plan_primary_stage to generate the primary plan.
55
If you've already got the plan to meet the user goal, directly go to step 5.
66
2. If need_lookup_dictionary is True, call verify_dictionary_term to verify or get the enum/term/dictionary value. Pull id and name.
7-
If you no items retured, you can pull all the list and find the match.
7+
If you no items retured, you can pull 100 records from the table and look for the match.
88
If need_lookup_dictionary is False, skip calling verify_dictionary_term.
99
3. If need_breakdown_task is true, call plan_secondary_stage for the specific primary stage.
1010
4. Repeat step 3 until you processed all the primary stages.
1111
5. You must call plan_summary for you final planned output.
1212

1313
*** IMPORTANT ***
1414
Don't run the planning process repeatedly if you have already got the result of user's request.
15+
Function verify_dictionary_term CAN'T generate INSERT SQL Statement.
1516

1617

1718
{% if global_knowledges != empty -%}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private List<string> GetDdlFromMySql(string[] tables)
4343
{
4444
var settings = _services.GetRequiredService<SqlDriverSetting>();
4545
var tableDdls = new List<string>();
46-
using var connection = new MySqlConnection(settings.MySqlExecutionConnectionString ?? settings.MySqlConnectionString);
46+
using var connection = new MySqlConnection(settings.MySqlMetaConnectionString ?? settings.MySqlConnectionString);
4747
connection.Open();
4848

4949
foreach (var table in tables)

src/Plugins/BotSharp.Plugin.SqlDriver/Settings/SqlDriverSetting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class SqlDriverSetting
66
public string MySqlConnectionString { get; set; } = null!;
77
public string MySqlExecutionConnectionString { get; set; } = null!;
88
public string MySqlTempConnectionString { get; set; } = null!;
9+
public string MySqlMetaConnectionString { get; set; } = null!;
910
public string SqlServerConnectionString { get; set; } = null!;
1011
public string SqlServerExecutionConnectionString { get; set; } = null!;
1112
public string SqlLiteConnectionString { get; set; } = null!;

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

Lines changed: 1 addition & 1 deletion
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 if tool or solution mentioned this approach",
3+
"description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is True",
44
"parameters": {
55
"type": "object",
66
"properties": {
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
Dictionary Verification Rules:
1+
Rules to call verify_dictionary_term:
22
=====
33
1. The table name must come from the planning in conversation.
4-
2. You must return the id and name/code.
4+
2. You must return the id and name/code for existing dictionary.
5+
3. Call the function only if need_lookup_dictionary is true.
56

67
You are connecting to {{ db_type }} database. You can run provided SQL statements by following {{ db_type }} rules.
78

8-
The dictionary table is identified by a name that begins with "data_". You are only allowed to query the dictionary table without joining it with other non-dictionary tables.
9+
The dictionary table is identified by a name that begins with "data_".
10+
You are only allowed to query the dictionary table without joining it with other non-dictionary tables.
911

10-
IMPORTANT: Don't generate insert SQL.
12+
IMPORTANT: You can NOT insert data into dictionary.
1113
=====

0 commit comments

Comments
 (0)