Spaces:
Sleeping
Sleeping
File size: 908 Bytes
4c2a557 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | interface ModelInletCost {
[key: string]: number;
}
function parseInletCostConfig(config: string | undefined): ModelInletCost {
if (!config) return {};
const numericValue = Number(config);
if (!isNaN(numericValue)) {
return { default: numericValue };
}
try {
const costs: ModelInletCost = {};
config.split(",").forEach((pair) => {
const [model, cost] = pair.trim().split(":");
const costValue = Number(cost);
if (!isNaN(costValue)) {
costs[model.trim()] = costValue;
}
});
return costs;
} catch (error) {
console.error("Error parsing COST_ON_INLET config:", error);
return {};
}
}
export function getModelInletCost(modelId: string): number {
if (!process.env.COST_ON_INLET) {
return 0;
}
const costConfig = parseInletCostConfig(process.env.COST_ON_INLET);
return costConfig[modelId] ?? costConfig["default"] ?? 0;
}
|