-
Couldn't load subscription status.
- Fork 1.3k
Support Vercel AI Data Stream Protocol #2923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Docs Preview
|
|
This would be a wonderful addon, looking forward to see it soon in main. |
|
@samuelcolvin can you add it to docs such that it would be integrated as chat service in existing Fullstack apps that uses pydantic-ai as Agent stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this! I left some comments on the code and I will try to test this and get back.
pydantic_ai_slim/pydantic_ai/vercel_ai_elements/request_types.py
Outdated
Show resolved
Hide resolved
pydantic_ai_slim/pydantic_ai/vercel_ai_elements/response_stream.py
Outdated
Show resolved
Hide resolved
pydantic_ai_slim/pydantic_ai/vercel_ai_elements/response_stream.py
Outdated
Show resolved
Hide resolved
pydantic_ai_slim/pydantic_ai/vercel_ai_elements/response_stream.py
Outdated
Show resolved
Hide resolved
# Conflicts: # examples/pydantic_ai_examples/chat_app.py # pydantic_ai_slim/pydantic_ai/agent/abstract.py # pydantic_ai_slim/pydantic_ai/run.py
|
fyi using this branch for datalayer/jupyter-ai-agents#45 🙏 for working on this. |
|
👀 Looking forward to seeing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all seems good, I'm amazed how big it's got.
I'm a bit unclear on what the public API will be?
| part: ModelResponsePart | ||
| """The newly started `ModelResponsePart`.""" | ||
|
|
||
| previous_part_kind: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think put this explanation in the docstring.
|
|
||
| ModelResponseStreamEvent = Annotated[ | ||
| PartStartEvent | PartDeltaEvent | FinalResultEvent, pydantic.Discriminator('event_kind') | ||
| PartStartEvent | PartDeltaEvent | PartEndEvent | FinalResultEvent, pydantic.Discriminator('event_kind') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we should have an equivilant of https://docs.pydantic.dev/latest/version-policy/ where we say what we consider a breaking change, and we explicitly say we can change messages without considering a breaking change.
# Conflicts: # pyproject.toml # tests/models/test_deepseek.py # tests/models/test_huggingface.py # uv.lock
# Conflicts: # docs/ui/ag-ui.md # examples/pydantic_ai_examples/ag_ui/api/agentic_chat.py # examples/pydantic_ai_examples/ag_ui/api/tool_based_generative_ui.py
To do:
clai weborAgent.to_web()?This adds support for Vercel AI Elements streams to Pydantic AI.
There's an example frontend in a separate repo github.com/pydantic/pydantic-ai-chat the plan is to either make that into a more complete template, or release a
pydantic-ai-chatpython library which contains a pre-built react frontend.@DouweM we should rename this to use the proper terminology of the "Vercel AI Data Stream Protocol"
Here's a demo of basic usage:
pydantic-ai-chat.mp4