Skip to content

Commit 8302358

Browse files
committed
fix
1 parent 613c544 commit 8302358

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/agents/extensions/models/litellm_model.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
) from _e
1919

2020
from openai import NOT_GIVEN, AsyncStream, NotGiven
21-
from openai.types.chat import ChatCompletionChunk, ChatCompletionMessageFunctionToolCall
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_function_tool_call import (
28-
ChatCompletionMessageFunctionToolCall,
29-
)
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
3032
from openai.types.responses import Response
3133

3234
from ... import _debug
@@ -364,7 +366,7 @@ def convert_message_to_openai(
364366
if message.role != "assistant":
365367
raise ModelBehaviorError(f"Unsupported role: {message.role}")
366368

367-
tool_calls = (
369+
tool_calls: list[ChatCompletionMessageToolCall] | None = (
368370
[LitellmConverter.convert_tool_call_to_openai(tool) for tool in message.tool_calls]
369371
if message.tool_calls
370372
else None
@@ -419,7 +421,8 @@ def convert_tool_call_to_openai(
419421
return ChatCompletionMessageFunctionToolCall(
420422
id=tool_call.id,
421423
type="function",
422-
function=ChatCompletionMessageFunctionToolCall(
423-
name=tool_call.function.name or "", arguments=tool_call.function.arguments
424+
function=Function(
425+
name=tool_call.function.name or "",
426+
arguments=tool_call.function.arguments,
424427
),
425428
)

src/agents/models/chatcmpl_converter.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)