Skip to content

Commit

Permalink
Clean chat_app example (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
DurandA authored Dec 27, 2024
1 parent 875d5eb commit e9bdb04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/pydantic_ai_examples/chat_app.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
font-weight: bold;
display: block;
}
#conversation .llm-response::before {
#conversation .model::before {
content: 'AI Response: ';
font-weight: bold;
display: block;
Expand Down
14 changes: 5 additions & 9 deletions examples/pydantic_ai_examples/chat_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import fastapi
import logfire
from fastapi import Depends, Request
from fastapi.responses import HTMLResponse, Response, StreamingResponse
from pydantic import Field, TypeAdapter
from fastapi.responses import FileResponse, Response, StreamingResponse
from typing_extensions import LiteralString, ParamSpec, TypedDict

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


@app.get('/')
async def index() -> HTMLResponse:
return HTMLResponse((THIS_DIR / 'chat_app.html').read_bytes())
async def index() -> FileResponse:
return FileResponse((THIS_DIR / 'chat_app.html'), media_type='text/html')


@app.get('/chat_app.ts')
async def main_ts() -> Response:
async def main_ts() -> FileResponse:
"""Get the raw typescript code, it's compiled in the browser, forgive me."""
return Response((THIS_DIR / 'chat_app.ts').read_bytes(), media_type='text/plain')
return FileResponse((THIS_DIR / 'chat_app.ts'), media_type='text/plain')


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


MessageTypeAdapter: TypeAdapter[ModelMessage] = TypeAdapter(
Annotated[ModelMessage, Field(discriminator='kind')]
)
P = ParamSpec('P')
R = TypeVar('R')

Expand Down

0 comments on commit e9bdb04

Please sign in to comment.