Skip to content

Commit c8bcc6e

Browse files
Add new OpenAI GPT-5 models (#2503)
1 parent 5ad233b commit c8bcc6e

File tree

6 files changed

+48
-13
lines changed

6 files changed

+48
-13
lines changed

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@
194194
'gpt-4o-mini-search-preview-2025-03-11',
195195
'gpt-4o-search-preview',
196196
'gpt-4o-search-preview-2025-03-11',
197+
'gpt-5',
198+
'gpt-5-2025-08-07',
199+
'gpt-5-chat-latest',
200+
'gpt-5-mini',
201+
'gpt-5-mini-2025-08-07',
202+
'gpt-5-nano',
203+
'gpt-5-nano-2025-08-07',
197204
'grok:grok-4',
198205
'grok:grok-4-0709',
199206
'grok:grok-3',
@@ -313,11 +320,18 @@
313320
'openai:gpt-4o-mini-search-preview-2025-03-11',
314321
'openai:gpt-4o-search-preview',
315322
'openai:gpt-4o-search-preview-2025-03-11',
323+
'openai:gpt-5',
324+
'openai:gpt-5-2025-08-07',
316325
'openai:o1',
326+
'openai:gpt-5-chat-latest',
317327
'openai:o1-2024-12-17',
328+
'openai:gpt-5-mini',
318329
'openai:o1-mini',
330+
'openai:gpt-5-mini-2025-08-07',
319331
'openai:o1-mini-2024-09-12',
332+
'openai:gpt-5-nano',
320333
'openai:o1-preview',
334+
'openai:gpt-5-nano-2025-08-07',
321335
'openai:o1-preview-2024-09-12',
322336
'openai:o1-pro',
323337
'openai:o1-pro-2025-03-19',

pydantic_ai_slim/pydantic_ai/models/openai.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
from openai.types.chat.chat_completion_content_part_image_param import ImageURL
6060
from openai.types.chat.chat_completion_content_part_input_audio_param import InputAudio
6161
from openai.types.chat.chat_completion_content_part_param import File, FileFile
62+
from openai.types.chat.chat_completion_message_custom_tool_call import ChatCompletionMessageCustomToolCall
63+
from openai.types.chat.chat_completion_message_function_tool_call import ChatCompletionMessageFunctionToolCall
64+
from openai.types.chat.chat_completion_message_function_tool_call_param import (
65+
ChatCompletionMessageFunctionToolCallParam,
66+
)
6267
from openai.types.chat.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
6368
from openai.types.chat.completion_create_params import (
6469
WebSearchOptions,
@@ -416,7 +421,14 @@ def _process_response(self, response: chat.ChatCompletion | str) -> ModelRespons
416421
items.extend(split_content_into_text_and_thinking(choice.message.content, self.profile.thinking_tags))
417422
if choice.message.tool_calls is not None:
418423
for c in choice.message.tool_calls:
419-
part = ToolCallPart(c.function.name, c.function.arguments, tool_call_id=c.id)
424+
if isinstance(c, ChatCompletionMessageFunctionToolCall):
425+
part = ToolCallPart(c.function.name, c.function.arguments, tool_call_id=c.id)
426+
elif isinstance(c, ChatCompletionMessageCustomToolCall): # pragma: no cover
427+
# NOTE: Custom tool calls are not supported.
428+
# See <https://github.com/pydantic/pydantic-ai/issues/2513> for more details.
429+
raise RuntimeError('Custom tool calls are not supported')
430+
else:
431+
assert_never(c)
420432
part.tool_call_id = _guard_tool_call_id(part)
421433
items.append(part)
422434
return ModelResponse(
@@ -476,7 +488,7 @@ async def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCom
476488
openai_messages.append(item)
477489
elif isinstance(message, ModelResponse):
478490
texts: list[str] = []
479-
tool_calls: list[chat.ChatCompletionMessageToolCallParam] = []
491+
tool_calls: list[ChatCompletionMessageFunctionToolCallParam] = []
480492
for item in message.parts:
481493
if isinstance(item, TextPart):
482494
texts.append(item.content)
@@ -507,8 +519,8 @@ async def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCom
507519
return openai_messages
508520

509521
@staticmethod
510-
def _map_tool_call(t: ToolCallPart) -> chat.ChatCompletionMessageToolCallParam:
511-
return chat.ChatCompletionMessageToolCallParam(
522+
def _map_tool_call(t: ToolCallPart) -> ChatCompletionMessageFunctionToolCallParam:
523+
return ChatCompletionMessageFunctionToolCallParam(
512524
id=_guard_tool_call_id(t=t),
513525
type='function',
514526
function={'name': t.tool_name, 'arguments': t.args_as_json_str()},

pydantic_ai_slim/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencies = [
6262
# WARNING if you add optional groups, please update docs/install.md
6363
logfire = ["logfire>=3.14.1"]
6464
# Models
65-
openai = ["openai>=1.92.0"]
65+
openai = ["openai>=1.99.9"]
6666
cohere = ["cohere>=5.16.0; platform_system != 'Emscripten'"]
6767
vertexai = ["google-auth>=2.36.0", "requests>=2.32.2"]
6868
google = ["google-genai>=1.28.0"]

tests/models/cassettes/test_model_names/test_known_model_names.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ interactions:
1414
uri: https://us.inference.heroku.com/available-models
1515
response:
1616
headers:
17+
cache-control:
18+
- no-cache, no-store, must-revalidate
19+
connection:
20+
- keep-alive
1721
content-length:
1822
- '760'
1923
content-security-policy:
2024
- default-src 'none'; frame-ancestors 'none'
2125
content-type:
2226
- application/json
27+
expires:
28+
- '0'
29+
pragma:
30+
- no-cache
2331
strict-transport-security:
2432
- max-age=63072000
2533
parsed_body:

tests/models/test_openai.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
ChoiceDeltaToolCallFunction,
6161
)
6262
from openai.types.chat.chat_completion_message import ChatCompletionMessage
63+
from openai.types.chat.chat_completion_message_function_tool_call import ChatCompletionMessageFunctionToolCall
6364
from openai.types.chat.chat_completion_message_tool_call import Function
6465
from openai.types.chat.chat_completion_token_logprob import ChatCompletionTokenLogprob
6566
from openai.types.completion_usage import CompletionUsage, PromptTokensDetails
@@ -241,7 +242,7 @@ async def test_request_structured_response(allow_model_requests: None):
241242
content=None,
242243
role='assistant',
243244
tool_calls=[
244-
chat.ChatCompletionMessageToolCall(
245+
ChatCompletionMessageFunctionToolCall(
245246
id='123',
246247
function=Function(arguments='{"response": [1, 2, 123]}', name='final_result'),
247248
type='function',
@@ -292,7 +293,7 @@ async def test_request_tool_call(allow_model_requests: None):
292293
content=None,
293294
role='assistant',
294295
tool_calls=[
295-
chat.ChatCompletionMessageToolCall(
296+
ChatCompletionMessageFunctionToolCall(
296297
id='1',
297298
function=Function(arguments='{"loc_name": "San Fransisco"}', name='get_location'),
298299
type='function',
@@ -311,7 +312,7 @@ async def test_request_tool_call(allow_model_requests: None):
311312
content=None,
312313
role='assistant',
313314
tool_calls=[
314-
chat.ChatCompletionMessageToolCall(
315+
ChatCompletionMessageFunctionToolCall(
315316
id='2',
316317
function=Function(arguments='{"loc_name": "London"}', name='get_location'),
317318
type='function',
@@ -722,7 +723,7 @@ async def test_parallel_tool_calls(allow_model_requests: None, parallel_tool_cal
722723
content=None,
723724
role='assistant',
724725
tool_calls=[
725-
chat.ChatCompletionMessageToolCall(
726+
ChatCompletionMessageFunctionToolCall(
726727
id='123',
727728
function=Function(arguments='{"response": [1, 2, 3]}', name='final_result'),
728729
type='function',

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)