Skip to content

Commit 788938d

Browse files
authored
Don't send strict to HuggingFace API as it's not supported by their types and at least some models (#3062)
1 parent df333bd commit 788938d

File tree

2 files changed

+0
-47
lines changed

2 files changed

+0
-47
lines changed

pydantic_ai_slim/pydantic_ai/models/huggingface.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ def _map_tool_definition(f: ToolDefinition) -> ChatCompletionInputTool:
377377
},
378378
}
379379
)
380-
if f.strict is not None:
381-
tool_param['function']['strict'] = f.strict
382380
return tool_param
383381

384382
async def _map_user_message(

tests/models/test_huggingface.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -893,51 +893,6 @@ async def test_thinking_part_in_history(allow_model_requests: None):
893893
)
894894

895895

896-
@pytest.mark.parametrize('strict', [True, False, None])
897-
async def test_tool_strict_mode(allow_model_requests: None, strict: bool | None):
898-
tool_call = ChatCompletionOutputToolCall.parse_obj_as_instance( # type:ignore
899-
{
900-
'function': ChatCompletionOutputFunctionDefinition.parse_obj_as_instance( # type:ignore
901-
{
902-
'name': 'my_tool',
903-
'arguments': '{"x": 42}',
904-
}
905-
),
906-
'id': '1',
907-
'type': 'function',
908-
}
909-
)
910-
responses = [
911-
completion_message(
912-
ChatCompletionOutputMessage.parse_obj_as_instance( # type:ignore
913-
{
914-
'content': None,
915-
'role': 'assistant',
916-
'tool_calls': [tool_call],
917-
}
918-
)
919-
),
920-
completion_message(ChatCompletionOutputMessage(content='final response', role='assistant')), # type: ignore
921-
]
922-
mock_client = MockHuggingFace.create_mock(responses)
923-
model = HuggingFaceModel('hf-model', provider=HuggingFaceProvider(hf_client=mock_client, api_key='x'))
924-
agent = Agent(model)
925-
926-
@agent.tool_plain(strict=strict)
927-
def my_tool(x: int) -> int:
928-
return x
929-
930-
result = await agent.run('hello')
931-
assert result.output == 'final response'
932-
933-
kwargs = get_mock_chat_completion_kwargs(mock_client)[0]
934-
tools = kwargs['tools']
935-
if strict is not None:
936-
assert tools[0]['function']['strict'] is strict
937-
else:
938-
assert 'strict' not in tools[0]['function']
939-
940-
941896
@pytest.mark.parametrize(
942897
'content_item, error_message',
943898
[

0 commit comments

Comments
 (0)