import * as React from "react"; import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell, } from "@/components/ui/table"; import { MultiSelect } from "@/components/ui/multi-select"; import { FlattenedModel, Provider } from "@/App"; interface PricingTableProps { data: FlattenedModel[]; providers: Provider[]; selectedProviders: string[]; selectedModels: string[]; onProviderChange: (values: string[]) => void; onModelChange: (values: string[]) => void; comparisonModels: string[]; inputTokens: number; outputTokens: number; tokenCalculation: string; requestSort: (key: keyof FlattenedModel) => void; sortConfig: { key: keyof FlattenedModel; direction: string; } | null; linkProviderModel: boolean; } export const PricingTable: React.FC = ({ data, providers, selectedProviders, selectedModels, onProviderChange, onModelChange, comparisonModels, inputTokens, outputTokens, tokenCalculation, requestSort, sortConfig, linkProviderModel, }) => { const calculatePrice = (price: number, tokens: number): number => { let multiplier = 1; if (tokenCalculation === "thousand") multiplier = 1e-3; else if (tokenCalculation === "unit") multiplier = 1e-6; else if (tokenCalculation === "billion") multiplier = 1e3; return price * tokens * multiplier; }; const calculateComparison = (modelPrice: number, comparisonPrice: number): string => { if (comparisonPrice === 0) return "∞"; return (((modelPrice - comparisonPrice) / comparisonPrice) * 100).toFixed(2); }; const getModelsForSelectedProviders = () => { const flatModels = providers.flatMap((provider) => provider.models.map((model) => ({ label: model.name, value: model.name, provider: provider.provider, })) ); const filtered = linkProviderModel ? flatModels.filter((m) => selectedProviders.includes(m.provider)) : flatModels; // Remove duplicates return Array.from(new Map(filtered.map((m) => [m.value, m])).values()); }; return ( Total Price (per {tokenCalculation} tokens) {comparisonModels.map((model) => ( Compared to {model} ))} ({ label: p.provider, value: p.provider }))} defaultValue={selectedProviders} onValueChange={onProviderChange} /> {comparisonModels.flatMap((model) => [ Input, Output, ])} {data.map((item) => ( {item.provider} {item.name} {item.inputPrice.toFixed(2)} {item.outputPrice.toFixed(2)} ${( calculatePrice(item.inputPrice, inputTokens) + calculatePrice(item.outputPrice, outputTokens) ).toFixed(2)} {comparisonModels.flatMap((model) => { const [comparisonProvider, comparisonModelName] = model.split(":"); const comparisonModel = providers .find((p) => p.provider === comparisonProvider) ?.models.find((m) => m.name === comparisonModelName); if (!comparisonModel) return [, ]; const inputDelta = calculateComparison(item.inputPrice, comparisonModel.inputPrice); const outputDelta = calculateComparison(item.outputPrice, comparisonModel.outputPrice); return [ 0 ? "bg-red-100" : ""}> {`${item.provider}:${item.name}` === model ? "0.00%" : `${inputDelta}%`} , 0 ? "bg-red-100" : ""}> {`${item.provider}:${item.name}` === model ? "0.00%" : `${outputDelta}%`} , ]; })} ))}
); };