From 04b3e85a37aff8dd8f54abec2b3a42913599199c Mon Sep 17 00:00:00 2001 From: Joanna Ren <101223@smsassist.com> Date: Mon, 14 Oct 2024 15:27:30 -0500 Subject: [PATCH] Add attachment example and refine dictionary lookup --- .../Services/MySqlService.cs | 21 ++++++++++++++++++- .../functions/plan_secondary_stage.json | 2 +- .../instructions/instruction.liquid | 3 ++- .../functions/sql_dictionary_lookup.json | 2 +- .../templates/sql_dictionary_lookup.fn.liquid | 10 +++++---- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs index 7ba8aaf4..70ce855e 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs @@ -2,7 +2,9 @@ using System.Data; 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 @@ namespace BotSharp.Plugin.ExcelHandler.Services 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 @@ namespace BotSharp.Plugin.ExcelHandler.Services 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.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 b3770e9a..ca6b3d0b 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 5dda81e3..49f296ac 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 @@ -2,7 +2,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. @@ -10,6 +10,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/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 1be003a4..6ad2a917 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 f5ceebdb..6a9b06e8 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