fix: money incorrectly formatted for some models

This commit is contained in:
Zoe
2026-03-03 10:24:00 -06:00
parent 1d83b40fe0
commit 9b1bfcbca9
@@ -221,10 +221,10 @@ const getModelData = (modelId: string, providerId: string, modelsDevData: any) =
for (const key in modelData.cost) {
switch (key) {
case 'input': {
cost.prompt = modelData.cost[key].toString();
cost.prompt = formatMoney(modelData.cost[key].toString());
} break;
case 'output': {
cost.completion = modelData.cost[key].toString();
cost.completion = formatMoney(modelData.cost[key].toString());
} break;
}
}
@@ -305,6 +305,21 @@ const lshDecimal = (number: string, shift: number) => {
return value;
}
const formatMoney = (value: string) => {
// ensure that there are two decimal places MINIMUM I WILL STRANGLE YOU SO HELP ME GOD
const [integerPart, fractionalPart] = value.split('.');
if (fractionalPart === undefined) {
return `${integerPart}.00`;
}
if (fractionalPart.length === 1) {
return `${integerPart}.${fractionalPart}0`;
}
return `${integerPart}.${fractionalPart}`;
}
const normalizeResponse = async (response: Record<string, any>, provider: typeof Providers[number], baseUrl: string, modelsDevData: any) => {
switch (provider) {
case 'cerebras': {