Skip to content

Commit 6f3514d

Browse files
committed
test
1 parent 97ac621 commit 6f3514d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/eca/shared_test.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,24 @@
3030
(testing "throws on uneven kvs"
3131
(is (thrown? IllegalArgumentException
3232
(shared/assoc-some {} :a 1 :b)))))
33+
34+
(deftest tokens->cost-test
35+
(let [db {:models {"my-model" {:input-token-cost 0.01
36+
:output-token-cost 0.02
37+
:input-cache-creation-token-cost 0.005
38+
:input-cache-read-token-cost 0.001}}}]
39+
(testing "basic input/output cost"
40+
(is (= "0.70" (shared/tokens->cost 30 nil nil 20 "my-model" db))))
41+
(testing "with cache creation tokens"
42+
(is (= "0.75" (shared/tokens->cost 30 10 nil 20 "my-model" db))))
43+
(testing "with cache read tokens"
44+
(is (= "0.73" (shared/tokens->cost 30 nil 30 20 "my-model" db))))
45+
(testing "with both cache creation and read tokens"
46+
(is (= "0.78" (shared/tokens->cost 30 10 30 20 "my-model" db))))
47+
(testing "accepts provider-prefixed model names"
48+
(is (= "0.70" (shared/tokens->cost 30 nil nil 20 "provider/my-model" db))))
49+
(testing "returns nil when model is missing from db"
50+
(is (nil? (shared/tokens->cost 30 nil nil 20 "unknown" db))))
51+
(testing "returns nil when mandatory costs are missing"
52+
(is (nil? (shared/tokens->cost 30 nil nil 20 "my-model-missing"
53+
{:models {"my-model-missing" {:input-token-cost 0.01}}}))))))

0 commit comments

Comments
 (0)