Melika Kheirieh commited on
Commit
6181651
·
1 Parent(s): 1615809

fix(router): coerce trace.duration_ms to int in response (_round_trace)

Browse files
Files changed (1) hide show
  1. 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: Dict[str, Any]) -> Dict[str, Any]:
227
- if t.get("cost_usd") is not None:
228
- cost = t["cost_usd"]
229
- if isinstance(cost, (int, float)):
230
- t["cost_usd"] = round(float(cost), 6)
231
- if t.get("duration_ms") is not None:
232
- dur = t["duration_ms"]
233
- if isinstance(dur, (int, float)):
234
- t["duration_ms"] = round(float(dur), 2)
235
- return t
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  # -------------------------------