Skip to content

Commit bcc2d7c

Browse files
authored
fix external import error (#211)
* fix * lint
1 parent 87fdc2c commit bcc2d7c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

eval_protocol/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
from .pytest import evaluation_test, SingleTurnRolloutProcessor
4242
from .pytest.parameterize import DefaultParameterIdGenerator
4343

44-
from .adapters import OpenAIResponsesAdapter
44+
try:
45+
from .adapters import OpenAIResponsesAdapter
46+
except ImportError:
47+
OpenAIResponsesAdapter = None
4548

4649
try:
4750
from .adapters import LangfuseAdapter, create_langfuse_adapter

eval_protocol/adapters/openai_responses.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from typing_extensions import Any
1111

1212
from openai.pagination import SyncCursorPage
13-
from openai.types.chat.chat_completion_function_tool_param import ChatCompletionFunctionToolParam
13+
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
1414
from openai.types.chat.chat_completion_message import FunctionCall
1515
from openai.types.responses import Response
1616
from openai.types.responses.response_item import ResponseItem
17-
from openai.types.chat.chat_completion_message_function_tool_call import (
18-
ChatCompletionMessageFunctionToolCall,
17+
from openai.types.chat.chat_completion_message_tool_call import (
18+
ChatCompletionMessageToolCall,
1919
Function,
2020
)
2121
from openai.types.responses.tool import Tool
@@ -114,11 +114,9 @@ def _create_evaluation_row(self, input_items: SyncCursorPage[ResponseItem], resp
114114
),
115115
)
116116

117-
def _responses_tools_to_chat_completion_tools(
118-
self, tools: List[Tool]
119-
) -> Sequence[ChatCompletionFunctionToolParam]:
117+
def _responses_tools_to_chat_completion_tools(self, tools: List[Tool]) -> Sequence[ChatCompletionToolParam]:
120118
"""Convert OpenAI Responses API tools to chat completion message function tool calls."""
121-
chat_completion_tools: List[ChatCompletionFunctionToolParam] = []
119+
chat_completion_tools: List[ChatCompletionToolParam] = []
122120
for tool in tools:
123121
if tool.type == "function":
124122
chat_completion_tools.append(
@@ -146,7 +144,7 @@ def _create_messages(self, input_items: SyncCursorPage[ResponseItem]) -> Iterabl
146144
be added before the assistant message with tool calls.
147145
"""
148146
messages: list[Message] = []
149-
current_tool_calls: list[ChatCompletionMessageFunctionToolCall] = []
147+
current_tool_calls: list[ChatCompletionMessageToolCall] = []
150148
tool_call_outputs: list[Message] = []
151149

152150
for item in input_items:
@@ -173,7 +171,7 @@ def _create_messages(self, input_items: SyncCursorPage[ResponseItem]) -> Iterabl
173171
# Collect tool call outputs to add before assistant message
174172
tool_call_outputs.append(Message(role="tool", content=item.output, tool_call_id=item.call_id))
175173
elif item.type == "function_call":
176-
tool_call = ChatCompletionMessageFunctionToolCall(
174+
tool_call = ChatCompletionMessageToolCall(
177175
id=item.call_id, type="function", function=Function(name=item.name, arguments=item.arguments)
178176
)
179177
current_tool_calls.append(tool_call)

0 commit comments

Comments
 (0)