Skip to content

Commit eb5483b

Browse files
seratchdaavoo
andauthored
chore(deps): Bump "openai>=1.99.6,<2" (#1415)
- fix(litellm_model): Replace `Function` with `ChatCompletionMessageFunctionToolCall`. - Breaking change coming from https://github.com/openai/openai-python/releases/tag/v1.99.2 This pull request resolves the errors in #1396 Fixes #1395 Fixes #1401 --------- Co-authored-by: daavoo <[email protected]>
1 parent 975cdec commit eb5483b

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = ">=3.9"
77
license = "MIT"
88
authors = [{ name = "OpenAI", email = "[email protected]" }]
99
dependencies = [
10-
"openai>=1.97.1,<2",
10+
"openai>=1.99.6,<2",
1111
"pydantic>=2.10, <3",
1212
"griffe>=1.5.6, <2",
1313
"typing-extensions>=4.12.2, <5",

src/agents/extensions/models/litellm_model.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
) from _e
1919

2020
from openai import NOT_GIVEN, AsyncStream, NotGiven
21-
from openai.types.chat import ChatCompletionChunk, ChatCompletionMessageToolCall
21+
from openai.types.chat import (
22+
ChatCompletionChunk,
23+
ChatCompletionMessageFunctionToolCall,
24+
)
2225
from openai.types.chat.chat_completion_message import (
2326
Annotation,
2427
AnnotationURLCitation,
2528
ChatCompletionMessage,
2629
)
27-
from openai.types.chat.chat_completion_message_tool_call import Function
30+
from openai.types.chat.chat_completion_message_function_tool_call import Function
31+
from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall
2832
from openai.types.responses import Response
2933

3034
from ... import _debug
@@ -362,7 +366,7 @@ def convert_message_to_openai(
362366
if message.role != "assistant":
363367
raise ModelBehaviorError(f"Unsupported role: {message.role}")
364368

365-
tool_calls = (
369+
tool_calls: list[ChatCompletionMessageToolCall] | None = (
366370
[LitellmConverter.convert_tool_call_to_openai(tool) for tool in message.tool_calls]
367371
if message.tool_calls
368372
else None
@@ -413,11 +417,12 @@ def convert_annotations_to_openai(
413417
@classmethod
414418
def convert_tool_call_to_openai(
415419
cls, tool_call: litellm.types.utils.ChatCompletionMessageToolCall
416-
) -> ChatCompletionMessageToolCall:
417-
return ChatCompletionMessageToolCall(
420+
) -> ChatCompletionMessageFunctionToolCall:
421+
return ChatCompletionMessageFunctionToolCall(
418422
id=tool_call.id,
419423
type="function",
420424
function=Function(
421-
name=tool_call.function.name or "", arguments=tool_call.function.arguments
425+
name=tool_call.function.name or "",
426+
arguments=tool_call.function.arguments,
422427
),
423428
)

src/agents/models/chatcmpl_converter.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
ChatCompletionContentPartTextParam,
1313
ChatCompletionDeveloperMessageParam,
1414
ChatCompletionMessage,
15+
ChatCompletionMessageFunctionToolCallParam,
1516
ChatCompletionMessageParam,
16-
ChatCompletionMessageToolCallParam,
1717
ChatCompletionSystemMessageParam,
1818
ChatCompletionToolChoiceOptionParam,
1919
ChatCompletionToolMessageParam,
@@ -126,15 +126,18 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
126126

127127
if message.tool_calls:
128128
for tool_call in message.tool_calls:
129-
items.append(
130-
ResponseFunctionToolCall(
131-
id=FAKE_RESPONSES_ID,
132-
call_id=tool_call.id,
133-
arguments=tool_call.function.arguments,
134-
name=tool_call.function.name,
135-
type="function_call",
129+
if tool_call.type == "function":
130+
items.append(
131+
ResponseFunctionToolCall(
132+
id=FAKE_RESPONSES_ID,
133+
call_id=tool_call.id,
134+
arguments=tool_call.function.arguments,
135+
name=tool_call.function.name,
136+
type="function_call",
137+
)
136138
)
137-
)
139+
elif tool_call.type == "custom":
140+
pass
138141

139142
return items
140143

@@ -420,7 +423,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
420423
elif file_search := cls.maybe_file_search_call(item):
421424
asst = ensure_assistant_message()
422425
tool_calls = list(asst.get("tool_calls", []))
423-
new_tool_call = ChatCompletionMessageToolCallParam(
426+
new_tool_call = ChatCompletionMessageFunctionToolCallParam(
424427
id=file_search["id"],
425428
type="function",
426429
function={
@@ -440,7 +443,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam:
440443
asst = ensure_assistant_message()
441444
tool_calls = list(asst.get("tool_calls", []))
442445
arguments = func_call["arguments"] if func_call["arguments"] else "{}"
443-
new_tool_call = ChatCompletionMessageToolCallParam(
446+
new_tool_call = ChatCompletionMessageFunctionToolCallParam(
444447
id=func_call["call_id"],
445448
type="function",
446449
function={

tests/test_openai_chatcompletions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from openai.types.chat.chat_completion import ChatCompletion, Choice
1010
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk
1111
from openai.types.chat.chat_completion_message import ChatCompletionMessage
12-
from openai.types.chat.chat_completion_message_tool_call import (
13-
ChatCompletionMessageToolCall,
12+
from openai.types.chat.chat_completion_message_tool_call import ( # type: ignore[attr-defined]
13+
ChatCompletionMessageFunctionToolCall,
1414
Function,
1515
)
1616
from openai.types.completion_usage import (
@@ -152,7 +152,7 @@ async def test_get_response_with_tool_call(monkeypatch) -> None:
152152
should append corresponding `ResponseFunctionToolCall` items after the
153153
assistant message item with matching name/arguments.
154154
"""
155-
tool_call = ChatCompletionMessageToolCall(
155+
tool_call = ChatCompletionMessageFunctionToolCall(
156156
id="call-id",
157157
type="function",
158158
function=Function(name="do_thing", arguments="{'x':1}"),

tests/test_openai_chatcompletions_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from typing import Literal, cast
2727

2828
import pytest
29-
from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageToolCall
29+
from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageFunctionToolCall
3030
from openai.types.chat.chat_completion_message_tool_call import Function
3131
from openai.types.responses import (
3232
ResponseFunctionToolCall,
@@ -87,7 +87,7 @@ def test_message_to_output_items_with_tool_call():
8787
be reflected as separate `ResponseFunctionToolCall` items appended after
8888
the message item.
8989
"""
90-
tool_call = ChatCompletionMessageToolCall(
90+
tool_call = ChatCompletionMessageFunctionToolCall(
9191
id="tool1",
9292
type="function",
9393
function=Function(name="myfn", arguments='{"x":1}'),
@@ -185,7 +185,7 @@ def test_items_to_messages_with_output_message_and_function_call():
185185
# Refusal in output message should be represented in assistant message
186186
assert "refusal" in assistant
187187
assert assistant["refusal"] == refusal.refusal
188-
# Tool calls list should contain one ChatCompletionMessageToolCall dict
188+
# Tool calls list should contain one ChatCompletionMessageFunctionToolCall dict
189189
tool_calls = assistant.get("tool_calls")
190190
assert isinstance(tool_calls, list)
191191
assert len(tool_calls) == 1
@@ -341,8 +341,8 @@ def test_tool_call_conversion():
341341

342342
tool_call = tool_calls[0]
343343
assert tool_call["id"] == function_call["call_id"]
344-
assert tool_call["function"]["name"] == function_call["name"]
345-
assert tool_call["function"]["arguments"] == function_call["arguments"]
344+
assert tool_call["function"]["name"] == function_call["name"] # type: ignore
345+
assert tool_call["function"]["arguments"] == function_call["arguments"] # type: ignore
346346

347347

348348
@pytest.mark.parametrize("role", ["user", "system", "developer"])

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)