fix: chart viz status updated

This commit is contained in:
qixinbo
2026-03-19 15:33:12 +08:00
parent 2aeed315b3
commit 9c73210143
2 changed files with 31 additions and 7 deletions
+26 -6
View File
@@ -197,14 +197,24 @@ async def nanobot_chat_stream(request: ChatRequest):
) )
text = "" text = ""
viz_sent = False last_viz_hash = None
while True: while True:
# Check for viz payload during processing # Check for viz payload during processing
viz_payload = current_viz_data.get() viz_payload = current_viz_data.get()
if viz_payload and not viz_sent: if viz_payload:
yield f"data: {json.dumps({'type': 'viz', **viz_payload}, ensure_ascii=False)}\n\n" try:
viz_sent = True # Only hash sql and chart to avoid dumping large result arrays every 0.2s
current_hash = hash((
viz_payload.get("sql"),
viz_payload.get("error"),
json.dumps(viz_payload.get("chart"), sort_keys=True)
))
if current_hash != last_viz_hash:
yield f"data: {json.dumps({'type': 'viz', **viz_payload}, ensure_ascii=False)}\n\n"
last_viz_hash = current_hash
except Exception as e:
print(f"Error checking viz_payload: {e}")
if current_task.done() and progress_queue.empty(): if current_task.done() and progress_queue.empty():
break break
@@ -219,8 +229,18 @@ async def nanobot_chat_stream(request: ChatRequest):
# Check again for viz payload after task completes if not sent yet # Check again for viz payload after task completes if not sent yet
viz_payload = current_viz_data.get() viz_payload = current_viz_data.get()
if viz_payload and not viz_sent: if viz_payload:
yield f"data: {json.dumps({'type': 'viz', **viz_payload}, ensure_ascii=False)}\n\n" try:
current_hash = hash((
viz_payload.get("sql"),
viz_payload.get("error"),
json.dumps(viz_payload.get("chart"), sort_keys=True)
))
if current_hash != last_viz_hash:
yield f"data: {json.dumps({'type': 'viz', **viz_payload}, ensure_ascii=False)}\n\n"
last_viz_hash = current_hash
except Exception as e:
pass
# Persist viz payload to session # Persist viz payload to session
if viz_payload and nanobot_service.agent: if viz_payload and nanobot_service.agent:
+5 -1
View File
@@ -648,7 +648,11 @@ export function ChatInterface() {
} }
if (payload.type === "viz") { if (payload.type === "viz") {
pushProgressLog("可视化结果已生成"); if (payload.chart?.chart_spec) {
pushProgressLog("图表生成完成");
} else if (payload.sql) {
pushProgressLog("数据查询完成");
}
streamedViz = buildMessageViz(payload); streamedViz = buildMessageViz(payload);
flushAssistant(true); // 立即把 viz 状态刷入 messages flushAssistant(true); // 立即把 viz 状态刷入 messages
} }