Skip to content

update sql button render #808

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

Merged
merged 1 commit into from
Dec 27, 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 @@ -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")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public SqlDriverPlanningHook(IServiceProvider services)
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>();
Expand All @@ -42,7 +42,7 @@ await HookEmitter.Emit<ISqlDriverHook>(_services, async (hook) =>
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;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ await HookEmitter.Emit<ISqlDriverHook>(_services, async (hook) =>

public async Task OnPlanningCompleted(string planner, RoleDialogModel msg)
{

}

public async Task<string> GetSummaryAdditionalRequirements(string planner, RoleDialogModel message)
Expand All @@ -91,8 +91,27 @@ private RichContent<IRichMessage> BuildRunQueryButton(string conversationId, str
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>
{
Expand All @@ -105,23 +124,9 @@ private RichContent<IRichMessage> BuildRunQueryButton(string conversationId, str
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()
}
};

}
}