mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
chore: resolve merge conflicts from main
- Resolved conflicts in calculateApiCostOpenAI signature (added reasoningTokens param) - Updated cerebras.ts to use new cost calculation with reasoning tokens - Updated groq.ts to use new cost calculation with reasoning tokens - Updated lite-llm.ts to use new cost calculation with reasoning tokens - Updated openai-native.ts to use new cost calculation with reasoning tokens - All providers now properly handle reasoning token costs
This commit is contained in:
parent
d6e594eeda
commit
427fbec10d
5 changed files with 10 additions and 15 deletions
|
|
@ -331,7 +331,7 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
|
|||
const { info } = this.getModel()
|
||||
// Use actual token usage from the last request
|
||||
const { inputTokens, outputTokens } = this.lastUsage
|
||||
const { totalCost } = calculateApiCostOpenAI(info, inputTokens, outputTokens)
|
||||
const totalCost = calculateApiCostOpenAI(info, inputTokens, outputTokens)
|
||||
return totalCost
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export class GroqHandler extends BaseOpenAiCompatibleProvider<GroqModelId> {
|
|||
const cacheWriteTokens = 0
|
||||
|
||||
// Calculate cost using OpenAI-compatible cost calculation
|
||||
const { totalCost } = calculateApiCostOpenAI(info, inputTokens, outputTokens, cacheWriteTokens, cacheReadTokens)
|
||||
const totalCost = calculateApiCostOpenAI(info, inputTokens, outputTokens, cacheWriteTokens, cacheReadTokens)
|
||||
|
||||
yield {
|
||||
type: "usage",
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ export class LiteLLMHandler extends RouterProvider implements SingleCompletionHa
|
|||
(lastUsage as any).prompt_cache_hit_tokens ||
|
||||
0
|
||||
|
||||
const { totalCost } = calculateApiCostOpenAI(
|
||||
const totalCost = calculateApiCostOpenAI(
|
||||
info,
|
||||
lastUsage.prompt_tokens || 0,
|
||||
lastUsage.completion_tokens || 0,
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
|
|||
|
||||
// Pass total input tokens directly to calculateApiCostOpenAI
|
||||
// The function handles subtracting both cache reads and writes internally
|
||||
const { totalCost } = calculateApiCostOpenAI(
|
||||
const totalCost = calculateApiCostOpenAI(
|
||||
effectiveInfo,
|
||||
totalInputTokens,
|
||||
totalOutputTokens,
|
||||
|
|
|
|||
|
|
@ -12,20 +12,15 @@ function calculateApiCostInternal(
|
|||
outputTokens: number,
|
||||
cacheCreationInputTokens: number,
|
||||
cacheReadInputTokens: number,
|
||||
totalInputTokens: number,
|
||||
totalOutputTokens: number,
|
||||
): ApiCostResult {
|
||||
totalInputTokens: number, // kept for potential future use
|
||||
totalOutputTokens: number, // kept for potential future use
|
||||
): number {
|
||||
const cacheWritesCost = ((modelInfo.cacheWritesPrice || 0) / 1_000_000) * cacheCreationInputTokens
|
||||
const cacheReadsCost = ((modelInfo.cacheReadsPrice || 0) / 1_000_000) * cacheReadInputTokens
|
||||
const baseInputCost = ((modelInfo.inputPrice || 0) / 1_000_000) * inputTokens
|
||||
const outputCost = ((modelInfo.outputPrice || 0) / 1_000_000) * outputTokens
|
||||
const totalCost = cacheWritesCost + cacheReadsCost + baseInputCost + outputCost
|
||||
|
||||
return {
|
||||
totalInputTokens,
|
||||
totalOutputTokens,
|
||||
totalCost,
|
||||
}
|
||||
return totalCost
|
||||
}
|
||||
|
||||
// For Anthropic compliant usage, the input tokens count does NOT include the
|
||||
|
|
@ -36,7 +31,7 @@ export function calculateApiCostAnthropic(
|
|||
outputTokens: number,
|
||||
cacheCreationInputTokens?: number,
|
||||
cacheReadInputTokens?: number,
|
||||
): ApiCostResult {
|
||||
): number {
|
||||
const cacheCreation = cacheCreationInputTokens || 0
|
||||
const cacheRead = cacheReadInputTokens || 0
|
||||
|
||||
|
|
@ -62,7 +57,7 @@ export function calculateApiCostOpenAI(
|
|||
outputTokens: number,
|
||||
cacheCreationInputTokens?: number,
|
||||
cacheReadInputTokens?: number,
|
||||
): ApiCostResult {
|
||||
): number {
|
||||
const cacheCreationInputTokensNum = cacheCreationInputTokens || 0
|
||||
const cacheReadInputTokensNum = cacheReadInputTokens || 0
|
||||
const nonCachedInputTokens = Math.max(0, inputTokens - cacheCreationInputTokensNum - cacheReadInputTokensNum)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue