TokenUsage
The tokens a call to a ChatModel read (inputTokens) and wrote (outputTokens), or those of several calls added up. TokenUsage() is no tokens, the start of a count:
data class Order(val messages: List<ChatMessage>, val tokens: TokenUsage = TokenUsage())
node("summarize", work = { order -> model.chat(ChatRequest(order.messages)) }) { order, response ->
order.copy(messages = order.messages + response.message, tokens = order.tokens + response.usage)
}Content copied to clipboard
It is @Serializable, so a state that holds one can be saved by a checkpointer that uses kotlinx.serialization.
Functions
Link copied to clipboard
Returns these tokens and those of other added up. A call whose provider reports no usage has null, which adds nothing.