(
*,
request: Request,
username: str,
service: ChatService,
payload: dict[str, Any] | None = None,
)
| 81 | |
| 82 | |
| 83 | async def _send_chat( |
| 84 | *, |
| 85 | request: Request, |
| 86 | username: str, |
| 87 | service: ChatService, |
| 88 | payload: dict[str, Any] | None = None, |
| 89 | ): |
| 90 | post_data = payload if payload is not None else await _json_or_none(request) |
| 91 | if post_data is None: |
| 92 | return JSONResponse(error("Missing JSON body")) |
| 93 | |
| 94 | try: |
| 95 | stream = await service.build_chat_stream(username, post_data) |
| 96 | except ChatServiceError as exc: |
| 97 | return JSONResponse(error(str(exc))) |
| 98 | |
| 99 | return StreamingResponse( |
| 100 | stream, |
| 101 | media_type="text/event-stream", |
| 102 | headers={ |
| 103 | "Cache-Control": "no-cache", |
| 104 | "Transfer-Encoding": "chunked", |
| 105 | "Connection": "keep-alive", |
| 106 | }, |
| 107 | ) |
| 108 | |
| 109 | |
| 110 | @router.get("/chat/sessions/new") |
no test coverage detected