Skip to content

Commit f3c9410

Browse files
committed
feat: Add reasoning content for openai model provider
1 parent 7f0a905 commit f3c9410

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

tests/strands/models/test_openai.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def test_stream(openai_client, model):
6363
mock_tool_call_1_part_1 = unittest.mock.Mock(index=0)
6464
mock_tool_call_2_part_1 = unittest.mock.Mock(index=1)
6565
mock_delta_1 = unittest.mock.Mock(
66-
reasoning_content="<think>",
66+
reasoning_content="",
6767
content=None,
6868
tool_calls=None,
6969
)
7070
mock_delta_2 = unittest.mock.Mock(
71-
reasoning_content="\nOkey, the user just</think>",
71+
reasoning_content="\nI'm thinking",
7272
content=None,
7373
tool_calls=None,
7474
)
@@ -101,8 +101,8 @@ def test_stream(openai_client, model):
101101
exp_events = [
102102
{"chunk_type": "message_start"},
103103
{"chunk_type": "content_start", "data_type": "text"},
104-
{"chunk_type": "content_delta", "data_type": "reasoning_content", "data": "<think>"},
105-
{"chunk_type": "content_delta", "data_type": "reasoning_content", "data": "\nOkey, the user just</think>"},
104+
# {"chunk_type": "content_delta", "data_type": "reasoning_content", "data": ""},
105+
{"chunk_type": "content_delta", "data_type": "reasoning_content", "data": "\nI'm thinking"},
106106
{"chunk_type": "content_delta", "data_type": "text", "data": "I'll calculate"},
107107
{"chunk_type": "content_delta", "data_type": "text", "data": "that for you"},
108108
{"chunk_type": "content_stop", "data_type": "text"},

tests/strands/types/models/test_openai.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ def test_format_request_message_content(content, exp_result):
107107
assert tru_result == exp_result
108108

109109

110-
def test_format_request_message_content_unsupported_type():
111-
content = {"unsupported": {}}
112-
113-
with pytest.raises(TypeError, match="content_type=<unsupported> | unsupported type"):
114-
SAOpenAIModel.format_request_message_content(content)
115-
116-
117110
def test_format_request_message_tool_call():
118111
tool_use = {
119112
"input": {"expression": "2+2"},
@@ -288,6 +281,11 @@ def test_format_request(model, messages, tool_specs, system_prompt):
288281
},
289282
{"contentBlockDelta": {"delta": {"toolUse": {"input": ""}}}},
290283
),
284+
# Content Delta - Reasoning Text
285+
(
286+
{"chunk_type": "content_delta", "data_type": "reasoning_content", "data": "I'm thinking"},
287+
{"contentBlockDelta": {"delta": {"reasoningContent": {"text": "I'm thinking"}}}},
288+
),
291289
# Content Delta - Text
292290
(
293291
{"chunk_type": "content_delta", "data_type": "text", "data": "hello"},
@@ -337,10 +335,3 @@ def test_format_request(model, messages, tool_specs, system_prompt):
337335
def test_format_chunk(event, exp_chunk, model):
338336
tru_chunk = model.format_chunk(event)
339337
assert tru_chunk == exp_chunk
340-
341-
342-
def test_format_chunk_unknown_type(model):
343-
event = {"chunk_type": "unknown"}
344-
345-
with pytest.raises(RuntimeError, match="chunk_type=<unknown> | unknown type"):
346-
model.format_chunk(event)

0 commit comments

Comments
 (0)