refactor(translator): P4 concern #5 buildUsage — apply to kiro/ollama/commandcode
- Replace 3 inline {prompt,completion,total} usage objects with buildUsage()
- Preserves ?? vs total fallback semantics (commandcode)
- Golden tests pass, identical output
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { register } from "../index.js";
|
||||
import { FORMATS } from "../formats.js";
|
||||
import { buildChunk } from "../helpers/chunkBuilder.js";
|
||||
import { buildUsage } from "../helpers/usageHelper.js";
|
||||
import { fallbackToolCallId } from "../helpers/toolCallHelper.js";
|
||||
|
||||
/**
|
||||
@@ -79,11 +80,8 @@ export function ollamaToOpenAI(chunk, state) {
|
||||
* Extract usage stats from Ollama response
|
||||
*/
|
||||
function extractUsage(ollamaChunk) {
|
||||
return {
|
||||
prompt_tokens: ollamaChunk.prompt_eval_count || 0,
|
||||
completion_tokens: ollamaChunk.eval_count || 0,
|
||||
total_tokens: (ollamaChunk.prompt_eval_count || 0) + (ollamaChunk.eval_count || 0)
|
||||
};
|
||||
const inTok = ollamaChunk.prompt_eval_count || 0, outTok = ollamaChunk.eval_count || 0;
|
||||
return buildUsage({ promptTokens: inTok, completionTokens: outTok, totalTokens: inTok + outTok });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user