Skip to content

Commit

Permalink
examples: add assistant-stream hello world example (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Oct 14, 2024
1 parent e7d8b3a commit 4966a62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/assistant-stream-hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
20 changes: 20 additions & 0 deletions python/assistant-stream-hello-world/api/chat/completions/index.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions python/assistant-stream-hello-world/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assistant-stream==0.0.2
fastapi==0.115.0

0 comments on commit 4966a62

Please sign in to comment.