Spaces:
Sleeping
Sleeping
Commit Β·
20d594f
1
Parent(s): 3653d68
feat: wire SQL routing through CLI and web UI
Browse filesCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app_cli.py +8 -1
- app_web.py +9 -4
app_cli.py
CHANGED
|
@@ -314,15 +314,19 @@ def main() -> None:
|
|
| 314 |
|
| 315 |
search_query = qu_result.get("search_query", user_input)
|
| 316 |
display_query = qu_result.get("display_query", user_input)
|
|
|
|
|
|
|
| 317 |
|
| 318 |
# Show reformulated query if different from original
|
| 319 |
if search_query != user_input:
|
| 320 |
console.print(f"[dim]Searching for: \"{search_query}\"[/dim]")
|
|
|
|
|
|
|
| 321 |
|
| 322 |
# ββ Retrieve ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 323 |
with console.status("[bold blue]Searching knowledge base...[/bold blue]"):
|
| 324 |
try:
|
| 325 |
-
retrieval_result = retrieve(search_query, effective_cfg)
|
| 326 |
except Exception as e:
|
| 327 |
console.print(f"[red]Retrieval error: {e}[/red]")
|
| 328 |
continue
|
|
@@ -377,7 +381,10 @@ def main() -> None:
|
|
| 377 |
# Source summary
|
| 378 |
db_count = len(retrieval_result.get("db_results", []))
|
| 379 |
web_count = len(retrieval_result.get("web_results", []))
|
|
|
|
| 380 |
source_summary = f"[dim]Sources: {db_count} local"
|
|
|
|
|
|
|
| 381 |
if web_count:
|
| 382 |
source_summary += f", {web_count} web"
|
| 383 |
source_summary += " -- type /sources for details[/dim]"
|
|
|
|
| 314 |
|
| 315 |
search_query = qu_result.get("search_query", user_input)
|
| 316 |
display_query = qu_result.get("display_query", user_input)
|
| 317 |
+
route = qu_result.get("route", "vector")
|
| 318 |
+
sql_query = qu_result.get("sql_query")
|
| 319 |
|
| 320 |
# Show reformulated query if different from original
|
| 321 |
if search_query != user_input:
|
| 322 |
console.print(f"[dim]Searching for: \"{search_query}\"[/dim]")
|
| 323 |
+
if route in ("sql", "both"):
|
| 324 |
+
console.print(f"[dim]Using SQL query for structured data[/dim]")
|
| 325 |
|
| 326 |
# ββ Retrieve ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 327 |
with console.status("[bold blue]Searching knowledge base...[/bold blue]"):
|
| 328 |
try:
|
| 329 |
+
retrieval_result = retrieve(search_query, effective_cfg, route=route, sql_query=sql_query)
|
| 330 |
except Exception as e:
|
| 331 |
console.print(f"[red]Retrieval error: {e}[/red]")
|
| 332 |
continue
|
|
|
|
| 381 |
# Source summary
|
| 382 |
db_count = len(retrieval_result.get("db_results", []))
|
| 383 |
web_count = len(retrieval_result.get("web_results", []))
|
| 384 |
+
sql_count = len(retrieval_result.get("sql_results", []))
|
| 385 |
source_summary = f"[dim]Sources: {db_count} local"
|
| 386 |
+
if sql_count:
|
| 387 |
+
source_summary += f", {sql_count} SQL rows"
|
| 388 |
if web_count:
|
| 389 |
source_summary += f", {web_count} web"
|
| 390 |
source_summary += " -- type /sources for details[/dim]"
|
app_web.py
CHANGED
|
@@ -182,6 +182,8 @@ def render_chat():
|
|
| 182 |
|
| 183 |
search_query = qu_result.get("search_query", combined)
|
| 184 |
display_query = qu_result.get("display_query", original_query)
|
|
|
|
|
|
|
| 185 |
|
| 186 |
# Generate assistant response
|
| 187 |
with st.chat_message("assistant"):
|
|
@@ -192,7 +194,7 @@ def render_chat():
|
|
| 192 |
|
| 193 |
# Retrieval
|
| 194 |
try:
|
| 195 |
-
retrieval_result = retrieve(search_query, cfg)
|
| 196 |
except Exception as e:
|
| 197 |
status.update(label=f"Retrieval error: {e}", state="error")
|
| 198 |
st.error(f"Retrieval failed: {e}")
|
|
@@ -201,9 +203,12 @@ def render_chat():
|
|
| 201 |
|
| 202 |
n_local = len(retrieval_result.get("db_results", []))
|
| 203 |
n_web = len(retrieval_result.get("web_results", []))
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# Response generation uses display_query β a clear,
|
| 209 |
# complete question that incorporates any clarification context
|
|
|
|
| 182 |
|
| 183 |
search_query = qu_result.get("search_query", combined)
|
| 184 |
display_query = qu_result.get("display_query", original_query)
|
| 185 |
+
route = qu_result.get("route", "vector")
|
| 186 |
+
sql_query = qu_result.get("sql_query")
|
| 187 |
|
| 188 |
# Generate assistant response
|
| 189 |
with st.chat_message("assistant"):
|
|
|
|
| 194 |
|
| 195 |
# Retrieval
|
| 196 |
try:
|
| 197 |
+
retrieval_result = retrieve(search_query, cfg, route=route, sql_query=sql_query)
|
| 198 |
except Exception as e:
|
| 199 |
status.update(label=f"Retrieval error: {e}", state="error")
|
| 200 |
st.error(f"Retrieval failed: {e}")
|
|
|
|
| 203 |
|
| 204 |
n_local = len(retrieval_result.get("db_results", []))
|
| 205 |
n_web = len(retrieval_result.get("web_results", []))
|
| 206 |
+
n_sql = len(retrieval_result.get("sql_results", []))
|
| 207 |
+
source_label = f"Found {n_local} local"
|
| 208 |
+
if n_sql:
|
| 209 |
+
source_label += f" + {n_sql} SQL rows"
|
| 210 |
+
source_label += f" + {n_web} web sources. Generating response..."
|
| 211 |
+
status.update(label=source_label)
|
| 212 |
|
| 213 |
# Response generation uses display_query β a clear,
|
| 214 |
# complete question that incorporates any clarification context
|