Spaces:
Running
Running
Melika Kheirieh
commited on
Commit
·
6181651
1
Parent(s):
1615809
fix(router): coerce trace.duration_ms to int in response (_round_trace)
Browse files- app/routers/nl2sql.py +24 -10
app/routers/nl2sql.py
CHANGED
|
@@ -223,16 +223,30 @@ def _to_dict(obj: Any) -> Any:
|
|
| 223 |
return obj
|
| 224 |
|
| 225 |
|
| 226 |
-
def _round_trace(t:
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
|
| 238 |
# -------------------------------
|
|
|
|
| 223 |
return obj
|
| 224 |
|
| 225 |
|
| 226 |
+
def _round_trace(t: Any) -> Dict[str, Any]:
|
| 227 |
+
"""Normalize a trace entry to a dict and coerce duration_ms to int."""
|
| 228 |
+
if isinstance(t, dict):
|
| 229 |
+
stage = t.get("stage", "?")
|
| 230 |
+
ms = t.get("duration_ms", 0)
|
| 231 |
+
notes = t.get("notes")
|
| 232 |
+
cost = t.get("cost_usd")
|
| 233 |
+
else:
|
| 234 |
+
stage = getattr(t, "stage", "?")
|
| 235 |
+
ms = getattr(t, "duration_ms", 0)
|
| 236 |
+
notes = getattr(t, "notes", None)
|
| 237 |
+
cost = getattr(t, "cost_usd", None)
|
| 238 |
+
|
| 239 |
+
try:
|
| 240 |
+
ms_int = int(ms) if ms is not None else 0
|
| 241 |
+
except Exception:
|
| 242 |
+
ms_int = 0
|
| 243 |
+
|
| 244 |
+
return {
|
| 245 |
+
"stage": str(stage) if stage is not None else "?",
|
| 246 |
+
"duration_ms": ms_int,
|
| 247 |
+
"notes": notes,
|
| 248 |
+
"cost_usd": cost,
|
| 249 |
+
}
|
| 250 |
|
| 251 |
|
| 252 |
# -------------------------------
|