diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index c8eb28dc8..465ae9615 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -54,6 +54,12 @@ public void CreateUser(User user) File.WriteAllText(path, JsonSerializer.Serialize(user, _options)); } + public void UpdateExistUser(string userId, User user) + { + user.Id = userId; + CreateUser(user); + } + public void UpdateUserVerified(string userId) { var user = GetUserById(userId); diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs index 7ba8aaf48..70ce855eb 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs @@ -2,7 +2,9 @@ using BotSharp.Abstraction.Routing; using BotSharp.Plugin.ExcelHandler.Helpers.MySql; using BotSharp.Plugin.ExcelHandler.Models; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using MySql.Data.MySqlClient; +using Newtonsoft.Json; using NPOI.SS.UserModel; namespace BotSharp.Plugin.ExcelHandler.Services @@ -108,10 +110,14 @@ public IEnumerable WriteExcelDataToDB(IWorkbook workbook) continue; } var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet); + + string table = $"{_database}.{_tableName}"; + string exampleData = GetInsertExample(table); + commandResult = new SqlContextOut { isSuccessful = isInsertSuccess, - Message = $"{insertMessage}\r\n{message}", + Message = $"{insertMessage}\r\nExample Data: {exampleData}", FileName = _currentFileName }; commandList.Add(commandResult); @@ -240,5 +246,18 @@ public void ExecuteSqlQueryForInsertion(string sqlQuery) cmd.ExecuteNonQuery(); } } + private string GetInsertExample(string tableName) + { + using var connection = _mySqlDbHelpers.GetDbConnection(); + _database = connection.Database; + var sqlQuery = $"SELECT * FROM {tableName} LIMIT 2;"; + using var cmd = new MySqlCommand(sqlQuery, connection); + using var reader = cmd.ExecuteReader(); + + var dataExample = new DataTable(); + dataExample.Load(reader); + + return JsonConvert.SerializeObject(dataExample); + } } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid index 82afe7e6a..49e374a1f 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid @@ -1,7 +1,8 @@ -You are a knowledge generator for knowledge base. Extract the answer in "SQL Answer" to answer the User Questions -Replace alias with the actual table name. Output json array only, formatting as [{"question":"string", "answer":"string/sql statement"}]. -Skip the question/answer for tmp table. -Don't include tmp table in the answer. +You are a knowledge generator for knowledge base. Extract the answer in "SQL Answer" to answer the User Questions. +* Replace alias with the actual table name. Output json array only, formatting as [{"question":"string", "answer":""}]. +* Skip the question/answer for tmp table. +* Don't include tmp table in the answer. +* Include all the explanation comments as additional knowledge. ===== User Questions: diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_secondary_stage.json b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_secondary_stage.json index b3770e9aa..ca6b3d0b2 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_secondary_stage.json +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_secondary_stage.json @@ -10,7 +10,7 @@ }, "solution_search_question": { "type": "string", - "description": "Provide solution query text" + "description": "Generate question to find the knowledge for text. Be short" } }, "required": [ "task_description", "solution_search_question" ] diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid index d15329a89..de42bc4d3 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid @@ -4,7 +4,7 @@ Use the TwoStagePlanner approach to plan the overall implementation steps, follo 1. Call plan_primary_stage to generate the primary plan. If you've already got the plan to meet the user goal, directly go to step 5. 2. If need_lookup_dictionary is True, call verify_dictionary_term to verify or get the enum/term/dictionary value. Pull id and name. - If you no items retured, you can pull all the list and find the match. + If you no items retured, you can pull 100 records from the table and look for the match. If need_lookup_dictionary is False, skip calling verify_dictionary_term. 3. If need_breakdown_task is true, call plan_secondary_stage for the specific primary stage. 4. Repeat step 3 until you processed all the primary stages. @@ -12,6 +12,7 @@ Use the TwoStagePlanner approach to plan the overall implementation steps, follo *** IMPORTANT *** Don't run the planning process repeatedly if you have already got the result of user's request. +Function verify_dictionary_term CAN'T generate INSERT SQL Statement. {% if global_knowledges != empty -%} diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs index dcd70915f..8d277b9df 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs @@ -43,7 +43,7 @@ private List GetDdlFromMySql(string[] tables) { var settings = _services.GetRequiredService(); var tableDdls = new List(); - using var connection = new MySqlConnection(settings.MySqlExecutionConnectionString ?? settings.MySqlConnectionString); + using var connection = new MySqlConnection(settings.MySqlMetaConnectionString ?? settings.MySqlConnectionString); connection.Open(); foreach (var table in tables) diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Settings/SqlDriverSetting.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Settings/SqlDriverSetting.cs index 3a4095a69..c6917894f 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Settings/SqlDriverSetting.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Settings/SqlDriverSetting.cs @@ -6,6 +6,7 @@ public class SqlDriverSetting public string MySqlConnectionString { get; set; } = null!; public string MySqlExecutionConnectionString { get; set; } = null!; public string MySqlTempConnectionString { get; set; } = null!; + public string MySqlMetaConnectionString { get; set; } = null!; public string SqlServerConnectionString { get; set; } = null!; public string SqlServerExecutionConnectionString { get; set; } = null!; public string SqlLiteConnectionString { get; set; } = null!; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json index 1be003a44..6ad2a9179 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json @@ -1,6 +1,6 @@ { "name": "verify_dictionary_term", - "description": "Get id from dictionary table by keyword if tool or solution mentioned this approach", + "description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is True", "parameters": { "type": "object", "properties": { diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid index f5ceebdb2..6a9b06e87 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid @@ -1,11 +1,13 @@ -Dictionary Verification Rules: +Rules to call verify_dictionary_term: ===== 1. The table name must come from the planning in conversation. -2. You must return the id and name/code. +2. You must return the id and name/code for existing dictionary. +3. Call the function only if need_lookup_dictionary is true. You are connecting to {{ db_type }} database. You can run provided SQL statements by following {{ db_type }} rules. -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. +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. -IMPORTANT: Don't generate insert SQL. +IMPORTANT: You can NOT insert data into dictionary. ===== \ No newline at end of file