diff --git a/src/apps/chat/components/composer/tokens/TokenBadge.tsx b/src/apps/chat/components/composer/tokens/TokenBadge.tsx index 37cf9e01f..f7a2208df 100644 --- a/src/apps/chat/components/composer/tokens/TokenBadge.tsx +++ b/src/apps/chat/components/composer/tokens/TokenBadge.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { Badge } from '@mui/joy'; -import type { DChatGeneratePricing } from '~/common/stores/llms/llms.pricing'; +import type { DPricingChatGenerate } from '~/common/stores/llms/llms.pricing'; import { formatModelsCost } from '~/common/util/costUtils'; import { tokenCountsMathAndMessage, TokenTooltip } from './TokenTooltip'; @@ -14,7 +14,7 @@ import { tokenCountsMathAndMessage, TokenTooltip } from './TokenTooltip'; export const TokenBadgeMemo = React.memo(TokenBadge); function TokenBadge(props: { - chatPricing?: DChatGeneratePricing, + chatPricing?: DPricingChatGenerate, direct: number, history?: number, diff --git a/src/apps/chat/components/composer/tokens/TokenProgressbar.tsx b/src/apps/chat/components/composer/tokens/TokenProgressbar.tsx index 72a93513c..c44de4988 100644 --- a/src/apps/chat/components/composer/tokens/TokenProgressbar.tsx +++ b/src/apps/chat/components/composer/tokens/TokenProgressbar.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { Box, useTheme } from '@mui/joy'; -import type { DChatGeneratePricing } from '~/common/stores/llms/llms.pricing'; +import type { DPricingChatGenerate } from '~/common/stores/llms/llms.pricing'; import { tokenCountsMathAndMessage, TokenTooltip } from './TokenTooltip'; @@ -15,7 +15,7 @@ import { tokenCountsMathAndMessage, TokenTooltip } from './TokenTooltip'; export const TokenProgressbarMemo = React.memo(TokenProgressbar); function TokenProgressbar(props: { - chatPricing?: DChatGeneratePricing, + chatPricing?: DPricingChatGenerate, direct: number, history: number, diff --git a/src/apps/chat/components/composer/tokens/TokenTooltip.tsx b/src/apps/chat/components/composer/tokens/TokenTooltip.tsx index 9a36b17f8..90857671a 100644 --- a/src/apps/chat/components/composer/tokens/TokenTooltip.tsx +++ b/src/apps/chat/components/composer/tokens/TokenTooltip.tsx @@ -3,13 +3,13 @@ import * as React from 'react'; import type { SxProps } from '@mui/joy/styles/types'; import { Box, ColorPaletteProp, Tooltip } from '@mui/joy'; -import { DChatGeneratePricing, getLlmCostForTokens } from '~/common/stores/llms/llms.pricing'; +import { DPricingChatGenerate, getLlmCostForTokens } from '~/common/stores/llms/llms.pricing'; import { adjustContentScaling, themeScalingMap } from '~/common/app.theme'; import { formatModelsCost } from '~/common/util/costUtils'; import { useUIContentScaling } from '~/common/state/store-ui'; -export function tokenCountsMathAndMessage(tokenLimit: number | 0, directTokens: number, historyTokens?: number, responseMaxTokens?: number, chatPricing?: DChatGeneratePricing): { +export function tokenCountsMathAndMessage(tokenLimit: number | 0, directTokens: number, historyTokens?: number, responseMaxTokens?: number, chatPricing?: DPricingChatGenerate): { color: ColorPaletteProp, message: string, remainingTokens: number, diff --git a/src/common/stores/llms/llms.pricing.ts b/src/common/stores/llms/llms.pricing.ts index 8a0a460c7..95b90bb05 100644 --- a/src/common/stores/llms/llms.pricing.ts +++ b/src/common/stores/llms/llms.pricing.ts @@ -6,11 +6,11 @@ import type { DLLM } from './llms.types'; * Pricing is denominated in $/MegaTokens. */ export type DModelPricing = { - chat?: DChatGeneratePricing, + chat?: DPricingChatGenerate, } -// NOTE: (!) keep this in sync with ChatGeneratePricing_schema (modules/llms/server/llm.server.types.ts) -export type DChatGeneratePricing = { +// NOTE: (!) keep this in sync with PricingChatGenerate_schema (modules/llms/server/llm.server.types.ts) +export type DPricingChatGenerate = { // unit: 'USD_Mtok', input?: DTieredPricing; output?: DTieredPricing; @@ -24,7 +24,7 @@ export type DChatGeneratePricing = { read: DTieredPricing; // write: DTieredPricing; // Not needed, as it's automatic }; - // NOT in AixWire_API_ListModels.ChatGeneratePricing_schema + // NOT in AixWire_API_ListModels.PricingChatGenerate_schema _isFree?: boolean; // precomputed, so we avoid recalculating it } @@ -40,7 +40,7 @@ type DPricePerMToken = number | 'free'; /// detect Free Pricing -export function isModelPricingFree(pricingChatGenerate: DChatGeneratePricing): boolean { +export function isModelPricingFree(pricingChatGenerate: DPricingChatGenerate): boolean { if (!pricingChatGenerate) return true; return _isPricingFree(pricingChatGenerate.input) && _isPricingFree(pricingChatGenerate.output); } @@ -89,13 +89,13 @@ export function portModelPricingV2toV3(llm: DLLM): void { const pretendIsV2 = llm.pricing as Was_DModelPricingV2; if (pretendIsV2.chatIn || pretendIsV2.chatOut) { - const V3: DChatGeneratePricing = {}; + const V3pcg: DPricingChatGenerate = {}; if (pretendIsV2.chatIn) - V3.input = pretendIsV2.chatIn; + V3pcg.input = pretendIsV2.chatIn; if (pretendIsV2.chatOut) - V3.output = pretendIsV2.chatOut; - V3._isFree = isModelPricingFree(V3); - llm.pricing = { chat: V3 }; + V3pcg.output = pretendIsV2.chatOut; + V3pcg._isFree = isModelPricingFree(V3pcg); + llm.pricing = { chat: V3pcg }; delete pretendIsV2.chatIn; delete pretendIsV2.chatOut; } diff --git a/src/common/stores/metrics/metrics.chatgenerate.ts b/src/common/stores/metrics/metrics.chatgenerate.ts index 1966e6e49..701809aae 100644 --- a/src/common/stores/metrics/metrics.chatgenerate.ts +++ b/src/common/stores/metrics/metrics.chatgenerate.ts @@ -1,4 +1,4 @@ -import { DChatGeneratePricing, getLlmCostForTokens, isModelPricingFree } from '~/common/stores/llms/llms.pricing'; +import { DPricingChatGenerate, getLlmCostForTokens, isModelPricingFree } from '~/common/stores/llms/llms.pricing'; /** * This is a stored type - IMPORTANT: do not break. @@ -88,7 +88,7 @@ export function finishChatGenerateTokenMetrics(metrics: DChatGenerateMetricsLg | const USD_TO_CENTS = 100; -export function computeChatGenerationCosts(metrics?: Readonly, pricing?: DChatGeneratePricing | undefined, logLlmRefId?: string): ChatGenerateCostMetricsMd | undefined { +export function computeChatGenerationCosts(metrics?: Readonly, pricing?: DPricingChatGenerate | undefined, logLlmRefId?: string): ChatGenerateCostMetricsMd | undefined { if (!metrics) return undefined; diff --git a/src/modules/llms/models-modal/LLMOptionsModal.tsx b/src/modules/llms/models-modal/LLMOptionsModal.tsx index f5411b3ec..4f1ca064b 100644 --- a/src/modules/llms/models-modal/LLMOptionsModal.tsx +++ b/src/modules/llms/models-modal/LLMOptionsModal.tsx @@ -6,7 +6,7 @@ import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline'; import VisibilityIcon from '@mui/icons-material/Visibility'; import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; -import type { DChatGeneratePricing } from '~/common/stores/llms/llms.pricing'; +import type { DPricingChatGenerate } from '~/common/stores/llms/llms.pricing'; import type { DLLMId } from '~/common/stores/llms/llms.types'; import { FormLabelStart } from '~/common/components/forms/FormLabelStart'; import { GoodModal } from '~/common/components/modals/GoodModal'; @@ -31,10 +31,10 @@ function VendorLLMOptionsComponent(props: { llmId: DLLMId }) { } -function prettyPricingComponent(chatPricing: DChatGeneratePricing): React.ReactNode { - if (!chatPricing) return 'Pricing not available'; +function prettyPricingComponent(pricingChatGenerate: DPricingChatGenerate): React.ReactNode { + if (!pricingChatGenerate) return 'Pricing not available'; - const formatPrice = (price: DChatGeneratePricing['input']): string => { + const formatPrice = (price: DPricingChatGenerate['input']): string => { if (!price) return 'N/A'; if (price === 'free') return 'Free'; if (typeof price === 'number') return `$${price.toFixed(2)}`; @@ -43,19 +43,19 @@ function prettyPricingComponent(chatPricing: DChatGeneratePricing): React.ReactN return 'Unknown'; }; - const inputPrice = formatPrice(chatPricing.input); - const outputPrice = formatPrice(chatPricing.output); + const inputPrice = formatPrice(pricingChatGenerate.input); + const outputPrice = formatPrice(pricingChatGenerate.output); let cacheInfo = ''; - if (chatPricing.cache) { - switch (chatPricing.cache.cType) { + if (pricingChatGenerate.cache) { + switch (pricingChatGenerate.cache.cType) { case 'ant-bp': { - const { read, write, duration } = chatPricing.cache; + const { read, write, duration } = pricingChatGenerate.cache; cacheInfo = `Cache: Read ${formatPrice(read)}, Write ${formatPrice(write)}, Duration: ${duration}s`; break; } case 'oai-ac': { - const { read } = chatPricing.cache; + const { read } = pricingChatGenerate.cache; cacheInfo = `Cache: Read ${formatPrice(read)}`; break; } diff --git a/src/modules/llms/server/llm.server.types.ts b/src/modules/llms/server/llm.server.types.ts index 222a3b683..7d567e4c0 100644 --- a/src/modules/llms/server/llm.server.types.ts +++ b/src/modules/llms/server/llm.server.types.ts @@ -54,8 +54,8 @@ const TieredPricing_schema = z.union([ z.array(PriceUpTo_schema), ]); -// NOTE: (!) keep this in sync with DChatGeneratePricing (llms.pricing.ts) -const ChatGeneratePricing_schema = z.object({ +// NOTE: (!) keep this in sync with DPricingChatGenerate (llms.pricing.ts) +const PricingChatGenerate_schema = z.object({ input: TieredPricing_schema.optional(), output: TieredPricing_schema.optional(), // Future: Perplexity has a cost per request, consider this for future additions @@ -92,7 +92,7 @@ export const ModelDescription_schema = z.object({ // rateLimits: rateLimitsSchema.optional(), trainingDataCutoff: z.string().optional(), benchmark: BenchmarksScores_schema.optional(), - chatPrice: ChatGeneratePricing_schema.optional(), + chatPrice: PricingChatGenerate_schema.optional(), hidden: z.boolean().optional(), // TODO: add inputTypes/Kinds.. });