Skip to content

Commit 5329c71

Browse files
Yields the usage tokens
1 parent 4008a1a commit 5329c71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/api/providers/unbound.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,22 @@ export class UnboundHandler implements ApiHandler, SingleCompletionHandler {
9696

9797
for await (const chunk of completion) {
9898
const delta = chunk.choices[0]?.delta
99+
const usage = chunk.usage
99100

100101
if (delta?.content) {
101102
yield {
102103
type: "text",
103104
text: delta.content,
104105
}
105106
}
107+
108+
if (usage) {
109+
yield {
110+
type: "usage",
111+
inputTokens: usage?.prompt_tokens || 0,
112+
outputTokens: usage?.completion_tokens || 0,
113+
}
114+
}
106115
}
107116
}
108117

0 commit comments

Comments
 (0)