mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
Handle Roo provider pricing correctly (#8802)
This commit is contained in:
parent
485b551cf3
commit
1a9e7ca233
2 changed files with 17 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { RooModelsResponseSchema } from "@roo-code/types"
|
||||
|
||||
import type { ModelRecord } from "../../../shared/api"
|
||||
import { parseApiPrice } from "../../../shared/cost"
|
||||
|
||||
import { DEFAULT_HEADERS } from "../constants"
|
||||
|
||||
|
|
@ -71,10 +72,10 @@ export async function getRooModels(baseUrl: string, apiKey?: string): Promise<Mo
|
|||
const supportsImages = tags.includes("vision")
|
||||
|
||||
// Parse pricing (API returns strings, convert to numbers)
|
||||
const inputPrice = parseFloat(pricing.input)
|
||||
const outputPrice = parseFloat(pricing.output)
|
||||
const cacheReadPrice = pricing.input_cache_read ? parseFloat(pricing.input_cache_read) : undefined
|
||||
const cacheWritePrice = pricing.input_cache_write ? parseFloat(pricing.input_cache_write) : undefined
|
||||
const inputPrice = parseApiPrice(pricing.input)
|
||||
const outputPrice = parseApiPrice(pricing.output)
|
||||
const cacheReadPrice = pricing.input_cache_read ? parseApiPrice(pricing.input_cache_read) : undefined
|
||||
const cacheWritePrice = pricing.input_cache_write ? parseApiPrice(pricing.input_cache_write) : undefined
|
||||
|
||||
models[modelId] = {
|
||||
maxTokens,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ import { DEFAULT_HEADERS } from "./constants"
|
|||
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
|
||||
import { getModels, flushModels, getModelsFromCache } from "../providers/fetchers/modelCache"
|
||||
|
||||
// Extend OpenAI's CompletionUsage to include Roo specific fields
|
||||
interface RooUsage extends OpenAI.CompletionUsage {
|
||||
cache_creation_input_tokens?: number
|
||||
cost?: number
|
||||
}
|
||||
|
||||
export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
|
||||
private authStateListener?: (state: { state: AuthState }) => void
|
||||
private fetcherBaseURL: string
|
||||
|
|
@ -124,10 +130,14 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
}
|
||||
|
||||
if (chunk.usage) {
|
||||
const usage = chunk.usage as RooUsage
|
||||
yield {
|
||||
type: "usage",
|
||||
inputTokens: chunk.usage.prompt_tokens || 0,
|
||||
outputTokens: chunk.usage.completion_tokens || 0,
|
||||
inputTokens: usage.prompt_tokens || 0,
|
||||
outputTokens: usage.completion_tokens || 0,
|
||||
cacheWriteTokens: usage.cache_creation_input_tokens,
|
||||
cacheReadTokens: usage.prompt_tokens_details?.cached_tokens,
|
||||
totalCost: usage.cost ?? 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue