-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c3041f
commit cd47b0f
Showing
24 changed files
with
200 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# `pydantic_ai.Agent` | ||
|
||
::: pydantic_ai.Agent | ||
options: | ||
members: | ||
- __init__ | ||
- run | ||
- run_sync | ||
- run_stream | ||
- model | ||
- override_deps | ||
- override_model | ||
- last_run_messages | ||
- system_prompt | ||
- retriever_plain | ||
- retriever_context | ||
- result_validator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `pydantic_ai.dependencies` | ||
|
||
::: pydantic_ai.dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `pydantic_ai.exceptions` | ||
|
||
::: pydantic_ai.exceptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# `pydantic_ai.messages` | ||
|
||
::: pydantic_ai.messages | ||
options: | ||
members: | ||
- Message | ||
- SystemPrompt | ||
- UserPrompt | ||
- ToolReturn | ||
- RetryPrompt | ||
- ModelAnyResponse | ||
- ModelTextResponse | ||
- ModelStructuredResponse | ||
- ToolCall | ||
- ArgsJson | ||
- ArgsObject | ||
- MessagesTypeAdapter |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# FunctionModel | ||
# `pydantic_ai.models.function` | ||
|
||
::: pydantic_ai.models.function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Gemini | ||
# `pydantic_ai.models.gemini` | ||
|
||
::: pydantic_ai.models.gemini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# OpenAI | ||
# `pydantic_ai.models.openai` | ||
|
||
::: pydantic_ai.models.openai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# TestModel | ||
# `pydantic_ai.models.test` | ||
|
||
::: pydantic_ai.models.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# `pydantic_ai.result` | ||
|
||
::: pydantic_ai.result | ||
options: | ||
inherited_members: true | ||
members: | ||
- ResultData | ||
- RunResult | ||
- StreamedRunResult | ||
- Cost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Monitoring and Performance | ||
|
||
Applications that use LLMs have some challenges that are well known and understood: LLMs are **slow**, **unreliable** and **expensive**. | ||
These applications also have some challenges that most developers have encountered much less often: they're **fickle** and **non-deterministic**. Subtle changes in a prompt can completely change a model's performance, and there's no `EXPLAIN` query you can run to understand why. | ||
|
||
From a software engineers point of view, you can think of LLMs as the worst database you've ever heard of, but worse. | ||
|
||
To build successful applications with LLMs, we need new tools to understand both model performance, and the behavior of applications that rely on them. | ||
|
||
LLM Observability tools that just let you understand how your model is performing are useless: making API calls to an LLM is easy, it's building that into an application that's hard. | ||
|
||
## Pydantic Logfire | ||
|
||
[Pydantic Logfire](https://pydantic.dev/logfire) is an observability platform from the developers of Pydantic and PydanticAI, that aims to let you understand your entire application: Gen AI, classic predictive AI, HTTP traffic, database queries and everything else a modern application needs. | ||
|
||
!!! note "Pydantic Logfire is a commercial product" | ||
Logfire is a commercially supported, hosted platform with an extremely generous and perpetual free tier. | ||
You can sign up and start using Logfire in a couple of minutes. | ||
|
||
PydanticAI has built-in (but optional) support for Logfire via the [`logfire-api`](https://github.com/pydantic/logfire/tree/main/logfire-api) no-op package. | ||
|
||
That means if the `logfire` package is installed, detailed information about agent runs is sent to Logfire. But if the `logfire` package is not installed, there's no overhead and nothing is sent. | ||
|
||
Here's an example showing details of running the [Weather Agent](examples/weather-agent.md) in Logfire: | ||
|
||
![Weather Agent Logfire](img/logfire-weather-agent.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
## Ending runs | ||
|
||
TODO | ||
**TODO** | ||
|
||
* runs end when either a plain text response is received or the model calls a tool associated with one of the structured result types | ||
* example | ||
* we should add `message_limit` (number of model messages) and `cost_limit` to `run()` etc. | ||
|
||
## Structured result validation | ||
|
||
**TODO** | ||
|
||
* structured results (like retrievers) use Pydantic, Pydantic builds the JSON schema and does the validation | ||
* PydanticAI tries hard to simplify the schema, this means: | ||
* if the return type is `str` or a union including `str`, plain text responses are enabled | ||
* if the schema is a union (after remove `str` from the members), each member is registered as its own tool call | ||
* if the schema is not an object, the result type is wrapped in a single element object | ||
|
||
## Result validators functions | ||
|
||
TODO | ||
**TODO** | ||
|
||
* Some validation is inconvenient or impossible to do in Pydantic validators, in particular when the validation requires IO and is asynchronous. PydanticAI provides a way to add validation functions via the [`agent.result_validator`][pydantic_ai.Agent.result_validator] decorator. | ||
* example | ||
|
||
## Streamed Results | ||
|
||
TODO | ||
**TODO** | ||
|
||
## Cost | ||
Streamed responses provide a unique challenge: | ||
* validating the partial result is both practically and semantically complex, but pydantic can do this | ||
* we don't know if a result will be the final result of a run until we start streaming it, so PydanticAI has to start streaming just enough of the response to sniff out if it's the final response, then either stream the rest of the response to call a retriever, or return an object that lets the rest of the response be streamed by the user | ||
* examples including: streaming text, streaming validated data, streaming the raw data to do validation inside a try/except block when necessary | ||
* explanation of how streamed responses are "debounced" | ||
|
||
TODO | ||
## Cost | ||
|
||
## API Reference | ||
**TODO** | ||
|
||
::: pydantic_ai.result | ||
options: | ||
inherited_members: true | ||
members: | ||
- ResultData | ||
- RunResult | ||
- StreamedRunResult | ||
- Cost | ||
* counts tokens, not dollars | ||
* example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
INHERIT: mkdocs.yml | ||
|
||
markdown_extensions: | ||
- tables | ||
- admonition | ||
- attr_list | ||
- md_in_html | ||
- pymdownx.details | ||
- pymdownx.caret | ||
- pymdownx.critic | ||
- pymdownx.mark | ||
- pymdownx.superfences | ||
- pymdownx.snippets | ||
- pymdownx.tilde | ||
- pymdownx.inlinehilite | ||
- pymdownx.highlight: | ||
pygments_lang_class: true | ||
- pymdownx.extra: | ||
pymdownx.superfences: | ||
custom_fences: | ||
- name: mermaid | ||
class: mermaid | ||
format: !!python/name:pymdownx.superfences.fence_code_format | ||
- pymdownx.emoji: | ||
emoji_index: !!python/name:material.extensions.emoji.twemoji | ||
emoji_generator: !!python/name:material.extensions.emoji.to_svg | ||
- pymdownx.tabbed: | ||
alternate_style: true | ||
- pymdownx.tasklist: | ||
custom_checkbox: true | ||
- sane_lists # this means you can start a list from any number | ||
- material.extensions.preview: | ||
targets: | ||
include: | ||
- '*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.