Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/req_llm/providers/openai/responses_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@ defmodule ReqLLM.Providers.OpenAI.ResponsesAPI do
item
end

item =
if detail.text do
Map.put(item, "summary", [%{"type" => "summary_text", "text" => detail.text}])
else
Map.put(item, "summary", [])
end

[item]
end

Expand Down
36 changes: 36 additions & 0 deletions test/provider/openai/responses_api_unit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,42 @@ defmodule Provider.OpenAI.ResponsesAPIUnitTest do
assert log =~ "Skipping non-OpenAI reasoning detail from provider: :anthropic"
end

test "encodes summary from reasoning detail text" do
reasoning_detail = %ReqLLM.Message.ReasoningDetails{
text: "I need to think about this carefully",
signature: "encrypted_sig_abc",
encrypted?: true,
provider: :openai,
format: "openai-responses-v1",
index: 0,
provider_data: %{"id" => "rs_prev123", "type" => "reasoning"}
}

assistant_msg = %ReqLLM.Message{
role: :assistant,
content: [%ReqLLM.Message.ContentPart{type: :text, text: "Answer"}],
reasoning_details: [reasoning_detail]
}

user_msg = %ReqLLM.Message{
role: :user,
content: [%ReqLLM.Message.ContentPart{type: :text, text: "Follow up"}]
}

context = %ReqLLM.Context{messages: [assistant_msg, user_msg]}
request = build_request(context: context)

encoded = ResponsesAPI.encode_body(request)
body = Jason.decode!(encoded.body)

[reasoning_input | _] = body["input"]
assert reasoning_input["type"] == "reasoning"

assert reasoning_input["summary"] == [
%{"type" => "summary_text", "text" => "I need to think about this carefully"}
]
end

test "encodes reasoning detail without id when provider_data has no id" do
reasoning_detail = %ReqLLM.Message.ReasoningDetails{
text: "Reasoning text",
Expand Down
Loading