Skip to content

Commit e9bdb04

Browse files
authored
Clean chat_app example (#553)
1 parent 875d5eb commit e9bdb04

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

examples/pydantic_ai_examples/chat_app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
font-weight: bold;
1515
display: block;
1616
}
17-
#conversation .llm-response::before {
17+
#conversation .model::before {
1818
content: 'AI Response: ';
1919
font-weight: bold;
2020
display: block;

examples/pydantic_ai_examples/chat_app.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import fastapi
2323
import logfire
2424
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
2726
from typing_extensions import LiteralString, ParamSpec, TypedDict
2827

2928
from pydantic_ai import Agent
@@ -55,14 +54,14 @@ async def lifespan(_app: fastapi.FastAPI):
5554

5655

5756
@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')
6059

6160

6261
@app.get('/chat_app.ts')
63-
async def main_ts() -> Response:
62+
async def main_ts() -> FileResponse:
6463
"""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')
6665

6766

6867
async def get_db(request: Request) -> Database:
@@ -138,9 +137,6 @@ async def stream_messages():
138137
return StreamingResponse(stream_messages(), media_type='text/plain')
139138

140139

141-
MessageTypeAdapter: TypeAdapter[ModelMessage] = TypeAdapter(
142-
Annotated[ModelMessage, Field(discriminator='kind')]
143-
)
144140
P = ParamSpec('P')
145141
R = TypeVar('R')
146142

0 commit comments

Comments
 (0)