UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

19 lines (14 loc) 533 B
import type { ModelUsage } from '@lobechat/types'; import type { Pricing } from 'model-bank'; import { computeChatCost } from './computeChatCost'; import type { ComputeChatCostOptions } from './computeChatCost'; export const withUsageCost = ( usage: ModelUsage, pricing?: Pricing, options?: ComputeChatCostOptions, ): ModelUsage => { if (!pricing) return usage; const pricingResult = computeChatCost(pricing, usage, options); if (!pricingResult) return usage; return { ...usage, cost: pricingResult.totalCost }; };