Skip to content

Commit 22d5435

Browse files
committed
Add error handling
1 parent ea5b818 commit 22d5435

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/eca/llm_api.clj

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,22 @@
262262
:user-messages user-messages
263263
:on-error on-error-wrapper
264264
:config config})]
265-
(let [{:keys [output-text reason-text tools-to-call call-tools-fn reason-id usage]} result]
266-
(when reason-text
267-
(on-reason-wrapper {:status :started :id reason-id})
268-
(on-reason-wrapper {:status :thinking :id reason-id :text reason-text})
269-
(on-reason-wrapper {:status :finished :id reason-id}))
270-
(on-message-received-wrapper {:type :text :text output-text})
271-
(some-> usage (on-usage-updated))
272-
(if-let [new-result (when (seq tools-to-call)
273-
(doseq [tool-to-call tools-to-call]
274-
(on-prepare-tool-call tool-to-call))
275-
(call-tools-fn on-tools-called))]
276-
(recur new-result)
277-
(on-message-received-wrapper {:type :finish :finish-reason "stop"}))))
265+
(let [{:keys [error output-text reason-text tools-to-call call-tools-fn reason-id usage]} result]
266+
(if error
267+
(on-error-wrapper error)
268+
(do
269+
(when reason-text
270+
(on-reason-wrapper {:status :started :id reason-id})
271+
(on-reason-wrapper {:status :thinking :id reason-id :text reason-text})
272+
(on-reason-wrapper {:status :finished :id reason-id}))
273+
(on-message-received-wrapper {:type :text :text output-text})
274+
(some-> usage (on-usage-updated))
275+
(if-let [new-result (when (seq tools-to-call)
276+
(doseq [tool-to-call tools-to-call]
277+
(on-prepare-tool-call tool-to-call))
278+
(call-tools-fn on-tools-called))]
279+
(recur new-result)
280+
(on-message-received-wrapper {:type :finish :finish-reason "stop"}))))))
278281
(prompt!
279282
{:sync? false
280283
:provider provider

src/eca/llm_providers/openai_chat.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
on-error
9494
(fn [error-data]
9595
(llm-util/log-response logger-tag rid "response-error" error-data)
96-
error-data))]
96+
{:error error-data}))]
9797
(llm-util/log-request logger-tag rid url body)
9898
@(http/post
9999
url

0 commit comments

Comments
 (0)