Skip to content

Commit 5aa55e0

Browse files
committed
Fix tests
1 parent eda12de commit 5aa55e0

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

integration-test/integration/chat/custom_provider_test.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
162162
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
163163
(match-content chat-id "assistant" {:type "text" :text "Knock "})
164+
(match-content chat-id "system" {:type "usage"})
164165
(match-content chat-id "assistant" {:type "text" :text "knock!"})
165166
(match-content chat-id "system" {:type "progress" :state "finished"})
166167
(is (match?
@@ -184,6 +185,7 @@
184185

185186
(match-content chat-id "user" {:type "text" :text "Who's there?\n"})
186187
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
188+
(match-content chat-id "system" {:type "usage"})
187189
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
188190
(match-content chat-id "assistant" {:type "text" :text "Foo"})
189191
(match-content chat-id "system" {:type "progress" :state "finished"})
@@ -213,6 +215,7 @@
213215
(match-content chat-id "assistant" {:type "text" :text "Fo"})
214216
(match-content chat-id "assistant" {:type "text" :text "o "})
215217
(match-content chat-id "assistant" {:type "text" :text "bar"})
218+
(match-content chat-id "system" {:type "usage"})
216219
(match-content chat-id "assistant" {:type "text" :text "!\n\nHa!"})
217220
(match-content chat-id "system" {:type "progress" :state "finished"})
218221
(is (match?

integration-test/integration/chat/github_copilot_test.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
3535
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
3636
(match-content chat-id "assistant" {:type "text" :text "Knock "})
37+
(match-content chat-id "system" {:type "usage"})
3738
(match-content chat-id "assistant" {:type "text" :text "knock!"})
3839
(match-content chat-id "system" {:type "progress" :state "finished"})
3940
(is (match?
@@ -57,6 +58,7 @@
5758

5859
(match-content chat-id "user" {:type "text" :text "Who's there?\n"})
5960
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
61+
(match-content chat-id "system" {:type "usage"})
6062
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
6163
(match-content chat-id "assistant" {:type "text" :text "Foo"})
6264
(match-content chat-id "system" {:type "progress" :state "finished"})
@@ -88,6 +90,7 @@
8890
(match-content chat-id "assistant" {:type "text" :text "Fo"})
8991
(match-content chat-id "assistant" {:type "text" :text "o "})
9092
(match-content chat-id "assistant" {:type "text" :text "bar"})
93+
(match-content chat-id "system" {:type "usage"})
9194
(match-content chat-id "assistant" {:type "text" :text "!\n\nHa!"})
9295
(match-content chat-id "system" {:type "progress" :state "finished"})
9396
(is (match?
@@ -128,6 +131,7 @@
128131
(match-content chat-id "assistant" {:type "reasonText" :id (m/pred string?) :text "y hello"})
129132
(match-content chat-id "assistant" {:type "reasonFinished" :id (m/pred string?) :totalTimeMs (m/pred number?)})
130133
(match-content chat-id "assistant" {:type "text" :text "hello "})
134+
(match-content chat-id "system" {:type "usage"})
131135
(match-content chat-id "assistant" {:type "text" :text "there!"})
132136
(match-content chat-id "system" {:type "progress" :state "finished"})
133137
(is (match?
@@ -158,6 +162,7 @@
158162
(match-content chat-id "assistant" {:type "reasonText" :id (m/pred string?) :text "ay fine"})
159163
(match-content chat-id "assistant" {:type "reasonFinished" :id (m/pred string?) :totalTimeMs (m/pred number?)})
160164
(match-content chat-id "assistant" {:type "text" :text "I'm"})
165+
(match-content chat-id "system" {:type "usage"})
161166
(match-content chat-id "assistant" {:type "text" :text " fine"})
162167
(match-content chat-id "system" {:type "progress" :state "finished"})
163168
(is (match?

integration-test/integration/chat/google_test.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
3535
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
3636
(match-content chat-id "assistant" {:type "text" :text "Knoc"})
37+
(match-content chat-id "system" {:type "usage"})
3738
(match-content chat-id "assistant" {:type "text" :text "k knock!"})
3839
(match-content chat-id "system" {:type "progress" :state "finished"})
3940
(is (match?
@@ -57,6 +58,7 @@
5758

5859
(match-content chat-id "user" {:type "text" :text "Who's there?\n"})
5960
(match-content chat-id "system" {:type "progress" :state "running" :text "Waiting model"})
61+
(match-content chat-id "system" {:type "usage"})
6062
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
6163
(match-content chat-id "assistant" {:type "text" :text "Foo"})
6264
(match-content chat-id "system" {:type "progress" :state "finished"})
@@ -87,6 +89,7 @@
8789
(match-content chat-id "system" {:type "progress" :state "running" :text "Generating"})
8890
(match-content chat-id "assistant" {:type "text" :text "Fo"})
8991
(match-content chat-id "assistant" {:type "text" :text "o b"})
92+
(match-content chat-id "system" {:type "usage"})
9093
(match-content chat-id "assistant" {:type "text" :text "ar!\n\nHa!"})
9194
(match-content chat-id "system" {:type "progress" :state "finished"})
9295
(is (match?
@@ -127,6 +130,7 @@
127130
(match-content chat-id "assistant" {:type "reasonText" :id (m/pred string?) :text "say hello"})
128131
(match-content chat-id "assistant" {:type "reasonFinished" :id (m/pred string?) :totalTimeMs (m/pred number?)})
129132
(match-content chat-id "assistant" {:type "text" :text "hell"})
133+
(match-content chat-id "system" {:type "usage"})
130134
(match-content chat-id "assistant" {:type "text" :text "o there!"})
131135
(match-content chat-id "system" {:type "progress" :state "finished"})
132136
(is (match?
@@ -157,6 +161,7 @@
157161
(match-content chat-id "assistant" {:type "reasonText" :id (m/pred string?) :text " say fine"})
158162
(match-content chat-id "assistant" {:type "reasonFinished" :id (m/pred string?) :totalTimeMs (m/pred number?)})
159163
(match-content chat-id "assistant" {:type "text" :text "I"})
164+
(match-content chat-id "system" {:type "usage"})
160165
(match-content chat-id "assistant" {:type "text" :text "'m fine"})
161166
(match-content chat-id "system" {:type "progress" :state "finished"})
162167
(is (match?

src/eca/llm_providers/openai_chat.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,6 @@
301301
;; Incremental parser buffer for content to detect thinking tags across chunks
302302
content-buffer* (atom "")
303303
handle-response (fn handle-response [event data tool-calls-atom rid]
304-
(when-let [usage (:usage data)]
305-
(on-usage-updated (let [input-cache-read-tokens (-> usage :prompt_tokens_details :cached_tokens)]
306-
{:input-tokens (if input-cache-read-tokens
307-
(- (:prompt_tokens usage) input-cache-read-tokens)
308-
(:prompt_tokens usage))
309-
:output-tokens (:completion_tokens usage)
310-
:input-cache-read-tokens input-cache-read-tokens})))
311304
(if (= event "stream-end")
312305
(do
313306
;; Flush any leftover buffered content and finish reasoning if needed
@@ -405,7 +398,14 @@
405398
(reset! reasoning-type* nil))
406399
;; Handle regular finish
407400
(when (not= finish-reason "tool_calls")
408-
(on-message-received {:type :finish :finish-reason finish-reason}))))))))
401+
(on-message-received {:type :finish :finish-reason finish-reason})))))))
402+
(when-let [usage (:usage data)]
403+
(on-usage-updated (let [input-cache-read-tokens (-> usage :prompt_tokens_details :cached_tokens)]
404+
{:input-tokens (if input-cache-read-tokens
405+
(- (:prompt_tokens usage) input-cache-read-tokens)
406+
(:prompt_tokens usage))
407+
:output-tokens (:completion_tokens usage)
408+
:input-cache-read-tokens input-cache-read-tokens}))))
409409
rid (llm-util/gen-rid)]
410410
(base-request!
411411
{:rid rid

0 commit comments

Comments
 (0)