Skip to content

Commit 1831da1

Browse files
add model documentation (#250)
Co-authored-by: Sydney Runkle <[email protected]>
1 parent b08874b commit 1831da1

File tree

21 files changed

+590
-382
lines changed

21 files changed

+590
-382
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ all: format lint typecheck testcov ## Run code formatting, linting, static type
114114

115115
.PHONY: help
116116
help: ## Show this help (usage: make help)
117-
@echo "Usage: make [target]"
118-
@echo "Targets:"
117+
@echo "Usage: make [recipe]"
118+
@echo "Recipes:"
119119
@awk '/^[a-zA-Z0-9_-]+:.*?##/ { \
120120
helpMessage = match($$0, /## (.*)/); \
121121
if (helpMessage) { \
122-
target = $$1; \
123-
sub(/:/, "", target); \
124-
printf " \033[36m%-20s\033[0m %s\n", target, substr($$0, RSTART + 3, RLENGTH); \
122+
recipe = $$1; \
123+
sub(/:/, "", recipe); \
124+
printf " \033[36m%-20s\033[0m %s\n", recipe, substr($$0, RSTART + 3, RLENGTH); \
125125
} \
126126
}' $(MAKEFILE_LIST)

docs/api/models/anthropic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
## Setup
44

5-
For details on how to set up authentication with this model, see [model configuration for Anthropic](../../install.md#anthropic).
5+
For details on how to set up authentication with this model, see [model configuration for Anthropic](../../models.md#anthropic).
66

77
::: pydantic_ai.models.anthropic

docs/api/models/function.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,49 @@
22

33
A model controlled by a local function.
44

5-
[`FunctionModel`][pydantic_ai.models.function.FunctionModel] is similar to [`TestModel`][pydantic_ai.models.test.TestModel],
5+
[`FunctionModel`][pydantic_ai.models.function.FunctionModel] is similar to [`TestModel`](test.md),
66
but allows greater control over the model's behavior.
77

88
Its primary use case is for more advanced unit testing than is possible with `TestModel`.
99

10+
Here's a minimal example:
11+
12+
```py {title="function_model_usage.py" call_name="test_my_agent" lint="not-imports"}
13+
from pydantic_ai import Agent
14+
from pydantic_ai.messages import Message, ModelResponse
15+
from pydantic_ai.models.function import FunctionModel, AgentInfo
16+
17+
my_agent = Agent('openai:gpt-4o')
18+
19+
20+
async def model_function(messages: list[Message], info: AgentInfo) -> ModelResponse:
21+
print(messages)
22+
"""
23+
[
24+
UserPrompt(
25+
content='Testing my agent...',
26+
timestamp=datetime.datetime(...),
27+
role='user',
28+
message_kind='user-prompt',
29+
)
30+
]
31+
"""
32+
print(info)
33+
"""
34+
AgentInfo(
35+
function_tools=[], allow_text_result=True, result_tools=[], model_settings=None
36+
)
37+
"""
38+
return ModelResponse.from_text('hello world')
39+
40+
41+
async def test_my_agent():
42+
"""Unit test for my_agent, to be run by pytest."""
43+
with my_agent.override(model=FunctionModel(model_function)):
44+
result = await my_agent.run('Testing my agent...')
45+
assert result.data == 'hello world'
46+
```
47+
48+
See [Unit testing with `FunctionModel`](../../testing-evals.md#unit-testing-with-functionmodel) for detailed documentation.
49+
1050
::: pydantic_ai.models.function

docs/api/models/gemini.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Despite these shortcomings, the Gemini model is actually quite powerful and very
1515

1616
## Setup
1717

18-
For details on how to set up authentication with this model, see [model configuration for Gemini](../../install.md#gemini).
18+
For details on how to set up authentication with this model, see [model configuration for Gemini](../../models.md#gemini).
1919

2020
::: pydantic_ai.models.gemini

docs/api/models/groq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
## Setup
44

5-
For details on how to set up authentication with this model, see [model configuration for Groq](../../install.md#groq).
5+
For details on how to set up authentication with this model, see [model configuration for Groq](../../models.md#groq).
66

77
::: pydantic_ai.models.groq

docs/api/models/mistral.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# `pydantic_ai.models.mistral`
22

3+
## Setup
4+
5+
For details on how to set up authentication with this model, see [model configuration for Mistral](../../models.md#mistral).
6+
37
::: pydantic_ai.models.mistral

docs/api/models/ollama.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Setup
44

5-
For details on how to set up authentication with this model, see [model configuration for Ollama](../../install.md#ollama).
5+
For details on how to set up authentication with this model, see [model configuration for Ollama](../../models.md#ollama).
66

77
## Example local usage
88

docs/api/models/openai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
## Setup
44

5-
For details on how to set up authentication with this model, see [model configuration for OpenAI](../../install.md#openai).
5+
For details on how to set up authentication with this model, see [model configuration for OpenAI](../../models.md#openai).
66

77
::: pydantic_ai.models.openai

docs/api/models/test.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,24 @@
22

33
Utility model for quickly testing apps built with PydanticAI.
44

5+
Here's a minimal example:
6+
7+
```py {title="test_model_usage.py" call_name="test_my_agent" lint="not-imports"}
8+
from pydantic_ai import Agent
9+
from pydantic_ai.models.test import TestModel
10+
11+
my_agent = Agent('openai:gpt-4o', system_prompt='...')
12+
13+
14+
async def test_my_agent():
15+
"""Unit test for my_agent, to be run by pytest."""
16+
m = TestModel()
17+
with my_agent.override(model=m):
18+
result = await my_agent.run('Testing my agent...')
19+
assert result.data == 'success (no tool calls)'
20+
assert m.agent_model_function_tools == []
21+
```
22+
23+
See [Unit testing with `TestModel`](../../testing-evals.md#unit-testing-with-testmodel) for detailed documentation.
24+
525
::: pydantic_ai.models.test

docs/api/models/vertexai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ having the same schemas as the equivalent [Gemini endpoints][pydantic_ai.models.
1313
## Setup
1414

1515
For details on how to set up authentication with this model as well as a comparison with the `generativelanguage.googleapis.com` API used by [`GeminiModel`][pydantic_ai.models.gemini.GeminiModel],
16-
see [model configuration for Gemini via VertexAI](../../install.md#gemini-via-vertexai).
16+
see [model configuration for Gemini via VertexAI](../../models.md#gemini-via-vertexai).
1717

1818
## Example Usage
1919

0 commit comments

Comments
 (0)