🐛 fix(chat.py): rename websocket_endpoint to chat for better semantics
✨ feat(chat.py): add build_status endpoint to check if flow_id is in flow_data_store
The function name websocket_endpoint was renamed to chat to improve semantics. The new build_status endpoint was added to check if a flow_id is in the flow_data_store. This endpoint returns a JSON response with a boolean value indicating whether the flow_id is built or not. If the flow_id is not in the flow_data_store, a JSON response with a value of False is returned. If an exception occurs, a 500 HTTPException is raised with the exception message as the detail.
This commit is contained in:
parent
de7b2c9f31
commit
fe0c6f7f38
1 changed files with 15 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
HTTPException,
|
||||
WebSocket,
|
||||
WebSocketDisconnect,
|
||||
WebSocketException,
|
||||
|
|
@ -18,7 +19,7 @@ flow_data_store = {}
|
|||
|
||||
|
||||
@router.websocket("/chat/{client_id}")
|
||||
async def websocket_endpoint(client_id: str, websocket: WebSocket):
|
||||
async def chat(client_id: str, websocket: WebSocket):
|
||||
"""Websocket endpoint for chat."""
|
||||
try:
|
||||
if client_id in chat_manager.in_memory_cache:
|
||||
|
|
@ -45,6 +46,19 @@ async def init_build(graph_data: dict):
|
|||
return JSONResponse(content={"flowId": flow_id})
|
||||
|
||||
|
||||
@router.get("/build/{flow_id}/status")
|
||||
async def build_status(flow_id: str):
|
||||
"""Check the flow_id is in the flow_data_store."""
|
||||
try:
|
||||
if flow_id in flow_data_store:
|
||||
return JSONResponse(content={"built": True})
|
||||
else:
|
||||
return JSONResponse(content={"built": False})
|
||||
except Exception as exc:
|
||||
logger.error(exc)
|
||||
return HTTPException(status_code=500, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/build/stream/{flow_id}", response_class=StreamingResponse)
|
||||
async def stream_build(flow_id: str):
|
||||
"""Stream the build process based on stored flow data."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue