diff options
| author | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-09-04 14:45:35 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-09-04 14:45:35 +0300 |
| commit | da102bf068b5a0734008cc576a20aef97ae0495b (patch) | |
| tree | 4a7a5c3ddf4ec725f744aa931c6166409d3e5bea /Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs | |
| parent | 72d2d9316e27f623456574dd854da064611254a1 (diff) | |
| download | Tango-da102bf068b5a0734008cc576a20aef97ae0495b.tar.gz Tango-da102bf068b5a0734008cc576a20aef97ae0495b.zip | |
OpenAI query fallback to Claude.
Diffstat (limited to 'Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs')
| -rw-r--r-- | Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs index da91d31e0..a13b6a47a 100644 --- a/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs +++ b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Controllers/ChatController.cs @@ -19,7 +19,6 @@ namespace Tango.Portal.Chat.Web.Controllers private readonly KqlGuard _guard; private readonly KustoQueryService _adx; private readonly LlmClient _llm; - private static readonly string[] AllowTables = new[] { "JobRunsTable", "JobStatusTable", "TelemetryTable", "MachinesTable" }; public ChatController(SchemaRegistry schema, KqlGuard guard, KustoQueryService adx, LlmClient llm) { @@ -30,7 +29,7 @@ namespace Tango.Portal.Chat.Web.Controllers } [HttpPost("ask")] - public async Task<ActionResult<ChatResponse>> Ask([FromBody] ChatRequest req, CancellationToken ct) + public async Task<ActionResult<ChatResponse>> Ask([FromBody] ChatRequest req, CancellationToken ct, LlmProvider? provider = null) { try { @@ -39,13 +38,19 @@ namespace Tango.Portal.Chat.Web.Controllers var plotySample = _schema.GetPlotySample(); // 1) Ask the model for KQL - var plan = await _llm.ProposeKqlAsync(plannerPrompt, plotySample, req.Question, schemaJson, req.History, ct); - if (plan.Assistant == "data") + ProposeKqlResult? plan = null; + + if (provider == LlmProvider.Claude) { - return await AnswerWithDataAssistant(req, plan, ct); + plan = await _llm.ProposeKqlWithClaudeAsync(plannerPrompt, plotySample, req.Question, schemaJson, req.History, ct); + } + else + { + plan = await _llm.ProposeKqlAsync(plannerPrompt, plotySample, req.Question, schemaJson, req.History, ct); } - else if (plan.Assistant == "ploty") + + if (plan.Assistant == "data" || plan.Assistant == "ploty") { return await AnswerWithDataAssistant(req, plan, ct); } @@ -118,13 +123,20 @@ namespace Tango.Portal.Chat.Web.Controllers } catch (Exception ex) { - // Return error to the client so they can iterate - return new ChatResponse + if (plan.Provider == LlmProvider.OpenAI) { - Answer = $"Seems like my kusto query ran into some issue..\n{ex.Message}", - ThreadId = req.ThreadId, - UsedKql = plan.Kql - }; + return await Ask(req, ct, LlmProvider.Claude); + } + else + { + // Return error to the client so they can iterate + return new ChatResponse + { + Answer = $"Seems like my kusto query ran into some issue..\n{ex.Message}", + ThreadId = req.ThreadId, + UsedKql = plan.Kql + }; + } } if (table.Columns.Contains("ploty") && table.Rows.Count > 0) |
