pydantic-ai-slim 0.0.45__py3-none-any.whl → 0.0.47__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pydantic-ai-slim might be problematic. Click here for more details.
- pydantic_ai/__main__.py +6 -0
- pydantic_ai/_agent_graph.py +19 -13
- pydantic_ai/_cli.py +120 -77
- pydantic_ai/_result.py +4 -1
- pydantic_ai/_utils.py +1 -1
- pydantic_ai/agent.py +32 -32
- pydantic_ai/mcp.py +25 -1
- pydantic_ai/messages.py +1 -1
- pydantic_ai/models/__init__.py +221 -199
- pydantic_ai/models/anthropic.py +4 -1
- pydantic_ai/models/bedrock.py +7 -0
- pydantic_ai/models/cohere.py +4 -1
- pydantic_ai/models/gemini.py +4 -1
- pydantic_ai/models/groq.py +32 -15
- pydantic_ai/models/instrumented.py +6 -1
- pydantic_ai/models/mistral.py +6 -1
- pydantic_ai/models/openai.py +6 -3
- pydantic_ai/providers/anthropic.py +2 -1
- pydantic_ai/providers/azure.py +1 -1
- pydantic_ai/providers/bedrock.py +11 -0
- pydantic_ai/providers/cohere.py +2 -3
- pydantic_ai/providers/deepseek.py +2 -1
- pydantic_ai/providers/google_gla.py +1 -1
- pydantic_ai/providers/google_vertex.py +1 -1
- pydantic_ai/providers/groq.py +2 -3
- pydantic_ai/providers/mistral.py +2 -1
- pydantic_ai/providers/openai.py +2 -1
- pydantic_ai/tools.py +32 -1
- {pydantic_ai_slim-0.0.45.dist-info → pydantic_ai_slim-0.0.47.dist-info}/METADATA +6 -4
- pydantic_ai_slim-0.0.47.dist-info/RECORD +51 -0
- pydantic_ai_slim-0.0.45.dist-info/RECORD +0 -50
- {pydantic_ai_slim-0.0.45.dist-info → pydantic_ai_slim-0.0.47.dist-info}/WHEEL +0 -0
- {pydantic_ai_slim-0.0.45.dist-info → pydantic_ai_slim-0.0.47.dist-info}/entry_points.txt +0 -0
pydantic_ai/messages.py
CHANGED
|
@@ -9,7 +9,7 @@ from typing import Annotated, Any, Literal, Union, cast, overload
|
|
|
9
9
|
|
|
10
10
|
import pydantic
|
|
11
11
|
import pydantic_core
|
|
12
|
-
from opentelemetry._events import Event
|
|
12
|
+
from opentelemetry._events import Event # pyright: ignore[reportPrivateImportUsage]
|
|
13
13
|
from typing_extensions import TypeAlias
|
|
14
14
|
|
|
15
15
|
from ._utils import generate_tool_call_id as _generate_tool_call_id, now_utc as _now_utc
|
pydantic_ai/models/__init__.py
CHANGED
|
@@ -12,10 +12,10 @@ from contextlib import asynccontextmanager, contextmanager
|
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
13
|
from datetime import datetime
|
|
14
14
|
from functools import cache
|
|
15
|
-
from typing import TYPE_CHECKING
|
|
15
|
+
from typing import TYPE_CHECKING
|
|
16
16
|
|
|
17
17
|
import httpx
|
|
18
|
-
from typing_extensions import Literal
|
|
18
|
+
from typing_extensions import Literal, TypeAliasType
|
|
19
19
|
|
|
20
20
|
from .._parts_manager import ModelResponsePartsManager
|
|
21
21
|
from ..exceptions import UserError
|
|
@@ -27,195 +27,209 @@ if TYPE_CHECKING:
|
|
|
27
27
|
from ..tools import ToolDefinition
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
KnownModelName =
|
|
31
|
-
'
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
30
|
+
KnownModelName = TypeAliasType(
|
|
31
|
+
'KnownModelName',
|
|
32
|
+
Literal[
|
|
33
|
+
'anthropic:claude-3-7-sonnet-latest',
|
|
34
|
+
'anthropic:claude-3-5-haiku-latest',
|
|
35
|
+
'anthropic:claude-3-5-sonnet-latest',
|
|
36
|
+
'anthropic:claude-3-opus-latest',
|
|
37
|
+
'claude-3-7-sonnet-latest',
|
|
38
|
+
'claude-3-5-haiku-latest',
|
|
39
|
+
'bedrock:amazon.titan-tg1-large',
|
|
40
|
+
'bedrock:amazon.titan-text-lite-v1',
|
|
41
|
+
'bedrock:amazon.titan-text-express-v1',
|
|
42
|
+
'bedrock:us.amazon.nova-pro-v1:0',
|
|
43
|
+
'bedrock:us.amazon.nova-lite-v1:0',
|
|
44
|
+
'bedrock:us.amazon.nova-micro-v1:0',
|
|
45
|
+
'bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
46
|
+
'bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
47
|
+
'bedrock:anthropic.claude-3-5-haiku-20241022-v1:0',
|
|
48
|
+
'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0',
|
|
49
|
+
'bedrock:anthropic.claude-instant-v1',
|
|
50
|
+
'bedrock:anthropic.claude-v2:1',
|
|
51
|
+
'bedrock:anthropic.claude-v2',
|
|
52
|
+
'bedrock:anthropic.claude-3-sonnet-20240229-v1:0',
|
|
53
|
+
'bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0',
|
|
54
|
+
'bedrock:anthropic.claude-3-haiku-20240307-v1:0',
|
|
55
|
+
'bedrock:us.anthropic.claude-3-haiku-20240307-v1:0',
|
|
56
|
+
'bedrock:anthropic.claude-3-opus-20240229-v1:0',
|
|
57
|
+
'bedrock:us.anthropic.claude-3-opus-20240229-v1:0',
|
|
58
|
+
'bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0',
|
|
59
|
+
'bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0',
|
|
60
|
+
'bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0',
|
|
61
|
+
'bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0',
|
|
62
|
+
'bedrock:cohere.command-text-v14',
|
|
63
|
+
'bedrock:cohere.command-r-v1:0',
|
|
64
|
+
'bedrock:cohere.command-r-plus-v1:0',
|
|
65
|
+
'bedrock:cohere.command-light-text-v14',
|
|
66
|
+
'bedrock:meta.llama3-8b-instruct-v1:0',
|
|
67
|
+
'bedrock:meta.llama3-70b-instruct-v1:0',
|
|
68
|
+
'bedrock:meta.llama3-1-8b-instruct-v1:0',
|
|
69
|
+
'bedrock:us.meta.llama3-1-8b-instruct-v1:0',
|
|
70
|
+
'bedrock:meta.llama3-1-70b-instruct-v1:0',
|
|
71
|
+
'bedrock:us.meta.llama3-1-70b-instruct-v1:0',
|
|
72
|
+
'bedrock:meta.llama3-1-405b-instruct-v1:0',
|
|
73
|
+
'bedrock:us.meta.llama3-2-11b-instruct-v1:0',
|
|
74
|
+
'bedrock:us.meta.llama3-2-90b-instruct-v1:0',
|
|
75
|
+
'bedrock:us.meta.llama3-2-1b-instruct-v1:0',
|
|
76
|
+
'bedrock:us.meta.llama3-2-3b-instruct-v1:0',
|
|
77
|
+
'bedrock:us.meta.llama3-3-70b-instruct-v1:0',
|
|
78
|
+
'bedrock:mistral.mistral-7b-instruct-v0:2',
|
|
79
|
+
'bedrock:mistral.mixtral-8x7b-instruct-v0:1',
|
|
80
|
+
'bedrock:mistral.mistral-large-2402-v1:0',
|
|
81
|
+
'bedrock:mistral.mistral-large-2407-v1:0',
|
|
82
|
+
'claude-3-5-sonnet-latest',
|
|
83
|
+
'claude-3-opus-latest',
|
|
84
|
+
'cohere:c4ai-aya-expanse-32b',
|
|
85
|
+
'cohere:c4ai-aya-expanse-8b',
|
|
86
|
+
'cohere:command',
|
|
87
|
+
'cohere:command-light',
|
|
88
|
+
'cohere:command-light-nightly',
|
|
89
|
+
'cohere:command-nightly',
|
|
90
|
+
'cohere:command-r',
|
|
91
|
+
'cohere:command-r-03-2024',
|
|
92
|
+
'cohere:command-r-08-2024',
|
|
93
|
+
'cohere:command-r-plus',
|
|
94
|
+
'cohere:command-r-plus-04-2024',
|
|
95
|
+
'cohere:command-r-plus-08-2024',
|
|
96
|
+
'cohere:command-r7b-12-2024',
|
|
97
|
+
'deepseek:deepseek-chat',
|
|
98
|
+
'deepseek:deepseek-reasoner',
|
|
99
|
+
'google-gla:gemini-1.0-pro',
|
|
100
|
+
'google-gla:gemini-1.5-flash',
|
|
101
|
+
'google-gla:gemini-1.5-flash-8b',
|
|
102
|
+
'google-gla:gemini-1.5-pro',
|
|
103
|
+
'google-gla:gemini-2.0-flash-exp',
|
|
104
|
+
'google-gla:gemini-2.0-flash-thinking-exp-01-21',
|
|
105
|
+
'google-gla:gemini-exp-1206',
|
|
106
|
+
'google-gla:gemini-2.0-flash',
|
|
107
|
+
'google-gla:gemini-2.0-flash-lite-preview-02-05',
|
|
108
|
+
'google-gla:gemini-2.0-pro-exp-02-05',
|
|
109
|
+
'google-vertex:gemini-1.0-pro',
|
|
110
|
+
'google-vertex:gemini-1.5-flash',
|
|
111
|
+
'google-vertex:gemini-1.5-flash-8b',
|
|
112
|
+
'google-vertex:gemini-1.5-pro',
|
|
113
|
+
'google-vertex:gemini-2.0-flash-exp',
|
|
114
|
+
'google-vertex:gemini-2.0-flash-thinking-exp-01-21',
|
|
115
|
+
'google-vertex:gemini-exp-1206',
|
|
116
|
+
'google-vertex:gemini-2.0-flash',
|
|
117
|
+
'google-vertex:gemini-2.0-flash-lite-preview-02-05',
|
|
118
|
+
'google-vertex:gemini-2.0-pro-exp-02-05',
|
|
119
|
+
'gpt-3.5-turbo',
|
|
120
|
+
'gpt-3.5-turbo-0125',
|
|
121
|
+
'gpt-3.5-turbo-0301',
|
|
122
|
+
'gpt-3.5-turbo-0613',
|
|
123
|
+
'gpt-3.5-turbo-1106',
|
|
124
|
+
'gpt-3.5-turbo-16k',
|
|
125
|
+
'gpt-3.5-turbo-16k-0613',
|
|
126
|
+
'gpt-4',
|
|
127
|
+
'gpt-4-0125-preview',
|
|
128
|
+
'gpt-4-0314',
|
|
129
|
+
'gpt-4-0613',
|
|
130
|
+
'gpt-4-1106-preview',
|
|
131
|
+
'gpt-4-32k',
|
|
132
|
+
'gpt-4-32k-0314',
|
|
133
|
+
'gpt-4-32k-0613',
|
|
134
|
+
'gpt-4-turbo',
|
|
135
|
+
'gpt-4-turbo-2024-04-09',
|
|
136
|
+
'gpt-4-turbo-preview',
|
|
137
|
+
'gpt-4-vision-preview',
|
|
138
|
+
'gpt-4o',
|
|
139
|
+
'gpt-4o-2024-05-13',
|
|
140
|
+
'gpt-4o-2024-08-06',
|
|
141
|
+
'gpt-4o-2024-11-20',
|
|
142
|
+
'gpt-4o-audio-preview',
|
|
143
|
+
'gpt-4o-audio-preview-2024-10-01',
|
|
144
|
+
'gpt-4o-audio-preview-2024-12-17',
|
|
145
|
+
'gpt-4o-mini',
|
|
146
|
+
'gpt-4o-mini-2024-07-18',
|
|
147
|
+
'gpt-4o-mini-audio-preview',
|
|
148
|
+
'gpt-4o-mini-audio-preview-2024-12-17',
|
|
149
|
+
'gpt-4o-mini-search-preview',
|
|
150
|
+
'gpt-4o-mini-search-preview-2025-03-11',
|
|
151
|
+
'gpt-4o-search-preview',
|
|
152
|
+
'gpt-4o-search-preview-2025-03-11',
|
|
153
|
+
'groq:distil-whisper-large-v3-en',
|
|
154
|
+
'groq:gemma2-9b-it',
|
|
155
|
+
'groq:llama-3.3-70b-versatile',
|
|
156
|
+
'groq:llama-3.1-8b-instant',
|
|
157
|
+
'groq:llama-guard-3-8b',
|
|
158
|
+
'groq:llama3-70b-8192',
|
|
159
|
+
'groq:llama3-8b-8192',
|
|
160
|
+
'groq:whisper-large-v3',
|
|
161
|
+
'groq:whisper-large-v3-turbo',
|
|
162
|
+
'groq:playai-tts',
|
|
163
|
+
'groq:playai-tts-arabic',
|
|
164
|
+
'groq:qwen-qwq-32b',
|
|
165
|
+
'groq:mistral-saba-24b',
|
|
166
|
+
'groq:qwen-2.5-coder-32b',
|
|
167
|
+
'groq:qwen-2.5-32b',
|
|
168
|
+
'groq:deepseek-r1-distill-qwen-32b',
|
|
169
|
+
'groq:deepseek-r1-distill-llama-70b',
|
|
170
|
+
'groq:llama-3.3-70b-specdec',
|
|
171
|
+
'groq:llama-3.2-1b-preview',
|
|
172
|
+
'groq:llama-3.2-3b-preview',
|
|
173
|
+
'groq:llama-3.2-11b-vision-preview',
|
|
174
|
+
'groq:llama-3.2-90b-vision-preview',
|
|
175
|
+
'mistral:codestral-latest',
|
|
176
|
+
'mistral:mistral-large-latest',
|
|
177
|
+
'mistral:mistral-moderation-latest',
|
|
178
|
+
'mistral:mistral-small-latest',
|
|
179
|
+
'o1',
|
|
180
|
+
'o1-2024-12-17',
|
|
181
|
+
'o1-mini',
|
|
182
|
+
'o1-mini-2024-09-12',
|
|
183
|
+
'o1-preview',
|
|
184
|
+
'o1-preview-2024-09-12',
|
|
185
|
+
'o3-mini',
|
|
186
|
+
'o3-mini-2025-01-31',
|
|
187
|
+
'openai:chatgpt-4o-latest',
|
|
188
|
+
'openai:gpt-3.5-turbo',
|
|
189
|
+
'openai:gpt-3.5-turbo-0125',
|
|
190
|
+
'openai:gpt-3.5-turbo-0301',
|
|
191
|
+
'openai:gpt-3.5-turbo-0613',
|
|
192
|
+
'openai:gpt-3.5-turbo-1106',
|
|
193
|
+
'openai:gpt-3.5-turbo-16k',
|
|
194
|
+
'openai:gpt-3.5-turbo-16k-0613',
|
|
195
|
+
'openai:gpt-4',
|
|
196
|
+
'openai:gpt-4-0125-preview',
|
|
197
|
+
'openai:gpt-4-0314',
|
|
198
|
+
'openai:gpt-4-0613',
|
|
199
|
+
'openai:gpt-4-1106-preview',
|
|
200
|
+
'openai:gpt-4-32k',
|
|
201
|
+
'openai:gpt-4-32k-0314',
|
|
202
|
+
'openai:gpt-4-32k-0613',
|
|
203
|
+
'openai:gpt-4-turbo',
|
|
204
|
+
'openai:gpt-4-turbo-2024-04-09',
|
|
205
|
+
'openai:gpt-4-turbo-preview',
|
|
206
|
+
'openai:gpt-4-vision-preview',
|
|
207
|
+
'openai:gpt-4o',
|
|
208
|
+
'openai:gpt-4o-2024-05-13',
|
|
209
|
+
'openai:gpt-4o-2024-08-06',
|
|
210
|
+
'openai:gpt-4o-2024-11-20',
|
|
211
|
+
'openai:gpt-4o-audio-preview',
|
|
212
|
+
'openai:gpt-4o-audio-preview-2024-10-01',
|
|
213
|
+
'openai:gpt-4o-audio-preview-2024-12-17',
|
|
214
|
+
'openai:gpt-4o-mini',
|
|
215
|
+
'openai:gpt-4o-mini-2024-07-18',
|
|
216
|
+
'openai:gpt-4o-mini-audio-preview',
|
|
217
|
+
'openai:gpt-4o-mini-audio-preview-2024-12-17',
|
|
218
|
+
'openai:gpt-4o-mini-search-preview',
|
|
219
|
+
'openai:gpt-4o-mini-search-preview-2025-03-11',
|
|
220
|
+
'openai:gpt-4o-search-preview',
|
|
221
|
+
'openai:gpt-4o-search-preview-2025-03-11',
|
|
222
|
+
'openai:o1',
|
|
223
|
+
'openai:o1-2024-12-17',
|
|
224
|
+
'openai:o1-mini',
|
|
225
|
+
'openai:o1-mini-2024-09-12',
|
|
226
|
+
'openai:o1-preview',
|
|
227
|
+
'openai:o1-preview-2024-09-12',
|
|
228
|
+
'openai:o3-mini',
|
|
229
|
+
'openai:o3-mini-2025-01-31',
|
|
230
|
+
'test',
|
|
231
|
+
],
|
|
232
|
+
)
|
|
219
233
|
"""Known model names that can be used with the `model` parameter of [`Agent`][pydantic_ai.Agent].
|
|
220
234
|
|
|
221
235
|
`KnownModelName` is provided as a concise way to specify a model.
|
|
@@ -372,7 +386,7 @@ def override_allow_model_requests(allow_model_requests: bool) -> Iterator[None]:
|
|
|
372
386
|
ALLOW_MODEL_REQUESTS = old_value # pyright: ignore[reportConstantRedefinition]
|
|
373
387
|
|
|
374
388
|
|
|
375
|
-
def infer_model(model: Model | KnownModelName) -> Model:
|
|
389
|
+
def infer_model(model: Model | KnownModelName | str) -> Model:
|
|
376
390
|
"""Infer the model from the name."""
|
|
377
391
|
if isinstance(model, Model):
|
|
378
392
|
return model
|
|
@@ -383,7 +397,6 @@ def infer_model(model: Model | KnownModelName) -> Model:
|
|
|
383
397
|
|
|
384
398
|
try:
|
|
385
399
|
provider, model_name = model.split(':', maxsplit=1)
|
|
386
|
-
provider = cast(str, provider)
|
|
387
400
|
except ValueError:
|
|
388
401
|
model_name = model
|
|
389
402
|
# TODO(Marcelo): We should deprecate this way.
|
|
@@ -431,32 +444,41 @@ def infer_model(model: Model | KnownModelName) -> Model:
|
|
|
431
444
|
raise UserError(f'Unknown model: {model}')
|
|
432
445
|
|
|
433
446
|
|
|
434
|
-
def cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
|
|
435
|
-
"""Cached HTTPX async client
|
|
447
|
+
def cached_async_http_client(*, provider: str | None = None, timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
|
|
448
|
+
"""Cached HTTPX async client that creates a separate client for each provider.
|
|
449
|
+
|
|
450
|
+
The client is cached based on the provider parameter. If provider is None, it's used for non-provider specific
|
|
451
|
+
requests (like downloading images). Multiple agents and calls can share the same client when they use the same provider.
|
|
436
452
|
|
|
437
453
|
There are good reasons why in production you should use a `httpx.AsyncClient` as an async context manager as
|
|
438
454
|
described in [encode/httpx#2026](https://github.com/encode/httpx/pull/2026), but when experimenting or showing
|
|
439
|
-
examples, it's very useful not to
|
|
455
|
+
examples, it's very useful not to.
|
|
440
456
|
|
|
441
457
|
The default timeouts match those of OpenAI,
|
|
442
458
|
see <https://github.com/openai/openai-python/blob/v1.54.4/src/openai/_constants.py#L9>.
|
|
443
459
|
"""
|
|
444
|
-
client = _cached_async_http_client(timeout=timeout, connect=connect)
|
|
460
|
+
client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
|
|
445
461
|
if client.is_closed:
|
|
446
462
|
# This happens if the context manager is used, so we need to create a new client.
|
|
447
463
|
_cached_async_http_client.cache_clear()
|
|
448
|
-
client = _cached_async_http_client(timeout=timeout, connect=connect)
|
|
464
|
+
client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
|
|
449
465
|
return client
|
|
450
466
|
|
|
451
467
|
|
|
452
468
|
@cache
|
|
453
|
-
def _cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
|
|
469
|
+
def _cached_async_http_client(provider: str | None, timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
|
|
454
470
|
return httpx.AsyncClient(
|
|
471
|
+
transport=_cached_async_http_transport(),
|
|
455
472
|
timeout=httpx.Timeout(timeout=timeout, connect=connect),
|
|
456
473
|
headers={'User-Agent': get_user_agent()},
|
|
457
474
|
)
|
|
458
475
|
|
|
459
476
|
|
|
477
|
+
@cache
|
|
478
|
+
def _cached_async_http_transport() -> httpx.AsyncHTTPTransport:
|
|
479
|
+
return httpx.AsyncHTTPTransport()
|
|
480
|
+
|
|
481
|
+
|
|
460
482
|
@cache
|
|
461
483
|
def get_user_agent() -> str:
|
|
462
484
|
"""Get the user agent string for the HTTP client."""
|
pydantic_ai/models/anthropic.py
CHANGED
|
@@ -85,7 +85,10 @@ See [the Anthropic docs](https://docs.anthropic.com/en/docs/about-claude/models)
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
class AnthropicModelSettings(ModelSettings):
|
|
88
|
-
"""Settings used for an Anthropic model request.
|
|
88
|
+
"""Settings used for an Anthropic model request.
|
|
89
|
+
|
|
90
|
+
ALL FIELDS MUST BE `anthropic_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
|
|
91
|
+
"""
|
|
89
92
|
|
|
90
93
|
anthropic_metadata: MetadataParam
|
|
91
94
|
"""An object describing metadata about the request.
|
pydantic_ai/models/bedrock.py
CHANGED
|
@@ -112,6 +112,13 @@ P = ParamSpec('P')
|
|
|
112
112
|
T = typing.TypeVar('T')
|
|
113
113
|
|
|
114
114
|
|
|
115
|
+
class BedrockModelSettings(ModelSettings):
|
|
116
|
+
"""Settings for Bedrock models.
|
|
117
|
+
|
|
118
|
+
ALL FIELDS MUST BE `bedrock_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
|
|
115
122
|
@dataclass(init=False)
|
|
116
123
|
class BedrockConverseModel(Model):
|
|
117
124
|
"""A model that uses the Bedrock Converse API."""
|
pydantic_ai/models/cohere.py
CHANGED
|
@@ -80,7 +80,10 @@ See [Cohere's docs](https://docs.cohere.com/v2/docs/models) for a list of all av
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
class CohereModelSettings(ModelSettings):
|
|
83
|
-
"""Settings used for a Cohere model request.
|
|
83
|
+
"""Settings used for a Cohere model request.
|
|
84
|
+
|
|
85
|
+
ALL FIELDS MUST BE `cohere_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
|
|
86
|
+
"""
|
|
84
87
|
|
|
85
88
|
# This class is a placeholder for any future cohere-specific settings
|
|
86
89
|
|
pydantic_ai/models/gemini.py
CHANGED
|
@@ -70,7 +70,10 @@ See [the Gemini API docs](https://ai.google.dev/gemini-api/docs/models/gemini#mo
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
class GeminiModelSettings(ModelSettings):
|
|
73
|
-
"""Settings used for a Gemini model request.
|
|
73
|
+
"""Settings used for a Gemini model request.
|
|
74
|
+
|
|
75
|
+
ALL FIELDS MUST BE `gemini_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
|
|
76
|
+
"""
|
|
74
77
|
|
|
75
78
|
gemini_safety_settings: list[GeminiSafetySettings]
|
|
76
79
|
|
pydantic_ai/models/groq.py
CHANGED
|
@@ -43,34 +43,51 @@ except ImportError as _import_error:
|
|
|
43
43
|
'you can use the `groq` optional group — `pip install "pydantic-ai-slim[groq]"`'
|
|
44
44
|
) from _import_error
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
ProductionGroqModelNames = Literal[
|
|
47
|
+
'distil-whisper-large-v3-en',
|
|
48
|
+
'gemma2-9b-it',
|
|
48
49
|
'llama-3.3-70b-versatile',
|
|
49
|
-
'llama-3.3-70b-specdec',
|
|
50
50
|
'llama-3.1-8b-instant',
|
|
51
|
+
'llama-guard-3-8b',
|
|
52
|
+
'llama3-70b-8192',
|
|
53
|
+
'llama3-8b-8192',
|
|
54
|
+
'whisper-large-v3',
|
|
55
|
+
'whisper-large-v3-turbo',
|
|
56
|
+
]
|
|
57
|
+
"""Production Groq models from <https://console.groq.com/docs/models#production-models>."""
|
|
58
|
+
|
|
59
|
+
PreviewGroqModelNames = Literal[
|
|
60
|
+
'playai-tts',
|
|
61
|
+
'playai-tts-arabic',
|
|
62
|
+
'qwen-qwq-32b',
|
|
63
|
+
'mistral-saba-24b',
|
|
64
|
+
'qwen-2.5-coder-32b',
|
|
65
|
+
'qwen-2.5-32b',
|
|
66
|
+
'deepseek-r1-distill-qwen-32b',
|
|
67
|
+
'deepseek-r1-distill-llama-70b',
|
|
68
|
+
'llama-3.3-70b-specdec',
|
|
51
69
|
'llama-3.2-1b-preview',
|
|
52
70
|
'llama-3.2-3b-preview',
|
|
53
71
|
'llama-3.2-11b-vision-preview',
|
|
54
72
|
'llama-3.2-90b-vision-preview',
|
|
55
|
-
'llama3-70b-8192',
|
|
56
|
-
'llama3-8b-8192',
|
|
57
|
-
'mixtral-8x7b-32768',
|
|
58
|
-
'gemma2-9b-it',
|
|
59
73
|
]
|
|
60
|
-
"""
|
|
74
|
+
"""Preview Groq models from <https://console.groq.com/docs/models#preview-models>."""
|
|
61
75
|
|
|
62
|
-
GroqModelName = Union[str,
|
|
63
|
-
"""
|
|
64
|
-
Possible Groq model names.
|
|
76
|
+
GroqModelName = Union[str, ProductionGroqModelNames, PreviewGroqModelNames]
|
|
77
|
+
"""Possible Groq model names.
|
|
65
78
|
|
|
66
|
-
Since Groq supports a variety of
|
|
67
|
-
allow any name in the type hints.
|
|
68
|
-
|
|
79
|
+
Since Groq supports a variety of models and the list changes frequencly, we explicitly list the named models as of 2025-03-31
|
|
80
|
+
but allow any name in the type hints.
|
|
81
|
+
|
|
82
|
+
See <https://console.groq.com/docs/models> for an up to date date list of models and more details.
|
|
69
83
|
"""
|
|
70
84
|
|
|
71
85
|
|
|
72
86
|
class GroqModelSettings(ModelSettings):
|
|
73
|
-
"""Settings used for a Groq model request.
|
|
87
|
+
"""Settings used for a Groq model request.
|
|
88
|
+
|
|
89
|
+
ALL FIELDS MUST BE `groq_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
|
|
90
|
+
"""
|
|
74
91
|
|
|
75
92
|
# This class is a placeholder for any future groq-specific settings
|
|
76
93
|
|
|
@@ -7,7 +7,12 @@ from dataclasses import dataclass, field
|
|
|
7
7
|
from typing import Any, Callable, Literal
|
|
8
8
|
from urllib.parse import urlparse
|
|
9
9
|
|
|
10
|
-
from opentelemetry._events import
|
|
10
|
+
from opentelemetry._events import (
|
|
11
|
+
Event, # pyright: ignore[reportPrivateImportUsage]
|
|
12
|
+
EventLogger, # pyright: ignore[reportPrivateImportUsage]
|
|
13
|
+
EventLoggerProvider, # pyright: ignore[reportPrivateImportUsage]
|
|
14
|
+
get_event_logger_provider, # pyright: ignore[reportPrivateImportUsage]
|
|
15
|
+
)
|
|
11
16
|
from opentelemetry.trace import Span, Tracer, TracerProvider, get_tracer_provider
|
|
12
17
|
from opentelemetry.util.types import AttributeValue
|
|
13
18
|
from pydantic import TypeAdapter
|