Requesty: Only report final usage (#3542)

This commit is contained in:
Daniel Trugman 2025-05-13 12:24:28 +01:00 committed by GitHub
parent f6cae4df05
commit a14b655590
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"roo-cline": patch
---
Requesty: Fix token usage counts

View file

@ -101,6 +101,8 @@ export class RequestyHandler extends BaseProvider implements SingleCompletionHan
const stream = await this.client.chat.completions.create(completionParams)
let lastUsage: any = undefined
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta
if (delta?.content) {
@ -118,9 +120,13 @@ export class RequestyHandler extends BaseProvider implements SingleCompletionHan
}
if (chunk.usage) {
yield this.processUsageMetrics(chunk.usage, model.info)
lastUsage = chunk.usage
}
}
if (lastUsage) {
yield this.processUsageMetrics(lastUsage, model.info)
}
}
async completePrompt(prompt: string): Promise<string> {