pydantic-ai-slim 0.0.21__py3-none-any.whl → 0.0.23__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,35 @@ 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
169
163
 
170
164
 
171
165
  # pyright: reportUnknownMemberType=false
pydantic_ai/settings.py CHANGED
@@ -80,6 +80,7 @@ class ModelSettings(TypedDict, total=False):
80
80
  """Whether to allow parallel tool calls.
81
81
 
82
82
  Supported by:
83
+
83
84
  * OpenAI (some models, not o1)
84
85
  * Groq
85
86
  * Anthropic
@@ -89,6 +90,7 @@ class ModelSettings(TypedDict, total=False):
89
90
  """The random seed to use for the model, theoretically allowing for deterministic results.
90
91
 
91
92
  Supported by:
93
+
92
94
  * OpenAI
93
95
  * Groq
94
96
  * Cohere
@@ -99,6 +101,7 @@ class ModelSettings(TypedDict, total=False):
99
101
  """Penalize new tokens based on whether they have appeared in the text so far.
100
102
 
101
103
  Supported by:
104
+
102
105
  * OpenAI
103
106
  * Groq
104
107
  * Cohere
@@ -110,6 +113,7 @@ class ModelSettings(TypedDict, total=False):
110
113
  """Penalize new tokens based on their existing frequency in the text so far.
111
114
 
112
115
  Supported by:
116
+
113
117
  * OpenAI
114
118
  * Groq
115
119
  * Cohere
@@ -121,6 +125,7 @@ class ModelSettings(TypedDict, total=False):
121
125
  """Modify the likelihood of specified tokens appearing in the completion.
122
126
 
123
127
  Supported by:
128
+
124
129
  * OpenAI
125
130
  * Groq
126
131
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-slim
3
- Version: 0.0.21
3
+ Version: 0.0.23
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,13 +28,12 @@ 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.23
31
32
  Requires-Dist: pydantic>=2.10
32
33
  Provides-Extra: anthropic
33
34
  Requires-Dist: anthropic>=0.40.0; extra == 'anthropic'
34
35
  Provides-Extra: cohere
35
36
  Requires-Dist: cohere>=5.13.11; extra == 'cohere'
36
- Provides-Extra: graph
37
- Requires-Dist: pydantic-graph==0.0.21; extra == 'graph'
38
37
  Provides-Extra: groq
39
38
  Requires-Dist: groq>=0.12.0; extra == 'groq'
40
39
  Provides-Extra: logfire
@@ -42,7 +41,7 @@ Requires-Dist: logfire>=2.3; extra == 'logfire'
42
41
  Provides-Extra: mistral
43
42
  Requires-Dist: mistralai>=1.2.5; extra == 'mistral'
44
43
  Provides-Extra: openai
45
- Requires-Dist: openai>=1.59.0; extra == 'openai'
44
+ Requires-Dist: openai>=1.61.0; extra == 'openai'
46
45
  Provides-Extra: vertexai
47
46
  Requires-Dist: google-auth>=2.36.0; extra == 'vertexai'
48
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=1jTnra4feBI0cMq-uR9NPVMkoQv9KRd7AVZsy8R1OAs,44918
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=m5iGkMQQOmzV1j4wzuskIxXP3kbSM002A29kPEDusKI,13001
19
+ pydantic_ai/models/anthropic.py,sha256=nt7vuoQw_O5rBmEkncTPAd_RQ23j40I2pIoXWChIrJ4,17260
20
+ pydantic_ai/models/cohere.py,sha256=Nn7KbhSzWGR1a5ot2PtCEd0fZajhv5eL9qvTHJwUnps,10772
21
+ pydantic_ai/models/function.py,sha256=JuqULRz0TmhEqmPrbLeN6iqFrpP_k85B6rTgeeE7Tcg,9887
22
+ pydantic_ai/models/gemini.py,sha256=wXMtgjK9yepoBNb5LpFfD4eVyDejYlP9slrRFPXz98g,30181
23
+ pydantic_ai/models/groq.py,sha256=Or2CDLWDn-DCxeOdKZAXSbQLe7l_uLdPQZE7Iwo_QL4,14138
24
+ pydantic_ai/models/mistral.py,sha256=2lsTIoC3FhrYSyKS88yXQ4mZNu8LAqRQzKITp0EvzmY,25385
25
+ pydantic_ai/models/openai.py,sha256=1px0ykE-4xCHSaQJkfiudQkFTw0PHtjmlpidevDTTok,16682
26
+ pydantic_ai/models/test.py,sha256=eoenx_2RfcVCsao6RMDCGk0AtNBq7GIoSXi02Wep-k8,16428
27
+ pydantic_ai/models/vertexai.py,sha256=4SuVviOFgxcnOe6CjA_z8X0Hzozs6fcMUo5PvafYc68,9279
28
+ pydantic_ai_slim-0.0.23.dist-info/METADATA,sha256=XWCt3p_Ib1xE-2UABp0RVREc_e_WXXC0tdfjWiCrKbg,2839
29
+ pydantic_ai_slim-0.0.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ pydantic_ai_slim-0.0.23.dist-info/RECORD,,
@@ -1,29 +0,0 @@
1
- pydantic_ai/__init__.py,sha256=FbYetEgT6OO25u2KF5ZnFxKpz5DtnSpfckRXP4mjl8E,489
2
- pydantic_ai/_griffe.py,sha256=RYRKiLbgG97QxnazbAwlnc74XxevGHLQet-FGfq9qls,3960
3
- pydantic_ai/_parts_manager.py,sha256=ARfDQY1_5AIY5rNl_M2fAYHEFCe03ZxdhgjHf9qeIKw,11872
4
- pydantic_ai/_pydantic.py,sha256=dROz3Hmfdi0C2exq88FhefDRVo_8S3rtkXnoUHzsz0c,8753
5
- pydantic_ai/_result.py,sha256=tN1pVulf_EM4bkBvpNUWPnUXezLY-sBrJEVCFdy2nLU,10264
6
- pydantic_ai/_system_prompt.py,sha256=602c2jyle2R_SesOrITBDETZqsLk4BZ8Cbo8yEhmx04,1120
7
- pydantic_ai/_utils.py,sha256=zfuY3NiPPsSM5J1q2JElfbfIa8S1ONGOlC7M-iyBVso,9430
8
- pydantic_ai/agent.py,sha256=7o7yfatFPBDkrpSi2t0A4xivX7lzlNbOhtIMEJQpLKc,63620
9
- pydantic_ai/exceptions.py,sha256=eGDKX6bGhgVxXBzu81Sk3iiAkXr0GUtgT7bD5Rxlqpg,2028
10
- pydantic_ai/format_as_xml.py,sha256=QE7eMlg5-YUMw1_2kcI3h0uKYPZZyGkgXFDtfZTMeeI,4480
11
- pydantic_ai/messages.py,sha256=kzXn4ZjlX9Sy2KXgFHWYbbwPk7TzTPdztzOJLWEONwU,17101
12
- pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- pydantic_ai/result.py,sha256=0beXiUfiSb2kVc68iqLeg2qFQW6-mnTC8TFtiQayPDQ,18394
14
- pydantic_ai/settings.py,sha256=QSqs4_l_Gs2v4oixYNwKQhPiec_m9pn6XEAeUMFxt24,3054
15
- pydantic_ai/tools.py,sha256=lhupwm815lPlFFS79B0P61AyhUYtepA62LbZOCJrPEY,13205
16
- pydantic_ai/usage.py,sha256=60d9f6M7YEYuKMbqDGDogX4KsA73fhDtWyDXYXoIPaI,4948
17
- pydantic_ai/models/__init__.py,sha256=XgZAhiSVVX0TbePHXSxVnDIbG38jQG9g3WRMlA_EHDY,13063
18
- pydantic_ai/models/anthropic.py,sha256=v2m6zjaezLjtkHO2Rx67rmoN1iOqDeAp9fswJcqRMBA,16967
19
- pydantic_ai/models/cohere.py,sha256=wyjtD2uwkYYbsXLKwr-flmXSng_Atd-0jqtVDxDie14,10611
20
- pydantic_ai/models/function.py,sha256=jv2aw5K4KrMIRPFSTiGbBHcv16UZtGEe_1irjTudLg0,9826
21
- pydantic_ai/models/gemini.py,sha256=espBJbEMZjdzT5fC_rKOHoo_5o5xH-Y1Ea-RZR4JaPs,28222
22
- pydantic_ai/models/groq.py,sha256=W-uosi9PtvgXp8yoF6w8QZxPtrVjX1fmRQDjQQ10meE,13603
23
- pydantic_ai/models/mistral.py,sha256=RuRlxTBPGXIpcwTdjX2596uN2tgHBvCDQCWieWa1A_Q,24793
24
- pydantic_ai/models/openai.py,sha256=6ymsBzyu9WJVewbn3345jt_JoXpUpCLYOQERYJJlyRY,15228
25
- pydantic_ai/models/test.py,sha256=D_wBpRtrPcikopd5LBYjdAp3q-1gvuB9WnuopBQiRME,16659
26
- pydantic_ai/models/vertexai.py,sha256=bQZ5W8n4521AH3jTiyP1fOYxtNgCgkhjCbBeASv5Ap8,9388
27
- pydantic_ai_slim-0.0.21.dist-info/METADATA,sha256=EeGz0ZJG_g_o7xKu-2XiXN2zZsBhGZLwL39QaQGZQdc,2879
28
- pydantic_ai_slim-0.0.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- pydantic_ai_slim-0.0.21.dist-info/RECORD,,