Skip to content

Commit 6cec96f

Browse files
committed
Fix type checking and formatting issues
- Add type ignores for incomplete OpenAI SDK types on FileSearchToolCall - Use dict construction with cast for ResponseFileSearchToolCallParam (matches ImageGenerationTool pattern) - Fix ruff formatting for test parametrize decorator
1 parent 4376b96 commit 6cec96f

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

pydantic_ai_slim/pydantic_ai/models/openai.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,11 +1485,15 @@ async def _map_messages( # noqa: C901
14851485
and item.tool_call_id
14861486
and (args := item.args_as_dict())
14871487
):
1488-
file_search_item = responses.ResponseFileSearchToolCallParam(
1489-
id=item.tool_call_id,
1490-
action=cast(responses.response_file_search_tool_call_param.Action, args),
1491-
status='completed',
1492-
type='file_search_call',
1488+
# The cast is necessary because of incomplete OpenAI SDK types for FileSearchToolCall
1489+
file_search_item = cast(
1490+
responses.ResponseFileSearchToolCallParam,
1491+
{
1492+
'id': item.tool_call_id,
1493+
'action': args,
1494+
'status': 'completed',
1495+
'type': 'file_search_call',
1496+
},
14931497
)
14941498
openai_messages.append(file_search_item)
14951499
elif item.tool_name == ImageGenerationTool.kind and item.tool_call_id:
@@ -2268,14 +2272,15 @@ def _map_file_search_tool_call(
22682272
'status': item.status,
22692273
}
22702274

2271-
if action := item.action:
2272-
args = action.model_dump(mode='json')
2275+
# The OpenAI SDK has incomplete types for FileSearchToolCall.action
2276+
if action := item.action: # type: ignore[reportAttributeAccessIssue]
2277+
args = action.model_dump(mode='json') # type: ignore[reportUnknownMemberType]
22732278

22742279
return (
22752280
BuiltinToolCallPart(
22762281
tool_name=FileSearchTool.kind,
22772282
tool_call_id=item.id,
2278-
args=args,
2283+
args=args, # type: ignore[reportUnknownArgumentType]
22792284
provider_name=provider_name,
22802285
),
22812286
BuiltinToolReturnPart(

tests/test_builtin_tools.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ async def test_builtin_tools_not_supported_file_search(model: Model, allow_model
5252
await agent.run('Search my files')
5353

5454

55-
@pytest.mark.parametrize(
56-
'model', ('bedrock', 'mistral', 'huggingface', 'groq', 'anthropic', 'outlines'), indirect=True
57-
)
55+
@pytest.mark.parametrize('model', ('bedrock', 'mistral', 'huggingface', 'groq', 'anthropic', 'outlines'), indirect=True)
5856
async def test_builtin_tools_not_supported_file_search_stream(model: Model, allow_model_requests: None):
5957
agent = Agent(model=model, builtin_tools=[FileSearchTool(vector_store_ids=['test-id'])])
6058

0 commit comments

Comments
 (0)