Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pydantic_ai_slim/pydantic_ai/models/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .. import ModelHTTPError, UnexpectedModelBehavior, _utils, usage
from .._run_context import RunContext
from .._utils import guard_tool_call_id as _guard_tool_call_id
from ..exceptions import UserError
from ..messages import (
BinaryContent,
BuiltinToolCallPart,
Expand Down Expand Up @@ -367,6 +368,10 @@ def _get_builtin_tools(self, model_request_parameters: ModelRequestParameters) -
)
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
tools.append(BetaCodeExecutionTool20250522Param(name='code_execution', type='code_execution_20250522'))
else: # pragma: no cover
raise UserError(
f'`{tool.__class__.__name__}` is not supported by `AnthropicModel`. If it should be, please file an issue.'
)
return tools

async def _map_message(self, messages: list[ModelMessage]) -> tuple[str, list[BetaMessageParam]]: # noqa: C901
Expand Down
4 changes: 4 additions & 0 deletions pydantic_ai_slim/pydantic_ai/models/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def _get_tools(self, model_request_parameters: ModelRequestParameters) -> list[T
tools.append(ToolDict(google_search=GoogleSearchDict()))
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
tools.append(ToolDict(code_execution=ToolCodeExecutionDict()))
else: # pragma: no cover
raise UserError(
f'`{tool.__class__.__name__}` is not supported by `GoogleModel`. If it should be, please file an issue.'
)
return tools or None

def _get_tool_config(
Expand Down
8 changes: 5 additions & 3 deletions pydantic_ai_slim/pydantic_ai/models/groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .._run_context import RunContext
from .._thinking_part import split_content_into_text_and_thinking
from .._utils import generate_tool_call_id, guard_tool_call_id as _guard_tool_call_id, number_to_datetime
from ..builtin_tools import CodeExecutionTool, WebSearchTool
from ..builtin_tools import WebSearchTool
from ..exceptions import UserError
from ..messages import (
BinaryContent,
Expand Down Expand Up @@ -318,8 +318,10 @@ def _get_builtin_tools(
if isinstance(tool, WebSearchTool):
if not GroqModelProfile.from_profile(self.profile).groq_always_has_web_search_builtin_tool:
raise UserError('`WebSearchTool` is not supported by Groq') # pragma: no cover
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
raise UserError('`CodeExecutionTool` is not supported by Groq')
else:
raise UserError(
f'`{tool.__class__.__name__}` is not supported by `GroqModel`. If it should be, please file an issue.'
)
return tools

def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCompletionMessageParam]:
Expand Down
25 changes: 13 additions & 12 deletions pydantic_ai_slim/pydantic_ai/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ def _get_web_search_options(self, model_request_parameters: ModelRequestParamete
),
)
return WebSearchOptions(search_context_size=tool.search_context_size)
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
raise UserError('`CodeExecutionTool` is not supported by OpenAI')
else:
raise UserError(
f'`{tool.__class__.__name__}` is not supported by `OpenAIModel`. If it should be, please file an issue.'
)

async def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCompletionMessageParam]:
"""Just maps a `pydantic_ai.Message` to a `openai.types.ChatCompletionMessageParam`."""
Expand Down Expand Up @@ -632,14 +634,6 @@ class OpenAIResponsesModel(Model):
The [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses) is the
new API for OpenAI models.

The Responses API has built-in tools, that you can use instead of building your own:

- [Web search](https://platform.openai.com/docs/guides/tools-web-search)
- [File search](https://platform.openai.com/docs/guides/tools-file-search)
- [Computer use](https://platform.openai.com/docs/guides/tools-computer-use)

Use the `openai_builtin_tools` setting to add these tools to your model.

If you are interested in the differences between the Responses API and the Chat Completions API,
see the [OpenAI API docs](https://platform.openai.com/docs/guides/responses-vs-chat-completions).
"""
Expand Down Expand Up @@ -780,8 +774,11 @@ async def _responses_create(
model_settings: OpenAIResponsesModelSettings,
model_request_parameters: ModelRequestParameters,
) -> responses.Response | AsyncStream[responses.ResponseStreamEvent]:
tools = self._get_tools(model_request_parameters)
tools = self._get_builtin_tools(model_request_parameters) + tools
tools = (
self._get_builtin_tools(model_request_parameters)
+ list(model_settings.get('openai_builtin_tools', []))
+ self._get_tools(model_request_parameters)
)

if not tools:
tool_choice: Literal['none', 'required', 'auto'] | None = None
Expand Down Expand Up @@ -880,6 +877,10 @@ def _get_builtin_tools(self, model_request_parameters: ModelRequestParameters) -
tools.append(web_search_tool)
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
tools.append({'type': 'code_interpreter', 'container': {'type': 'auto'}})
else:
raise UserError( # pragma: no cover
f'`{tool.__class__.__name__}` is not supported by `OpenAIResponsesModel`. If it should be, please file an issue.'
)
return tools

def _map_tool_definition(self, f: ToolDefinition) -> responses.FunctionToolParam:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
connection:
- keep-alive
content-length:
- '217'
- '199'
content-type:
- application/json
host:
Expand All @@ -18,7 +18,6 @@ interactions:
input:
- content: Give me the best news about LLMs from the last 24 hours. Be short.
role: user
instructions: ''
model: gpt-4o
stream: false
tool_choice: auto
Expand All @@ -32,67 +31,77 @@ interactions:
connection:
- keep-alive
content-length:
- '3210'
- '2994'
content-type:
- application/json
openai-organization:
- pydantic-28gund
openai-processing-ms:
- '2843'
- '8814'
openai-project:
- proj_dKobscVY9YJxeEaDJen54e3d
openai-version:
- '2020-10-01'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
created_at: 1743506361
background: false
created_at: 1755020432
error: null
id: resp_67ebcbb93728819197f923ff16e98bce04f5055a2a33abc3
id: resp_689b7c90010c8196ac0efd68b021490f07450cfc2d48b975
incomplete_details: null
instructions: ''
instructions: null
max_output_tokens: null
max_tool_calls: null
metadata: {}
model: gpt-4o-2024-08-06
object: response
output:
- id: ws_67ebcbb9ab4481918bebf63b66dbb67c04f5055a2a33abc3
- action:
query: latest news on LLMs October 2023
type: search
id: ws_689b7c90de788196b18c6d68e7894def07450cfc2d48b975
status: completed
type: web_search_call
- content:
- annotations:
- end_index: 571
start_index: 404
title: OpenAI plans to release open-weight language model in coming months
- end_index: 364
start_index: 273
title: OpenAI's big GPT-5 launch gets bumpy
type: url_citation
url: https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai
- end_index: 846
start_index: 625
title: OpenAI plans to release open-weight language model in coming months
url: https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai
- end_index: 533
start_index: 417
title: OpenAI's big GPT-5 launch gets bumpy
type: url_citation
url: https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai
text: "In the past 24 hours, OpenAI announced plans to release its first open-weight language model with reasoning
capabilities since GPT-2. This model will allow developers to fine-tune it for specific applications without needing
the original training data. To gather feedback and refine the model, OpenAI will host developer events starting
in San Francisco and expanding to Europe and Asia-Pacific regions. ([reuters.com](https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai))\n\n\n##
OpenAI to Release Open-Weight Language Model:\n- [OpenAI plans to release open-weight language model in coming
months](https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai) "
url: https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai
logprobs: []
text: "OpenAI's recent launch of GPT-5 has faced mixed reactions. Despite strong benchmark performance and early
praise, users have reported issues like errors in basic math and geography. CEO Sam Altman has acknowledged these
concerns and assured that improvements are underway. ([axios.com](https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai))\n\n\n##
OpenAI's GPT-5 Launch Faces Mixed Reactions:\n- [OpenAI's big GPT-5 launch gets bumpy](https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai) "
type: output_text
id: msg_67ebcbbaf988819192d44919020b82e704f5055a2a33abc3
id: msg_689b7c951b7481968513d007e75151fd07450cfc2d48b975
role: assistant
status: completed
type: message
parallel_tool_calls: true
previous_response_id: null
prompt_cache_key: null
reasoning:
effort: null
generate_summary: null
summary: null
safety_identifier: null
service_tier: default
status: completed
store: true
temperature: 1.0
text:
format:
type: text
verbosity: medium
tool_choice: auto
tools:
- search_context_size: medium
Expand All @@ -103,16 +112,17 @@ interactions:
region: null
timezone: null
type: approximate
top_logprobs: 0
top_p: 1.0
truncation: disabled
usage:
input_tokens: 320
input_tokens_details:
cached_tokens: 0
output_tokens: 200
output_tokens: 159
output_tokens_details:
reasoning_tokens: 0
total_tokens: 520
total_tokens: 479
user: null
status:
code: 200
Expand Down
12 changes: 6 additions & 6 deletions tests/models/test_openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,23 @@ async def test_openai_responses_model_builtin_tools(allow_model_requests: None,
parts=[
TextPart(
content="""\
In the past 24 hours, OpenAI announced plans to release its first open-weight language model with reasoning capabilities since GPT-2. This model will allow developers to fine-tune it for specific applications without needing the original training data. To gather feedback and refine the model, OpenAI will host developer events starting in San Francisco and expanding to Europe and Asia-Pacific regions. ([reuters.com](https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai))
OpenAI's recent launch of GPT-5 has faced mixed reactions. Despite strong benchmark performance and early praise, users have reported issues like errors in basic math and geography. CEO Sam Altman has acknowledged these concerns and assured that improvements are underway. ([axios.com](https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai))


## OpenAI to Release Open-Weight Language Model:
- [OpenAI plans to release open-weight language model in coming months](https://www.reuters.com/technology/artificial-intelligence/openai-plans-release-open-weight-language-model-coming-months-2025-03-31/?utm_source=openai) \
## OpenAI's GPT-5 Launch Faces Mixed Reactions:
- [OpenAI's big GPT-5 launch gets bumpy](https://www.axios.com/2025/08/12/gpt-5-bumpy-launch-openai?utm_source=openai) \
"""
)
],
usage=Usage(
request_tokens=320,
response_tokens=200,
total_tokens=520,
response_tokens=159,
total_tokens=479,
details={'reasoning_tokens': 0, 'cached_tokens': 0},
),
model_name='gpt-4o-2024-08-06',
timestamp=IsDatetime(),
vendor_id='resp_67ebcbb93728819197f923ff16e98bce04f5055a2a33abc3',
vendor_id='resp_689b7c90010c8196ac0efd68b021490f07450cfc2d48b975',
),
]
)
Expand Down