pydantic-ai-slim 0.0.22__py3-none-any.whl → 0.0.24__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.

@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations as _annotations
2
2
 
3
+ from collections.abc import AsyncIterator
4
+ from contextlib import asynccontextmanager
3
5
  from dataclasses import dataclass, field
4
6
  from datetime import datetime, timedelta
5
7
  from pathlib import Path
@@ -7,11 +9,13 @@ from typing import Literal
7
9
 
8
10
  from httpx import AsyncClient as AsyncHTTPClient
9
11
 
12
+ from .. import usage
10
13
  from .._utils import run_in_executor
11
14
  from ..exceptions import UserError
12
- from ..tools import ToolDefinition
13
- from . import Model, cached_async_http_client, check_allow_model_requests
14
- from .gemini import GeminiAgentModel, GeminiModelName
15
+ from ..messages import ModelMessage, ModelResponse
16
+ from ..settings import ModelSettings
17
+ from . import ModelRequestParameters, StreamedResponse, cached_async_http_client
18
+ from .gemini import GeminiModel, GeminiModelName
15
19
 
16
20
  try:
17
21
  import google.auth
@@ -52,19 +56,17 @@ The template is used thus:
52
56
 
53
57
 
54
58
  @dataclass(init=False)
55
- class VertexAIModel(Model):
59
+ class VertexAIModel(GeminiModel):
56
60
  """A model that uses Gemini via the `*-aiplatform.googleapis.com` VertexAI API."""
57
61
 
58
- model_name: GeminiModelName
59
62
  service_account_file: Path | str | None
60
63
  project_id: str | None
61
64
  region: VertexAiRegion
62
65
  model_publisher: Literal['google']
63
- http_client: AsyncHTTPClient
64
66
  url_template: str
65
67
 
66
- auth: BearerTokenAuth | None
67
- url: str | None
68
+ _model_name: GeminiModelName = field(repr=False)
69
+ _system: str | None = field(default='google-vertex', repr=False)
68
70
 
69
71
  # TODO __init__ can be removed once we drop 3.9 and we can set kw_only correctly on the dataclass
70
72
  def __init__(
@@ -96,7 +98,7 @@ class VertexAIModel(Model):
96
98
  [`VERTEX_AI_URL_TEMPLATE` docs][pydantic_ai.models.vertexai.VERTEX_AI_URL_TEMPLATE]
97
99
  for more information.
98
100
  """
99
- self.model_name = model_name
101
+ self._model_name = model_name
100
102
  self.service_account_file = service_account_file
101
103
  self.project_id = project_id
102
104
  self.region = region
@@ -104,35 +106,16 @@ class VertexAIModel(Model):
104
106
  self.http_client = http_client or cached_async_http_client()
105
107
  self.url_template = url_template
106
108
 
107
- self.auth = None
108
- self.url = None
109
+ self._auth = None
110
+ self._url = None
109
111
 
110
- async def agent_model(
111
- self,
112
- *,
113
- function_tools: list[ToolDefinition],
114
- allow_text_result: bool,
115
- result_tools: list[ToolDefinition],
116
- ) -> GeminiAgentModel:
117
- check_allow_model_requests()
118
- url, auth = await self.ainit()
119
- return GeminiAgentModel(
120
- http_client=self.http_client,
121
- model_name=self.model_name,
122
- auth=auth,
123
- url=url,
124
- function_tools=function_tools,
125
- allow_text_result=allow_text_result,
126
- result_tools=result_tools,
127
- )
128
-
129
- async def ainit(self) -> tuple[str, BearerTokenAuth]:
112
+ async def ainit(self) -> None:
130
113
  """Initialize the model, setting the URL and auth.
131
114
 
132
115
  This will raise an error if authentication fails.
133
116
  """
134
- if self.url is not None and self.auth is not None:
135
- return self.url, self.auth
117
+ if self._url is not None and self._auth is not None:
118
+ return
136
119
 
137
120
  if self.service_account_file is not None:
138
121
  creds: BaseCredentials | ServiceAccountCredentials = _creds_from_file(self.service_account_file)
@@ -148,24 +131,45 @@ class VertexAIModel(Model):
148
131
  raise UserError(f'No project_id provided and none found in {creds_source}')
149
132
  project_id = creds_project_id
150
133
  else:
151
- if creds_project_id is not None and self.project_id != creds_project_id:
152
- raise UserError(
153
- f'The project_id you provided does not match the one from {creds_source}: '
154
- f'{self.project_id!r} != {creds_project_id!r}'
155
- )
156
134
  project_id = self.project_id
157
135
 
158
- self.url = url = self.url_template.format(
136
+ self._url = self.url_template.format(
159
137
  region=self.region,
160
138
  project_id=project_id,
161
139
  model_publisher=self.model_publisher,
162
- model=self.model_name,
140
+ model=self._model_name,
163
141
  )
164
- self.auth = auth = BearerTokenAuth(creds)
165
- return url, auth
142
+ self._auth = BearerTokenAuth(creds)
166
143
 
167
- def name(self) -> str:
168
- return f'google-vertex:{self.model_name}'
144
+ async def request(
145
+ self,
146
+ messages: list[ModelMessage],
147
+ model_settings: ModelSettings | None,
148
+ model_request_parameters: ModelRequestParameters,
149
+ ) -> tuple[ModelResponse, usage.Usage]:
150
+ await self.ainit()
151
+ return await super().request(messages, model_settings, model_request_parameters)
152
+
153
+ @asynccontextmanager
154
+ async def request_stream(
155
+ self,
156
+ messages: list[ModelMessage],
157
+ model_settings: ModelSettings | None,
158
+ model_request_parameters: ModelRequestParameters,
159
+ ) -> AsyncIterator[StreamedResponse]:
160
+ await self.ainit()
161
+ async with super().request_stream(messages, model_settings, model_request_parameters) as value:
162
+ yield value
163
+
164
+ @property
165
+ def model_name(self) -> GeminiModelName:
166
+ """The model name."""
167
+ return self._model_name
168
+
169
+ @property
170
+ def system(self) -> str | None:
171
+ """The system / model provider."""
172
+ return self._system
169
173
 
170
174
 
171
175
  # pyright: reportUnknownMemberType=false
pydantic_ai/result.py CHANGED
@@ -286,7 +286,7 @@ class StreamedRunResult(_BaseRunResult[ResultDataT], Generic[AgentDepsT, ResultD
286
286
  await self._marked_completed(
287
287
  _messages.ModelResponse(
288
288
  parts=[_messages.TextPart(combined_validated_text)],
289
- model_name=self._stream_response.model_name(),
289
+ model_name=self._stream_response.model_name,
290
290
  )
291
291
  )
292
292
 
@@ -347,7 +347,7 @@ class StreamedRunResult(_BaseRunResult[ResultDataT], Generic[AgentDepsT, ResultD
347
347
 
348
348
  def timestamp(self) -> datetime:
349
349
  """Get the timestamp of the response."""
350
- return self._stream_response.timestamp()
350
+ return self._stream_response.timestamp
351
351
 
352
352
  async def validate_structured_result(
353
353
  self, message: _messages.ModelResponse, *, allow_partial: bool = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-slim
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: Agent Framework / shim to use Pydantic with LLMs, slim package
5
5
  Author-email: Samuel Colvin <samuel@pydantic.dev>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ Requires-Dist: eval-type-backport>=0.2.0
28
28
  Requires-Dist: griffe>=1.3.2
29
29
  Requires-Dist: httpx>=0.27
30
30
  Requires-Dist: logfire-api>=1.2.0
31
- Requires-Dist: pydantic-graph==0.0.22
31
+ Requires-Dist: pydantic-graph==0.0.24
32
32
  Requires-Dist: pydantic>=2.10
33
33
  Provides-Extra: anthropic
34
34
  Requires-Dist: anthropic>=0.40.0; extra == 'anthropic'
@@ -41,7 +41,7 @@ Requires-Dist: logfire>=2.3; extra == 'logfire'
41
41
  Provides-Extra: mistral
42
42
  Requires-Dist: mistralai>=1.2.5; extra == 'mistral'
43
43
  Provides-Extra: openai
44
- Requires-Dist: openai>=1.59.0; extra == 'openai'
44
+ Requires-Dist: openai>=1.61.0; extra == 'openai'
45
45
  Provides-Extra: vertexai
46
46
  Requires-Dist: google-auth>=2.36.0; extra == 'vertexai'
47
47
  Requires-Dist: requests>=2.32.3; extra == 'vertexai'
@@ -0,0 +1,30 @@
1
+ pydantic_ai/__init__.py,sha256=FbYetEgT6OO25u2KF5ZnFxKpz5DtnSpfckRXP4mjl8E,489
2
+ pydantic_ai/_agent_graph.py,sha256=_uCNK12sEXmzB-Vk1OaCR-AMARYzEoInjKXZyx7ODjA,33136
3
+ pydantic_ai/_griffe.py,sha256=RYRKiLbgG97QxnazbAwlnc74XxevGHLQet-FGfq9qls,3960
4
+ pydantic_ai/_parts_manager.py,sha256=ARfDQY1_5AIY5rNl_M2fAYHEFCe03ZxdhgjHf9qeIKw,11872
5
+ pydantic_ai/_pydantic.py,sha256=dROz3Hmfdi0C2exq88FhefDRVo_8S3rtkXnoUHzsz0c,8753
6
+ pydantic_ai/_result.py,sha256=tN1pVulf_EM4bkBvpNUWPnUXezLY-sBrJEVCFdy2nLU,10264
7
+ pydantic_ai/_system_prompt.py,sha256=602c2jyle2R_SesOrITBDETZqsLk4BZ8Cbo8yEhmx04,1120
8
+ pydantic_ai/_utils.py,sha256=zfuY3NiPPsSM5J1q2JElfbfIa8S1ONGOlC7M-iyBVso,9430
9
+ pydantic_ai/agent.py,sha256=q9nc_bTUuwxYVrzmUb5NkwOUWQm2XIsxpTuyyAuVdpU,44900
10
+ pydantic_ai/exceptions.py,sha256=eGDKX6bGhgVxXBzu81Sk3iiAkXr0GUtgT7bD5Rxlqpg,2028
11
+ pydantic_ai/format_as_xml.py,sha256=QE7eMlg5-YUMw1_2kcI3h0uKYPZZyGkgXFDtfZTMeeI,4480
12
+ pydantic_ai/messages.py,sha256=kzXn4ZjlX9Sy2KXgFHWYbbwPk7TzTPdztzOJLWEONwU,17101
13
+ pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ pydantic_ai/result.py,sha256=HYTkmb-6fzbxXRlsPOyVic_EexEGN4JLfZfVBKpJtfM,18390
15
+ pydantic_ai/settings.py,sha256=ntuWnke9UA18aByDxk9OIhN0tAgOaPdqCEkRf-wlp8Y,3059
16
+ pydantic_ai/tools.py,sha256=lhupwm815lPlFFS79B0P61AyhUYtepA62LbZOCJrPEY,13205
17
+ pydantic_ai/usage.py,sha256=60d9f6M7YEYuKMbqDGDogX4KsA73fhDtWyDXYXoIPaI,4948
18
+ pydantic_ai/models/__init__.py,sha256=WCvo5bI2dWJbKPhdGWID-HFGrZGo3jvtHhgwaDuY75s,13219
19
+ pydantic_ai/models/anthropic.py,sha256=lArkCv0oZQeG1SqyEHlqKUyrcEYzYrS5fkW_ICKlikU,17749
20
+ pydantic_ai/models/cohere.py,sha256=yLUA3bTQg-4NNjpvD2DXkUIMluia8vETChsjYYN13lg,11016
21
+ pydantic_ai/models/function.py,sha256=5AWAFo-AZ0UyX8wBAYc5nd6U6XpOFvnsYr8vVfatEXQ,10333
22
+ pydantic_ai/models/gemini.py,sha256=CGaHve4wQxkGEa1hArgldvOBk79blGdOqdeLxMH_NQM,30846
23
+ pydantic_ai/models/groq.py,sha256=M7P-9LrH1lm4wyIMiytsHf28bwkukOyVzw3S7F9sbic,14612
24
+ pydantic_ai/models/mistral.py,sha256=1DA1AX-V46p7dI75-4aRwQ8TrQxdh5ZQaoMYZO7VRkI,25868
25
+ pydantic_ai/models/openai.py,sha256=kUV13suTp1ueibH2uYWaRCX832GApImdxSiGqNyfWo4,17161
26
+ pydantic_ai/models/test.py,sha256=6X0r78biqnvakiH1nFKYQFNOs4dWrS-yqe0RFBrKW0s,16873
27
+ pydantic_ai/models/vertexai.py,sha256=9Kp_1KMBlbP8_HRJTuFnrkkFmlJ7yFhADQYjxOgIh9Y,9523
28
+ pydantic_ai_slim-0.0.24.dist-info/METADATA,sha256=kSbEzpXrgMTSHX0ojDw-Mtf8QQFCFE5fIJTRZihLe1w,2839
29
+ pydantic_ai_slim-0.0.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ pydantic_ai_slim-0.0.24.dist-info/RECORD,,
@@ -1,30 +0,0 @@
1
- pydantic_ai/__init__.py,sha256=FbYetEgT6OO25u2KF5ZnFxKpz5DtnSpfckRXP4mjl8E,489
2
- pydantic_ai/_agent_graph.py,sha256=IdznyPzgrLmfiw3733GA3gYWOA_6LYIEuXBKTBXOi0A,32942
3
- pydantic_ai/_griffe.py,sha256=RYRKiLbgG97QxnazbAwlnc74XxevGHLQet-FGfq9qls,3960
4
- pydantic_ai/_parts_manager.py,sha256=ARfDQY1_5AIY5rNl_M2fAYHEFCe03ZxdhgjHf9qeIKw,11872
5
- pydantic_ai/_pydantic.py,sha256=dROz3Hmfdi0C2exq88FhefDRVo_8S3rtkXnoUHzsz0c,8753
6
- pydantic_ai/_result.py,sha256=tN1pVulf_EM4bkBvpNUWPnUXezLY-sBrJEVCFdy2nLU,10264
7
- pydantic_ai/_system_prompt.py,sha256=602c2jyle2R_SesOrITBDETZqsLk4BZ8Cbo8yEhmx04,1120
8
- pydantic_ai/_utils.py,sha256=zfuY3NiPPsSM5J1q2JElfbfIa8S1ONGOlC7M-iyBVso,9430
9
- pydantic_ai/agent.py,sha256=RDKBnHU1yFBMwW9e7_BUYs4aRfbwJ69bpWp_ha2y9M0,44880
10
- pydantic_ai/exceptions.py,sha256=eGDKX6bGhgVxXBzu81Sk3iiAkXr0GUtgT7bD5Rxlqpg,2028
11
- pydantic_ai/format_as_xml.py,sha256=QE7eMlg5-YUMw1_2kcI3h0uKYPZZyGkgXFDtfZTMeeI,4480
12
- pydantic_ai/messages.py,sha256=kzXn4ZjlX9Sy2KXgFHWYbbwPk7TzTPdztzOJLWEONwU,17101
13
- pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- pydantic_ai/result.py,sha256=0beXiUfiSb2kVc68iqLeg2qFQW6-mnTC8TFtiQayPDQ,18394
15
- pydantic_ai/settings.py,sha256=ntuWnke9UA18aByDxk9OIhN0tAgOaPdqCEkRf-wlp8Y,3059
16
- pydantic_ai/tools.py,sha256=lhupwm815lPlFFS79B0P61AyhUYtepA62LbZOCJrPEY,13205
17
- pydantic_ai/usage.py,sha256=60d9f6M7YEYuKMbqDGDogX4KsA73fhDtWyDXYXoIPaI,4948
18
- pydantic_ai/models/__init__.py,sha256=kVWd_WEK2dThHoG0Yha4t93w4Zaqkjcu9sKJ7nNqX_U,13245
19
- pydantic_ai/models/anthropic.py,sha256=v2m6zjaezLjtkHO2Rx67rmoN1iOqDeAp9fswJcqRMBA,16967
20
- pydantic_ai/models/cohere.py,sha256=wyjtD2uwkYYbsXLKwr-flmXSng_Atd-0jqtVDxDie14,10611
21
- pydantic_ai/models/function.py,sha256=jv2aw5K4KrMIRPFSTiGbBHcv16UZtGEe_1irjTudLg0,9826
22
- pydantic_ai/models/gemini.py,sha256=OsvtVqmKK4XmnLjPTRFwtCeXEuBOWfPrVZVZq0mSA30,28305
23
- pydantic_ai/models/groq.py,sha256=W-uosi9PtvgXp8yoF6w8QZxPtrVjX1fmRQDjQQ10meE,13603
24
- pydantic_ai/models/mistral.py,sha256=RuRlxTBPGXIpcwTdjX2596uN2tgHBvCDQCWieWa1A_Q,24793
25
- pydantic_ai/models/openai.py,sha256=ZwhYcpPIehDzmOBY_U1BKQhxYPtvKUeQjs9jDNr23bU,15547
26
- pydantic_ai/models/test.py,sha256=D_wBpRtrPcikopd5LBYjdAp3q-1gvuB9WnuopBQiRME,16659
27
- pydantic_ai/models/vertexai.py,sha256=bQZ5W8n4521AH3jTiyP1fOYxtNgCgkhjCbBeASv5Ap8,9388
28
- pydantic_ai_slim-0.0.22.dist-info/METADATA,sha256=lhhSBLTlHXj025p-n0u_X3EGOZnoSUTjAkXk59_WEV8,2839
29
- pydantic_ai_slim-0.0.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
- pydantic_ai_slim-0.0.22.dist-info/RECORD,,