From 5329c712de34a07d541a02dc91ab00a55afb785e Mon Sep 17 00:00:00 2001 From: Vignesh Subbiah Date: Tue, 28 Jan 2025 21:11:16 +0530 Subject: [PATCH] Yields the usage tokens --- src/api/providers/unbound.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/providers/unbound.ts b/src/api/providers/unbound.ts index 1992d71..23e419c 100644 --- a/src/api/providers/unbound.ts +++ b/src/api/providers/unbound.ts @@ -96,6 +96,7 @@ export class UnboundHandler implements ApiHandler, SingleCompletionHandler { for await (const chunk of completion) { const delta = chunk.choices[0]?.delta + const usage = chunk.usage if (delta?.content) { yield { @@ -103,6 +104,14 @@ export class UnboundHandler implements ApiHandler, SingleCompletionHandler { text: delta.content, } } + + if (usage) { + yield { + type: "usage", + inputTokens: usage?.prompt_tokens || 0, + outputTokens: usage?.completion_tokens || 0, + } + } } }