chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:39:17 +08:00
commit 4ed4e9ff99
1368 changed files with 334957 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
from collections.abc import AsyncIterator
from fastapi import FastAPI
from starlette.responses import StreamingResponse
from agents import Agent, Runner, RunResultStreaming
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
)
app = FastAPI()
@app.post("/stream")
async def stream():
result = Runner.run_streamed(agent, input="Tell me a joke")
stream_handler = StreamHandler(result)
return StreamingResponse(stream_handler.stream_events(), media_type="application/x-ndjson")
class StreamHandler:
def __init__(self, result: RunResultStreaming):
self.result = result
async def stream_events(self) -> AsyncIterator[str]:
async for event in self.result.stream_events():
yield f"{event.type}\n\n"