|
50 | 50 | (defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model db] |
51 | 51 | (let [normalized-model (if (string/includes? model "/") |
52 | 52 | (last (string/split model #"/")) |
53 | | - model) |
54 | | - {:keys [input-token-cost output-token-cost |
55 | | - input-cache-creation-token-cost input-cache-read-token-cost]} (get-in db [:models normalized-model]) |
56 | | - input-cost (* input-tokens input-token-cost) |
57 | | - input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost) |
58 | | - (+ input-cost (* input-cache-creation-tokens input-cache-creation-token-cost)) |
59 | | - input-cost) |
60 | | - input-cost (if (and input-cache-read-tokens input-cache-read-token-cost) |
61 | | - (+ input-cost (* input-cache-read-tokens input-cache-read-token-cost)) |
62 | | - input-cost)] |
63 | | - (when (and input-token-cost output-token-cost) |
64 | | - (format "%.2f" (+ input-cost |
65 | | - (* output-tokens output-token-cost)))))) |
| 53 | + model)] |
| 54 | + (when-let [{:keys [input-token-cost output-token-cost |
| 55 | + input-cache-creation-token-cost input-cache-read-token-cost]} (get-in db [:models normalized-model])] |
| 56 | + (when (and input-token-cost output-token-cost) |
| 57 | + (let [input-cost (* input-tokens input-token-cost) |
| 58 | + input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost) |
| 59 | + (+ input-cost (* input-cache-creation-tokens input-cache-creation-token-cost)) |
| 60 | + input-cost) |
| 61 | + input-cost (if (and input-cache-read-tokens input-cache-read-token-cost) |
| 62 | + (+ input-cost (* input-cache-read-tokens input-cache-read-token-cost)) |
| 63 | + input-cost)] |
| 64 | + (format "%.2f" (+ input-cost |
| 65 | + (* output-tokens output-token-cost)))))))) |
66 | 66 |
|
67 | 67 | (defn map->camel-cased-map [m] |
68 | 68 | (let [f (fn [[k v]] |
|
0 commit comments