MCPcopy
hub / github.com/benoitc/gunicorn / chat_sync

Function chat_sync

examples/streaming_chat/main.py:65–88  ·  view source on GitHub ↗

Non-streaming chat endpoint for comparison. Waits for the complete response before returning. Useful for testing or when streaming isn't needed. Args: request: Chat request with prompt Returns: Complete response as JSON

(request: ChatRequest)

Source from the content-addressed store, hash-verified

63
64@app.post("/chat/sync", response_model=ChatResponse)
65async def chat_sync(request: ChatRequest):
66 """Non-streaming chat endpoint for comparison.
67
68 Waits for the complete response before returning.
69 Useful for testing or when streaming isn't needed.
70
71 Args:
72 request: Chat request with prompt
73
74 Returns:
75 Complete response as JSON
76 """
77 client = await get_dirty_client_async()
78 action = "generate_with_thinking" if request.thinking else "generate"
79
80 tokens = []
81 async for token in client.stream_async(
82 "streaming_chat.chat_app:ChatApp",
83 action,
84 request.prompt
85 ):
86 tokens.append(token)
87
88 return ChatResponse(response="".join(tokens))
89
90
91@app.get("/health")

Callers

nothing calls this directly

Calls 3

get_dirty_client_asyncFunction · 0.90
ChatResponseClass · 0.85
stream_asyncMethod · 0.80

Tested by

no test coverage detected