Spaces:
Configuration error
Configuration error
Fix 422 on /ask: accept empty question field
Browse filesNewer FastAPI treats an empty required Form value as missing, so the
hidden question textarea (submitted as "" in System Chart Extraction
mode) started failing validation after the Space image rebuilt with the
latest FastAPI. Make question optional with an empty default and return
a friendly error for empty QA questions instead.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
main.py
CHANGED
|
@@ -2436,7 +2436,9 @@ async def get_conversation_history(extraction_id: str, conversation_key: str):
|
|
| 2436 |
async def ask_question(
|
| 2437 |
background_tasks: BackgroundTasks,
|
| 2438 |
categories: str = Form(...), # Changed from category to categories (comma-separated)
|
| 2439 |
-
|
|
|
|
|
|
|
| 2440 |
k: int = Form(10),
|
| 2441 |
goal: str = Form("QA"),
|
| 2442 |
enable_visualization: bool = Form(False),
|
|
@@ -2509,6 +2511,11 @@ async def ask_question(
|
|
| 2509 |
|
| 2510 |
# For QA goal, we can query multiple databases
|
| 2511 |
if goal == "QA":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2512 |
if llm_QA is None:
|
| 2513 |
return JSONResponse(
|
| 2514 |
content={"answer": "QA model not configured."},
|
|
|
|
| 2436 |
async def ask_question(
|
| 2437 |
background_tasks: BackgroundTasks,
|
| 2438 |
categories: str = Form(...), # Changed from category to categories (comma-separated)
|
| 2439 |
+
# Default to "" instead of required: newer FastAPI treats an empty form value as
|
| 2440 |
+
# missing, and the hidden question field submits "" in System Chart Extraction mode.
|
| 2441 |
+
question: str = Form(""),
|
| 2442 |
k: int = Form(10),
|
| 2443 |
goal: str = Form("QA"),
|
| 2444 |
enable_visualization: bool = Form(False),
|
|
|
|
| 2511 |
|
| 2512 |
# For QA goal, we can query multiple databases
|
| 2513 |
if goal == "QA":
|
| 2514 |
+
if not question.strip():
|
| 2515 |
+
return JSONResponse(
|
| 2516 |
+
content={"answer": "Please enter a question before submitting."},
|
| 2517 |
+
status_code=400
|
| 2518 |
+
)
|
| 2519 |
if llm_QA is None:
|
| 2520 |
return JSONResponse(
|
| 2521 |
content={"answer": "QA model not configured."},
|