fix(ai): normalize generated model costs (#5634)
This commit is contained in:
@@ -372,6 +372,10 @@ function normalizeNvidiaModelId(modelId: string): string {
|
|||||||
return modelId.toLowerCase().replaceAll("_", ".");
|
return modelId.toLowerCase().replaceAll("_", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function roundCost(value: number): number {
|
||||||
|
return Number(value.toFixed(6));
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchNvidiaNimModelIds(): Promise<Map<string, string>> {
|
async function fetchNvidiaNimModelIds(): Promise<Map<string, string>> {
|
||||||
try {
|
try {
|
||||||
console.log("Fetching models from NVIDIA NIM API...");
|
console.log("Fetching models from NVIDIA NIM API...");
|
||||||
@@ -417,10 +421,10 @@ async function fetchOpenRouterModels(): Promise<Model<any>[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert pricing from $/token to $/million tokens
|
// Convert pricing from $/token to $/million tokens
|
||||||
const inputCost = parseFloat(model.pricing?.prompt || "0") * 1_000_000;
|
const inputCost = roundCost(parseFloat(model.pricing?.prompt || "0") * 1_000_000);
|
||||||
const outputCost = parseFloat(model.pricing?.completion || "0") * 1_000_000;
|
const outputCost = roundCost(parseFloat(model.pricing?.completion || "0") * 1_000_000);
|
||||||
const cacheReadCost = parseFloat(model.pricing?.input_cache_read || "0") * 1_000_000;
|
const cacheReadCost = roundCost(parseFloat(model.pricing?.input_cache_read || "0") * 1_000_000);
|
||||||
const cacheWriteCost = parseFloat(model.pricing?.input_cache_write || "0") * 1_000_000;
|
const cacheWriteCost = roundCost(parseFloat(model.pricing?.input_cache_write || "0") * 1_000_000);
|
||||||
|
|
||||||
const normalizedModel: Model<any> = {
|
const normalizedModel: Model<any> = {
|
||||||
id: modelKey,
|
id: modelKey,
|
||||||
@@ -476,10 +480,10 @@ async function fetchAiGatewayModels(): Promise<Model<any>[]> {
|
|||||||
input.push("image");
|
input.push("image");
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputCost = toNumber(model.pricing?.input) * 1_000_000;
|
const inputCost = roundCost(toNumber(model.pricing?.input) * 1_000_000);
|
||||||
const outputCost = toNumber(model.pricing?.output) * 1_000_000;
|
const outputCost = roundCost(toNumber(model.pricing?.output) * 1_000_000);
|
||||||
const cacheReadCost = toNumber(model.pricing?.input_cache_read) * 1_000_000;
|
const cacheReadCost = roundCost(toNumber(model.pricing?.input_cache_read) * 1_000_000);
|
||||||
const cacheWriteCost = toNumber(model.pricing?.input_cache_write) * 1_000_000;
|
const cacheWriteCost = roundCost(toNumber(model.pricing?.input_cache_write) * 1_000_000);
|
||||||
|
|
||||||
models.push({
|
models.push({
|
||||||
id: model.id,
|
id: model.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user