Merge pull request #808 from Joannall/master

update sql button render
This commit is contained in:
Haiping 2024-12-27 17:00:30 +00:00 committed by GitHub
commit 699f913fbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 24 deletions

View file

@ -31,7 +31,7 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
type: "boolean",
required: true),
new ParameterPropertyDef("is_new_task",
"whether the user is requesting a new task that is different from the previous topic.",
"whether the user is requesting a new task that is different from the previous topic. Set the first round of conversation to false.",
type: "boolean")
};

View file

@ -23,9 +23,9 @@ public class SqlDriverPlanningHook : IPlanningHook
public async Task OnSourceCodeGenerated(string planner, RoleDialogModel msg, string language)
{
// envoke validate
if (language != "sql")
{
return;
if (language != "sql")
{
return;
}
var routing = _services.GetRequiredService<IRoutingService>();
@ -42,7 +42,7 @@ public class SqlDriverPlanningHook : IPlanningHook
var conversationStateService = _services.GetRequiredService<IConversationStateService>();
var conversationId = conversationStateService.GetConversationId();
msg.PostbackFunctionName = "execute_sql";
msg.RichContent = BuildRunQueryButton(planner, msg.Content);
msg.RichContent = BuildRunQueryButton(conversationId, msg.Content);
msg.StopCompletion = true;
return;
}
@ -71,7 +71,7 @@ public class SqlDriverPlanningHook : IPlanningHook
public async Task OnPlanningCompleted(string planner, RoleDialogModel msg)
{
}
public async Task<string> GetSummaryAdditionalRequirements(string planner, RoleDialogModel message)
@ -91,8 +91,27 @@ public class SqlDriverPlanningHook : IPlanningHook
string pattern = @"```sql\s*([\s\S]*?)\s*```";
var sql = Regex.Match(text, pattern).Groups[1].Value;
var state = _services.GetRequiredService<IConversationStateService>();
var deleteTable = state.GetState("tmp_table");
var deleteSql = $"DROP TABLE IF EXISTS {deleteTable};";
var tmpTable = state.GetState("tmp_table");
var elements = new List<ElementButton>() { };
elements.Add(new ElementButton
{
Type = "text",
Title = "Execute SQL Statement",
Payload = sql,
IsPrimary = true
});
if (tmpTable != string.Empty)
{
var deleteSql = $"DROP TABLE IF EXISTS {tmpTable};";
elements.Add(new ElementButton
{
Type = "text",
Title = "Delete Temp Table",
Payload = deleteSql
});
}
return new RichContent<IRichMessage>
{
@ -105,23 +124,9 @@ public class SqlDriverPlanningHook : IPlanningHook
Message = new ButtonTemplateMessage
{
Text = text,
Buttons = new List<ElementButton>
{
new ElementButton
{
Type = "text",
Title = "Execute the SQL Statement",
Payload = sql,
IsPrimary = true
},
new ElementButton
{
Type = "text",
Title = "Purge Cache",
Payload = deleteSql
}
}.ToArray()
Buttons = elements.ToArray()
}
};
}
}