Skip to content

Commit 4cb3316

Browse files
committed
Fix openai: transition functions should always return state
1 parent 884cfd4 commit 4cb3316

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/simulflow/processors/openai.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@
138138
::flow/out-ports {::llm-write llm-write}})))
139139

140140
(defn transition
141-
[{::flow/keys [in-ports out-ports]} transition]
141+
[{::flow/keys [in-ports out-ports] :as state} transition]
142142
(when (= transition ::flow/stop)
143143
(doseq [port (concat (vals in-ports) (vals out-ports))]
144-
(a/close! port))))
144+
(a/close! port)))
145+
state)
145146

146147
(defn transform-handle-llm-response
147148
"Handle the streaming response from the LLM. Return appropriate frames based on

test/simulflow/processors/openai_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@
236236
;; This test would need mock channels to verify closure
237237
;; For now, just test that the function exists and doesn't throw
238238
(let [mock-state {:clojure.core.async.flow/in-ports {} :clojure.core.async.flow/out-ports {}}]
239-
(is (nil? (openai/transition mock-state :clojure.core.async.flow/stop)))))
239+
(is (= (openai/transition mock-state :clojure.core.async.flow/stop) mock-state))))
240240

241241
(testing "ignores non-stop transitions"
242242
(let [mock-state {:clojure.core.async.flow/in-ports {} :clojure.core.async.flow/out-ports {}}]
243-
(is (nil? (openai/transition mock-state :clojure.core.async.flow/start))))))
243+
(is (= (openai/transition mock-state :clojure.core.async.flow/start) mock-state)))))
244244

245245
(deftest openai-multi-arity-fn-test
246246
(testing "0-arity returns describe"
@@ -251,7 +251,7 @@
251251

252252
(testing "2-arity delegates to transition"
253253
(let [mock-state {:clojure.core.async.flow/in-ports {} :clojure.core.async.flow/out-ports {}}]
254-
(is (nil? (openai/openai-llm-fn mock-state :clojure.core.async.flow/stop)))))
254+
(is (= mock-state (openai/openai-llm-fn mock-state :clojure.core.async.flow/stop)))))
255255

256256
(testing "3-arity delegates to transform"
257257
(let [context-frame (frame/llm-context {:messages [{:role :system :content "You are helpful"}] :tools []})

0 commit comments

Comments
 (0)