INNER CODE UNIT · Python
gen
simonlin1212/vibe-astock · vr/app.py:115
def gen():
try:
events = (chat_layer.run_chat_cli_stream if is_cli else chat_layer.run_chat_stream)(cfg, req.messages, req.context)
for ev in events:
yield json.dumps(ev, ensure_ascii=False) + "\n"
except Exception as e: # noqa: BLE001 — 运行时错误以流内事件上报,不中断连接
yield json.dumps({"type": "error", "message": f"对话失败:{e}"}, ensure_ascii=False) + "\n"
return StreamingResponse(gen(), media_type="application/x-ndjson")
class HoldingIn(BaseModel):
code: str
shares: float
cost: float
@app.get("/api/portfolio")