-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add assistant-stream hello world example (#1000)
- Loading branch information
Showing
3 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vercel |
20 changes: 20 additions & 0 deletions
20
python/assistant-stream-hello-world/api/chat/completions/index.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
assistant-stream==0.0.2 | ||
fastapi==0.115.0 |