Skip to content

Commit dec9fec

Browse files
committed
fix: #2038 openai==2.7.0 compatibility
1 parent d659a73 commit dec9fec

13 files changed

+88
-29
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>=2.6.1,<3",
10+
"openai>=2.7,<3",
1111
"pydantic>=2.12.3, <3",
1212
"griffe>=1.5.6, <2",
1313
"typing-extensions>=4.12.2, <5",

src/agents/models/chatcmpl_converter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon
136136
)
137137
if message.content:
138138
message_item.content.append(
139-
ResponseOutputText(text=message.content, type="output_text", annotations=[])
139+
ResponseOutputText(
140+
text=message.content, type="output_text", annotations=[], logprobs=[]
141+
)
140142
)
141143
if message.refusal:
142144
message_item.content.append(

src/agents/models/chatcmpl_stream_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ async def handle_stream(
231231
text="",
232232
type="output_text",
233233
annotations=[],
234+
logprobs=[],
234235
),
235236
)
236237
# Start a new assistant message stream
@@ -258,6 +259,7 @@ async def handle_stream(
258259
text="",
259260
type="output_text",
260261
annotations=[],
262+
logprobs=[],
261263
),
262264
type="response.content_part.added",
263265
sequence_number=sequence_number.get_and_increment(),

tests/test_agent_as_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async def test_agent_as_tool_returns_concatenated_text(monkeypatch: pytest.Monke
240240
annotations=[],
241241
text="Hello world",
242242
type="output_text",
243-
logprobs=None,
243+
logprobs=[],
244244
)
245245
],
246246
)
@@ -304,7 +304,7 @@ async def test_agent_as_tool_custom_output_extractor(monkeypatch: pytest.MonkeyP
304304
annotations=[],
305305
text="Original text",
306306
type="output_text",
307-
logprobs=None,
307+
logprobs=[],
308308
)
309309
],
310310
)

tests/test_agent_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ async def echo_tool(text: str) -> str:
12261226
"content": [
12271227
{
12281228
"annotations": [],
1229+
"logprobs": [],
12291230
"text": "Summary: Echoed foo and bar",
12301231
"type": "output_text",
12311232
}

tests/test_call_model_input_filter_unit.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ async def test_call_model_input_filter_sync_non_streamed_unit() -> None:
2828
id="1",
2929
type="message",
3030
role="assistant",
31-
content=[ResponseOutputText(text="ok", type="output_text", annotations=[])],
31+
content=[
32+
ResponseOutputText(
33+
text="ok", type="output_text", annotations=[], logprobs=[]
34+
)
35+
],
3236
status="completed",
3337
)
3438
]
@@ -64,7 +68,11 @@ async def test_call_model_input_filter_async_streamed_unit() -> None:
6468
id="1",
6569
type="message",
6670
role="assistant",
67-
content=[ResponseOutputText(text="ok", type="output_text", annotations=[])],
71+
content=[
72+
ResponseOutputText(
73+
text="ok", type="output_text", annotations=[], logprobs=[]
74+
)
75+
],
6876
status="completed",
6977
)
7078
]

tests/test_extension_filters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def _get_message_output_run_item(content: str) -> MessageOutputItem:
4242
agent=fake_agent(),
4343
raw_item=ResponseOutputMessage(
4444
id="1",
45-
content=[ResponseOutputText(text=content, annotations=[], type="output_text")],
45+
content=[
46+
ResponseOutputText(
47+
text=content, annotations=[], type="output_text", logprobs=[]
48+
)
49+
],
4650
role="assistant",
4751
status="completed",
4852
type="message",

tests/test_handoff_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def message_item(content: str, agent: Agent[Any]) -> MessageOutputItem:
2727
status="completed",
2828
role="assistant",
2929
type="message",
30-
content=[ResponseOutputText(text=content, type="output_text", annotations=[])],
30+
content=[
31+
ResponseOutputText(text=content, type="output_text", annotations=[], logprobs=[])
32+
],
3133
),
3234
)
3335

tests/test_items_helpers.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,22 @@ def make_message(
5757

5858
def test_extract_last_content_of_text_message() -> None:
5959
# Build a message containing two text segments.
60-
content1 = ResponseOutputText(annotations=[], text="Hello ", type="output_text")
61-
content2 = ResponseOutputText(annotations=[], text="world!", type="output_text")
60+
content1 = ResponseOutputText(
61+
annotations=[], text="Hello ", type="output_text", logprobs=[]
62+
)
63+
content2 = ResponseOutputText(
64+
annotations=[], text="world!", type="output_text", logprobs=[]
65+
)
6266
message = make_message([content1, content2])
6367
# Helpers should yield the last segment's text.
6468
assert ItemHelpers.extract_last_content(message) == "world!"
6569

6670

6771
def test_extract_last_content_of_refusal_message() -> None:
6872
# Build a message whose last content entry is a refusal.
69-
content1 = ResponseOutputText(annotations=[], text="Before refusal", type="output_text")
73+
content1 = ResponseOutputText(
74+
annotations=[], text="Before refusal", type="output_text", logprobs=[]
75+
)
7076
refusal = ResponseOutputRefusal(refusal="I cannot do that", type="refusal")
7177
message = make_message([content1, refusal])
7278
# Helpers should extract the refusal string when last content is a refusal.
@@ -87,8 +93,12 @@ def test_extract_last_content_non_message_returns_empty() -> None:
8793

8894
def test_extract_last_text_returns_text_only() -> None:
8995
# A message whose last segment is text yields the text.
90-
first_text = ResponseOutputText(annotations=[], text="part1", type="output_text")
91-
second_text = ResponseOutputText(annotations=[], text="part2", type="output_text")
96+
first_text = ResponseOutputText(
97+
annotations=[], text="part1", type="output_text", logprobs=[]
98+
)
99+
second_text = ResponseOutputText(
100+
annotations=[], text="part2", type="output_text", logprobs=[]
101+
)
92102
message = make_message([first_text, second_text])
93103
assert ItemHelpers.extract_last_text(message) == "part2"
94104
# Whereas when last content is a refusal, extract_last_text returns None.
@@ -116,9 +126,13 @@ def test_input_to_new_input_list_deep_copies_lists() -> None:
116126
def test_text_message_output_concatenates_text_segments() -> None:
117127
# Build a message with both text and refusal segments, only text segments are concatenated.
118128
pieces: list[ResponseOutputText | ResponseOutputRefusal] = []
119-
pieces.append(ResponseOutputText(annotations=[], text="a", type="output_text"))
129+
pieces.append(
130+
ResponseOutputText(annotations=[], text="a", type="output_text", logprobs=[])
131+
)
120132
pieces.append(ResponseOutputRefusal(refusal="denied", type="refusal"))
121-
pieces.append(ResponseOutputText(annotations=[], text="b", type="output_text"))
133+
pieces.append(
134+
ResponseOutputText(annotations=[], text="b", type="output_text", logprobs=[])
135+
)
122136
message = make_message(pieces)
123137
# Wrap into MessageOutputItem to feed into text_message_output.
124138
item = MessageOutputItem(agent=Agent(name="test"), raw_item=message)
@@ -131,8 +145,12 @@ def test_text_message_outputs_across_list_of_runitems() -> None:
131145
that only MessageOutputItem instances contribute any text. The non-message
132146
(ReasoningItem) should be ignored by Helpers.text_message_outputs.
133147
"""
134-
message1 = make_message([ResponseOutputText(annotations=[], text="foo", type="output_text")])
135-
message2 = make_message([ResponseOutputText(annotations=[], text="bar", type="output_text")])
148+
message1 = make_message(
149+
[ResponseOutputText(annotations=[], text="foo", type="output_text", logprobs=[])]
150+
)
151+
message2 = make_message(
152+
[ResponseOutputText(annotations=[], text="bar", type="output_text", logprobs=[])]
153+
)
136154
item1: RunItem = MessageOutputItem(agent=Agent(name="test"), raw_item=message1)
137155
item2: RunItem = MessageOutputItem(agent=Agent(name="test"), raw_item=message2)
138156
# Create a non-message run item of a different type, e.g., a reasoning trace.
@@ -171,7 +189,9 @@ def test_tool_call_output_item_constructs_function_call_output_dict():
171189

172190
def test_to_input_items_for_message() -> None:
173191
"""An output message should convert into an input dict matching the message's own structure."""
174-
content = ResponseOutputText(annotations=[], text="hello world", type="output_text")
192+
content = ResponseOutputText(
193+
annotations=[], text="hello world", type="output_text", logprobs=[]
194+
)
175195
message = ResponseOutputMessage(
176196
id="m1", content=[content], role="assistant", status="completed", type="message"
177197
)
@@ -184,6 +204,7 @@ def test_to_input_items_for_message() -> None:
184204
"content": [
185205
{
186206
"annotations": [],
207+
"logprobs": [],
187208
"text": "hello world",
188209
"type": "output_text",
189210
}

tests/test_openai_chatcompletions_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def test_items_to_messages_with_output_message_and_function_call():
152152
text="Part 1",
153153
type="output_text",
154154
annotations=[],
155+
logprobs=[],
155156
)
156157
refusal: ResponseOutputRefusal = ResponseOutputRefusal(
157158
refusal="won't do that",

0 commit comments

Comments
 (0)