Buckets:
AnonymousSpottedToad/human_verified_bucket / codebase /python /Quansight_ragna /tests /assistants /streaming_server.py
| import json | |
| import random | |
| import sse_starlette | |
| from fastapi import FastAPI, Request, Response, status | |
| from fastapi.responses import StreamingResponse | |
| app = FastAPI() | |
| async def health(): | |
| return Response(b"", status_code=status.HTTP_200_OK) | |
| async def sse(request: Request): | |
| data = await request.json() | |
| async def stream(): | |
| for obj in data: | |
| yield sse_starlette.ServerSentEvent(json.dumps(obj)) | |
| return sse_starlette.EventSourceResponse(stream()) | |
| async def jsonl(request: Request): | |
| data = await request.json() | |
| async def stream(): | |
| for obj in data: | |
| yield f"{json.dumps(obj)}\n" | |
| return StreamingResponse(stream()) | |
| async def json_(request: Request): | |
| data = await request.body() | |
| async def stream(): | |
| start = 0 | |
| while start < len(data): | |
| end = start + random.randint(1, 10) | |
| yield data[start:end] | |
| start = end | |
| return StreamingResponse(stream()) | |
Xet Storage Details
- Size:
- 1.05 kB
- Xet hash:
- f67da19b36df68298ec352aa8661ae356578893b37dc97748dde5418fdfb6727
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.