fix: money incorrectly formatted for some models
This commit is contained in:
@@ -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': {
|
||||
|
||||
Reference in New Issue
Block a user