Skip to content

Commit

Permalink
chore: 🤖 use getUsageCost
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpetrov committed Dec 8, 2023
1 parent 8bb36b4 commit a2302f5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/lib/chatv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ChatModelConfigSchema, ChatResponse } from './types/dtos';
import ChatModel from './chat-model';
import { ModelConfig } from './config';
import formatMessagesOpenAI from './format-messages-openai';
import getUsageCost from './get-usage-cost';
import truncateChatMessages from './truncateChatMessages';

export type ChatProps = ChatModelConfigSchema & {
Expand Down Expand Up @@ -76,11 +77,10 @@ const chat = async ({
completionTokens: output?.usage?.completion_tokens,
promptTokens: output?.usage?.prompt_tokens,
totalTokens: output?.usage?.total_tokens,
cost:
(output?.usage?.prompt_tokens || 0) *
ModelConfig[modelName]?.providerPriceByInputToken +
(output?.usage?.completion_tokens || 0) *
ModelConfig[modelName]?.providerPricePriceByOutputToken,
cost: getUsageCost({
modelName,
usage: output?.usage!,
}),
};

return {
Expand Down

1 comment on commit a2302f5

@vercel
Copy link

@vercel vercel bot commented on a2302f5 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.