|
52 | 52 | (:origin (first (filter #(= name (:name %)) all-tools)))) |
53 | 53 |
|
54 | 54 | (defn ^:private usage-msg->usage |
| 55 | + "How this works: |
| 56 | + - tokens: the last message from API already contain the total |
| 57 | + tokens considered, but we save them for cost calculation |
| 58 | + - cost: we count the tokens in past requests done + current one" |
55 | 59 | [{:keys [input-tokens output-tokens |
56 | 60 | input-cache-creation-tokens input-cache-read-tokens]} |
57 | 61 | full-model |
|
64 | 68 | (when input-cache-read-tokens |
65 | 69 | (swap! db* update-in [:chats chat-id :total-input-cache-read-tokens] (fnil + 0) input-cache-read-tokens)) |
66 | 70 | (let [db @db* |
67 | | - message-input-cache-tokens (or input-cache-creation-tokens 0) |
68 | 71 | total-input-tokens (get-in db [:chats chat-id :total-input-tokens] 0) |
69 | 72 | total-input-cache-creation-tokens (get-in db [:chats chat-id :total-input-cache-creation-tokens] nil) |
70 | 73 | total-input-cache-read-tokens (get-in db [:chats chat-id :total-input-cache-read-tokens] nil) |
71 | | - total-input-cache-tokens (or total-input-cache-read-tokens 0) |
72 | 74 | total-output-tokens (get-in db [:chats chat-id :total-output-tokens] 0) |
73 | 75 | model-capabilities (get-in db [:models full-model])] |
74 | | - (assoc-some {:message-output-tokens output-tokens |
75 | | - :message-input-tokens (+ input-tokens message-input-cache-tokens) |
76 | | - :session-tokens (+ total-input-tokens total-input-cache-tokens total-output-tokens)} |
| 76 | + (assoc-some {:session-tokens (+ input-tokens |
| 77 | + (or input-cache-read-tokens 0) |
| 78 | + (or input-cache-creation-tokens 0) |
| 79 | + output-tokens)} |
77 | 80 | :limit (:limit model-capabilities) |
78 | | - :message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities) |
| 81 | + :last-message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities) |
79 | 82 | :session-cost (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens model-capabilities))))) |
80 | 83 |
|
81 | 84 | (defn ^:private tokenize-args [^String s] |
|
0 commit comments