File tree Expand file tree Collapse file tree 6 files changed +30
-7
lines changed
Expand file tree Collapse file tree 6 files changed +30
-7
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Fix session-tokens in usage notifications.
6+ - Support context limit on usage notifications.
7+
58## 0.38.3
69
710- Fix anthropic token renew.
Original file line number Diff line number Diff line change @@ -543,6 +543,20 @@ interface UsageContent {
543543 * The cost of the whole chat session so far.
544544 */
545545 sessionCost? : string ;
546+
547+ /**
548+ * Informations about limits.
549+ */
550+ limit: {
551+ /**
552+ * The context limit for this chat.
553+ */
554+ context: number ;
555+ /**
556+ * The output limit for this chat.
557+ */
558+ output: number ;
559+ }
546560}
547561
548562/**
Original file line number Diff line number Diff line change 6868 total-input-tokens (get-in db [:chats chat-id :total-input-tokens ] 0 )
6969 total-input-cache-creation-tokens (get-in db [:chats chat-id :total-input-cache-creation-tokens ] nil )
7070 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-creation-tokens 0 )
72- total-output-tokens (get-in db [:chats chat-id :total-output-tokens ] 0 )]
71+ total-input-cache-tokens (+ (or total-input-cache-creation-tokens 0 )
72+ (or total-input-cache-read-tokens 0 ))
73+ total-output-tokens (get-in db [:chats chat-id :total-output-tokens ] 0 )
74+ model-capabilities (get-in db [:models full-model])]
7375 (assoc-some {:message-output-tokens output-tokens
7476 :message-input-tokens (+ input-tokens message-input-cache-tokens)
7577 :session-tokens (+ total-input-tokens total-input-cache-tokens total-output-tokens)}
76- :message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full-model db)
77- :session-cost (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens full-model db)))))
78+ :limit (:limit model-capabilities)
79+ :message-cost (shared/tokens->cost input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities)
80+ :session-cost (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens model-capabilities)))))
7881
7982(defn ^:private tokenize-args [^String s]
8083 (if (string/blank? s)
Original file line number Diff line number Diff line change 183183 total-input-cache-creation-tokens (get-in db [:chats chat-id :total-input-cache-creation-tokens ] nil )
184184 total-input-cache-read-tokens (get-in db [:chats chat-id :total-input-cache-read-tokens ] nil )
185185 total-output-tokens (get-in db [:chats chat-id :total-output-tokens ] 0 )
186+ model-capabilities (get-in db [:models full-model])
186187 text (multi-str (str " Total input tokens: " total-input-tokens)
187188 (when total-input-cache-creation-tokens
188189 (str " Total input cache creation tokens: " total-input-cache-creation-tokens))
189190 (when total-input-cache-read-tokens
190191 (str " Total input cache read tokens: " total-input-cache-read-tokens))
191192 (str " Total output tokens: " total-output-tokens)
192- (str " Total cost: $" (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens full- model db )))]
193+ (str " Total cost: $" (shared/tokens->cost total-input-tokens total-input-cache-creation-tokens total-input-cache-read-tokens total-output-tokens model-capabilities )))]
193194 {:type :chat-messages
194195 :chats {chat-id [{:role " system" :content [{:type :text :text text}]}]}})
195196 " config" {:type :chat-messages
Original file line number Diff line number Diff line change 4747 :web-search (contains? models-with-web-search-support (name model))
4848 :tools (get model-config " tool_call" )
4949 :max-output-tokens (get-in model-config [" limit" " output" ])}
50+ :limit {:context (get-in model-config [" limit" " context" ])
51+ :output (get-in model-config [" limit" " output" ])}
5052 :input-token-cost (some-> (get-in model-config [" cost" " input" ]) float (/ one-million))
5153 :output-token-cost (some-> (get-in model-config [" cost" " output" ]) float (/ one-million))
5254 :input-cache-creation-token-cost (some-> (get-in model-config [" cost" " cache_write" ]) float (/ one-million))
Original file line number Diff line number Diff line change 7373
7474(defn multi-str [& strings] (string/join " \n " (remove nil? strings)))
7575
76- (defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full- model db ]
76+ (defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens model-capabilities ]
7777 (when-let [{:keys [input-token-cost output-token-cost
78- input-cache-creation-token-cost input-cache-read-token-cost]} ( get-in db [ :models full- model]) ]
78+ input-cache-creation-token-cost input-cache-read-token-cost]} model-capabilities ]
7979 (when (and input-token-cost output-token-cost)
8080 (let [input-cost (* input-tokens input-token-cost)
8181 input-cost (if (and input-cache-creation-tokens input-cache-creation-token-cost)
You can’t perform that action at this time.
0 commit comments