|
22 | 22 | import fastapi
|
23 | 23 | import logfire
|
24 | 24 | from fastapi import Depends, Request
|
25 |
| -from fastapi.responses import HTMLResponse, Response, StreamingResponse |
26 |
| -from pydantic import Field, TypeAdapter |
| 25 | +from fastapi.responses import FileResponse, Response, StreamingResponse |
27 | 26 | from typing_extensions import LiteralString, ParamSpec, TypedDict
|
28 | 27 |
|
29 | 28 | from pydantic_ai import Agent
|
@@ -55,14 +54,14 @@ async def lifespan(_app: fastapi.FastAPI):
|
55 | 54 |
|
56 | 55 |
|
57 | 56 | @app.get('/')
|
58 |
| -async def index() -> HTMLResponse: |
59 |
| - return HTMLResponse((THIS_DIR / 'chat_app.html').read_bytes()) |
| 57 | +async def index() -> FileResponse: |
| 58 | + return FileResponse((THIS_DIR / 'chat_app.html'), media_type='text/html') |
60 | 59 |
|
61 | 60 |
|
62 | 61 | @app.get('/chat_app.ts')
|
63 |
| -async def main_ts() -> Response: |
| 62 | +async def main_ts() -> FileResponse: |
64 | 63 | """Get the raw typescript code, it's compiled in the browser, forgive me."""
|
65 |
| - return Response((THIS_DIR / 'chat_app.ts').read_bytes(), media_type='text/plain') |
| 64 | + return FileResponse((THIS_DIR / 'chat_app.ts'), media_type='text/plain') |
66 | 65 |
|
67 | 66 |
|
68 | 67 | async def get_db(request: Request) -> Database:
|
@@ -138,9 +137,6 @@ async def stream_messages():
|
138 | 137 | return StreamingResponse(stream_messages(), media_type='text/plain')
|
139 | 138 |
|
140 | 139 |
|
141 |
| -MessageTypeAdapter: TypeAdapter[ModelMessage] = TypeAdapter( |
142 |
| - Annotated[ModelMessage, Field(discriminator='kind')] |
143 |
| -) |
144 | 140 | P = ParamSpec('P')
|
145 | 141 | R = TypeVar('R')
|
146 | 142 |
|
|
0 commit comments