Skip to content

Commit

Permalink
Save input/output tokens in AiLLM
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Dec 25, 2024
1 parent 5b8bd1d commit 21a8f80
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/llm/services/ai-llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ export abstract class AiLLM<Provider extends ProviderV1> extends BaseLLM {
const finishTime = Date.now();
const llmCall: LlmCall = await llmCallSave;

// TODO calculate costs from response tokens
result.usage.totalTokens;
result.usage.promptTokens;
result.usage.completionTokens;
const inputCost = this.calculateInputCost(prompt);
const outputCost = this.calculateOutputCost(responseText);
const cost = inputCost + outputCost;
Expand All @@ -104,6 +100,8 @@ export abstract class AiLLM<Provider extends ProviderV1> extends BaseLLM {
llmCall.timeToFirstToken = null; // Not available in this implementation
llmCall.totalTime = finishTime - requestTime;
llmCall.cost = cost;
llmCall.inputTokens = result.usage.promptTokens;
llmCall.outputTokens = result.usage.completionTokens;
addCost(cost);

span.setAttributes({
Expand Down

0 comments on commit 21a8f80

Please sign in to comment.