|
| 1 | +(ns eca.llm-util-test |
| 2 | + (:require |
| 3 | + [clojure.java.io :as io] |
| 4 | + [clojure.test :refer [deftest is testing]] |
| 5 | + [eca.llm-util :as llm-util] |
| 6 | + [matcher-combinators.test :refer [match?]]) |
| 7 | + (:import |
| 8 | + [java.io ByteArrayInputStream])) |
| 9 | + |
| 10 | +(deftest event-data-seq-test |
| 11 | + (testing "when there is a event line and another data line" |
| 12 | + (with-open [r (io/reader (ByteArrayInputStream. (.getBytes (str "event: foo.bar\n" |
| 13 | + "data: {\"type\": \"foo.bar\"}\n" |
| 14 | + "\n" |
| 15 | + "event: foo.baz\n" |
| 16 | + "data: {\"type\": \"foo.baz\"}"))))] |
| 17 | + (is (match? |
| 18 | + [["foo.bar" {:type "foo.bar"}] |
| 19 | + ["foo.baz" {:type "foo.baz"}]] |
| 20 | + (llm-util/event-data-seq r))))) |
| 21 | + (testing "when there is no event line, only a data line" |
| 22 | + (with-open [r (io/reader (ByteArrayInputStream. (.getBytes (str "data: {\"type\": \"foo.bar\"}\n" |
| 23 | + "\n" |
| 24 | + "data: {\"type\": \"foo.baz\"}"))))] |
| 25 | + (is (match? |
| 26 | + [["foo.bar" {:type "foo.bar"}] |
| 27 | + ["foo.baz" {:type "foo.baz"}]] |
| 28 | + (llm-util/event-data-seq r))))) |
| 29 | + (testing "Ignore [DONE] when exists" |
| 30 | + (with-open [r (io/reader (ByteArrayInputStream. (.getBytes (str "data: {\"type\": \"foo.bar\"}\n" |
| 31 | + "\n" |
| 32 | + "data: {\"type\": \"foo.baz\"}\n" |
| 33 | + "\n" |
| 34 | + "data: [DONE]\n"))))] |
| 35 | + (is (match? |
| 36 | + [["foo.bar" {:type "foo.bar"}] |
| 37 | + ["foo.baz" {:type "foo.baz"}]] |
| 38 | + (llm-util/event-data-seq r)))))) |
0 commit comments