Skip to content

Commit 27f9314

Browse files
committed
Fix openai reasoning not being included in messages.
1 parent fad98c2 commit 27f9314

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix openai reasoning not being included in messages.
6+
57
## 0.23.0
68

79
- Support parallel tool call.

src/eca/features/chat.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@
252252
:id id
253253
:text text}))
254254
:finished (do
255-
(add-to-history! {:role "reason" :content {:external-id external-id
255+
(add-to-history! {:role "reason" :content {:id id
256+
:external-id external-id
256257
:text @received-thinking*}})
257258
(send-content! chat-ctx :assistant
258259
{:type :reasonFinished

src/eca/llm_providers/openai.clj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require
33
[cheshire.core :as json]
44
[clojure.java.io :as io]
5+
[clojure.string :as string]
56
[eca.llm-util :as llm-util]
67
[eca.logger :as logger]
78
[hato.client :as http]))
@@ -51,8 +52,13 @@
5152
{:type "function_call_output"
5253
:call_id (:id content)
5354
:output (llm-util/stringfy-tool-result content)}
54-
;; TODO include reason blocks
55-
"reason" nil
55+
"reason" {:type "reasoning"
56+
:id (:id content)
57+
:summary (if (string/blank? (:text content))
58+
[]
59+
[{:type "summary_text"
60+
:text (:text content)}])
61+
:encrypted_content (:external-id content)}
5662
(update msg :content (fn [c]
5763
(if (string? c)
5864
c
@@ -76,6 +82,9 @@
7682
:parallel_tool_calls true
7783
:instructions instructions
7884
:tools tools
85+
:include (when reason?
86+
["reasoning.encrypted_content"])
87+
:store false
7988
:reasoning (when reason?
8089
{:effort "medium"
8190
:summary "detailed"})
@@ -101,7 +110,7 @@
101110
(case (:type (:item data))
102111
"reasoning" (on-reason {:status :finished
103112
:id (-> data :item :id)
104-
:external-id (-> data :item :id)})
113+
:external-id (-> data :item :encrypted_content)})
105114
nil)
106115

107116
;; URL mentioned
@@ -166,6 +175,12 @@
166175
(swap! tool-call-by-item-id* dissoc (:item-id tool-call))))
167176
(on-message-received {:type :finish
168177
:finish-reason (-> data :response :status)})))
178+
179+
"response.failed" (do
180+
(when-let [error (-> data :response :error)]
181+
(on-error {:message (:message error)}))
182+
(on-message-received {:type :finish
183+
:finish-reason (-> data :response :status)}))
169184
nil))]
170185
(base-completion-request!
171186
{:rid (llm-util/gen-rid)

0 commit comments

Comments
 (0)