add db type
This commit is contained in:
parent
3986a50ce2
commit
45ff927258
|
|
@ -53,8 +53,32 @@ public class SqlExecutorHook : AgentHookBase, IAgentHook
|
|||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var agent = db.GetAgent(BuiltInAgentId.UtilityAssistant);
|
||||
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(SQL_EXECUTOR_TEMPLATE))?.Content ?? string.Empty;
|
||||
var fns = agent?.Functions?.Where(x => _targetSqlExecutorFunctions.Contains(x.Name))?.ToList();
|
||||
|
||||
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(SQL_EXECUTOR_TEMPLATE))?.Content ?? string.Empty;
|
||||
var dbType = GetDatabaseType();
|
||||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
prompt = render.Render(prompt, new Dictionary<string, object>
|
||||
{
|
||||
{ "db_type", dbType }
|
||||
});
|
||||
|
||||
return (prompt, fns);
|
||||
}
|
||||
|
||||
private string GetDatabaseType()
|
||||
{
|
||||
var settings = _services.GetRequiredService<SqlDriverSetting>();
|
||||
var dbType = "MySQL";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(settings?.SqlServerConnectionString))
|
||||
{
|
||||
dbType = "SQL Server";
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(settings?.SqlLiteConnectionString))
|
||||
{
|
||||
dbType = "SQL Lite";
|
||||
}
|
||||
return dbType;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@ namespace BotSharp.Plugin.SqlHero.Settings;
|
|||
public class SqlDriverSetting
|
||||
{
|
||||
public string MySqlConnectionString { get; set; }
|
||||
public string SqlServerConnectionString { get; set; }
|
||||
public string SqlLiteConnectionString { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
You are connecting to MySQL database. Please generate SQL statements following MySQL rules.
|
||||
You are connecting to {{ db_type }} database. Please generate SQL statements following {{ db_type }} rules.
|
||||
|
||||
Please call function sql_select if user wants to get or retrieve data from data tables.
|
||||
If there are any parameters, please add them in the WHERE clause, each of which starts with "@".
|
||||
|
|
|
|||
Loading…
Reference in a new issue