Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attachment example and refine dictionary lookup #684

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,10 +110,14 @@ public IEnumerable<SqlContextOut> 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);
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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.
5. You must call plan_summary for you final planned output.

*** 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 -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private List<string> GetDdlFromMySql(string[] tables)
{
var settings = _services.GetRequiredService<SqlDriverSetting>();
var tableDdls = new List<string>();
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
=====