diff --git a/python/assistant-stream-hello-world/.gitignore b/python/assistant-stream-hello-world/.gitignore new file mode 100644 index 0000000000..e985853ed8 --- /dev/null +++ b/python/assistant-stream-hello-world/.gitignore @@ -0,0 +1 @@ +.vercel diff --git a/python/assistant-stream-hello-world/api/chat/completions/index.py b/python/assistant-stream-hello-world/api/chat/completions/index.py new file mode 100644 index 0000000000..8ed9236e65 --- /dev/null +++ b/python/assistant-stream-hello-world/api/chat/completions/index.py @@ -0,0 +1,20 @@ +from assistant_stream import create_run, RunController +from assistant_stream.serialization import DataStreamResponse + +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +import asyncio + +app = FastAPI() +app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"]) + + +@app.post("/api/chat/completions") +async def chat_completions(): + async def run(controller: RunController): + controller.append_text("Hello ") + await asyncio.sleep(1) + controller.append_text("world.") + + return DataStreamResponse(create_run(run)) diff --git a/python/assistant-stream-hello-world/requirements.txt b/python/assistant-stream-hello-world/requirements.txt new file mode 100644 index 0000000000..7a5210fb05 --- /dev/null +++ b/python/assistant-stream-hello-world/requirements.txt @@ -0,0 +1,2 @@ +assistant-stream==0.0.2 +fastapi==0.115.0