Skip to content

Commit 9b4de86

Browse files
authored
Bump dependencies (#966)
1 parent dc0fc49 commit 9b4de86

File tree

11 files changed

+1075
-1101
lines changed

11 files changed

+1075
-1101
lines changed

examples/pydantic_ai_examples/flight_booking.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ class Failed(BaseModel):
105105

106106

107107
# This agent is responsible for extracting the user's seat selection
108-
seat_preference_agent = Agent[
109-
None, SeatPreference | Failed
110-
](
108+
seat_preference_agent = Agent[None, SeatPreference | Failed](
111109
'openai:gpt-4o',
112110
result_type=SeatPreference | Failed, # type: ignore
113111
system_prompt=(

examples/pydantic_ai_examples/rag.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ async def retrieve(context: RunContext[Deps], search_query: str) -> str:
6767
model='text-embedding-3-small',
6868
)
6969

70-
assert (
71-
len(embedding.data) == 1
72-
), f'Expected 1 embedding, got {len(embedding.data)}, doc query: {search_query!r}'
70+
assert len(embedding.data) == 1, (
71+
f'Expected 1 embedding, got {len(embedding.data)}, doc query: {search_query!r}'
72+
)
7373
embedding = embedding.data[0].embedding
7474
embedding_json = pydantic_core.to_json(embedding).decode()
7575
rows = await context.deps.pool.fetch(
@@ -149,9 +149,9 @@ async def insert_doc_section(
149149
input=section.embedding_content(),
150150
model='text-embedding-3-small',
151151
)
152-
assert (
153-
len(embedding.data) == 1
154-
), f'Expected 1 embedding, got {len(embedding.data)}, doc section: {section}'
152+
assert len(embedding.data) == 1, (
153+
f'Expected 1 embedding, got {len(embedding.data)}, doc section: {section}'
154+
)
155155
embedding = embedding.data[0].embedding
156156
embedding_json = pydantic_core.to_json(embedding).decode()
157157
await pool.execute(

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ def infer_model(model: Model | KnownModelName) -> Model:
364364
raise UserError(f'Unknown model: {model}')
365365

366366

367-
@cache
368367
def cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
369368
"""Cached HTTPX async client so multiple agents and calls can share the same client.
370369
@@ -375,6 +374,16 @@ def cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.Asyn
375374
The default timeouts match those of OpenAI,
376375
see <https://github.com/openai/openai-python/blob/v1.54.4/src/openai/_constants.py#L9>.
377376
"""
377+
client = _cached_async_http_client(timeout=timeout, connect=connect)
378+
if client.is_closed:
379+
# This happens if the context manager is used, so we need to create a new client.
380+
_cached_async_http_client.cache_clear()
381+
client = _cached_async_http_client(timeout=timeout, connect=connect)
382+
return client
383+
384+
385+
@cache
386+
def _cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
378387
return httpx.AsyncClient(
379388
timeout=httpx.Timeout(timeout=timeout, connect=connect),
380389
headers={'User-Agent': get_user_agent()},

pydantic_ai_slim/pydantic_ai/models/cohere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(
124124
assert api_key is None, 'Cannot provide both `cohere_client` and `api_key`'
125125
self.client = cohere_client
126126
else:
127-
self.client = AsyncClientV2(api_key=api_key, httpx_client=http_client) # type: ignore
127+
self.client = AsyncClientV2(api_key=api_key, httpx_client=http_client)
128128

129129
async def request(
130130
self,

pydantic_ai_slim/pydantic_ai/models/function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ async def request_stream(
109109
model_settings,
110110
)
111111

112-
assert (
113-
self.stream_function is not None
114-
), 'FunctionModel must receive a `stream_function` to support streamed requests'
112+
assert self.stream_function is not None, (
113+
'FunctionModel must receive a `stream_function` to support streamed requests'
114+
)
115115

116116
response_stream = PeekableAsyncStream(self.stream_function(messages, agent_info))
117117

pydantic_ai_slim/pydantic_ai/models/test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ def _get_tool_calls(self, model_request_parameters: ModelRequestParameters) -> l
130130

131131
def _get_result(self, model_request_parameters: ModelRequestParameters) -> _TextResult | _FunctionToolResult:
132132
if self.custom_result_text is not None:
133-
assert (
134-
model_request_parameters.allow_text_result
135-
), 'Plain response not allowed, but `custom_result_text` is set.'
133+
assert model_request_parameters.allow_text_result, (
134+
'Plain response not allowed, but `custom_result_text` is set.'
135+
)
136136
assert self.custom_result_args is None, 'Cannot set both `custom_result_text` and `custom_result_args`.'
137137
return _TextResult(self.custom_result_text)
138138
elif self.custom_result_args is not None:
139-
assert (
140-
model_request_parameters.result_tools is not None
141-
), 'No result tools provided, but `custom_result_args` is set.'
139+
assert model_request_parameters.result_tools is not None, (
140+
'No result tools provided, but `custom_result_args` is set.'
141+
)
142142
result_tool = model_request_parameters.result_tools[0]
143143

144144
if k := result_tool.outer_typed_dict_key:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ members = ["pydantic_ai_slim", "pydantic_graph", "examples"]
5757
# dev dependencies are defined in `pydantic-ai-slim/pyproject.toml` to allow for minimal testing
5858
lint = [
5959
"mypy>=1.11.2",
60-
"pyright>=1.1.388",
60+
"pyright>=1.1.388,<1.1.390",
6161
"ruff>=0.6.9",
6262
]
6363
docs = [

tests/models/test_gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class FormattedStringFields(BaseModel):
365365
_GeminiTools(
366366
function_declarations=[
367367
_GeminiFunction(
368-
description='This is the tool for the final ' 'Result',
368+
description='This is the tool for the final Result',
369369
name='result',
370370
parameters={
371371
'properties': {

tests/test_agent.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,14 @@ def test_run_sync_multiple():
848848

849849
@agent.tool_plain
850850
async def make_request() -> str:
851-
# raised a `RuntimeError: Event loop is closed` on repeat runs when we used `asyncio.run()`
852-
client = cached_async_http_client()
853-
# use this as I suspect it's about the fastest globally available endpoint
854-
try:
855-
response = await client.get('https://cloudflare.com/cdn-cgi/trace')
856-
except httpx.ConnectError:
857-
pytest.skip('offline')
858-
else:
859-
return str(response.status_code)
851+
async with cached_async_http_client() as client:
852+
# use this as I suspect it's about the fastest globally available endpoint
853+
try:
854+
response = await client.get('https://cloudflare.com/cdn-cgi/trace')
855+
except httpx.ConnectError: # pragma: no cover
856+
pytest.skip('offline')
857+
else:
858+
return str(response.status_code)
860859

861860
for _ in range(2):
862861
result = agent.run_sync('Hello')

tests/test_streaming.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def another_tool(y: int) -> int: # pragma: no cover
590590
ModelRequest(
591591
parts=[
592592
UserPromptPart(
593-
content='test early strategy with final ' 'result in middle',
593+
content='test early strategy with final result in middle',
594594
timestamp=IsNow(tz=datetime.timezone.utc),
595595
part_kind='user-prompt',
596596
)
@@ -632,7 +632,7 @@ def another_tool(y: int) -> int: # pragma: no cover
632632
parts=[
633633
ToolReturnPart(
634634
tool_name='regular_tool',
635-
content='Tool not executed - a final ' 'result was already processed.',
635+
content='Tool not executed - a final result was already processed.',
636636
tool_call_id=None,
637637
timestamp=IsNow(tz=datetime.timezone.utc),
638638
part_kind='tool-return',
@@ -646,7 +646,7 @@ def another_tool(y: int) -> int: # pragma: no cover
646646
),
647647
ToolReturnPart(
648648
tool_name='another_tool',
649-
content='Tool not executed - a final ' 'result was already processed.',
649+
content='Tool not executed - a final result was already processed.',
650650
tool_call_id=None,
651651
timestamp=IsNow(tz=datetime.timezone.utc),
652652
part_kind='tool-return',

0 commit comments

Comments
 (0)