This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "../test/testHarness";
|
||||
|
||||
import {
|
||||
millsPerThousandTokensToCreditsPerMillion,
|
||||
modelPriceToTextTokenCreditRate,
|
||||
resolveTextTokenCreditRate,
|
||||
} from "./modelPricing";
|
||||
|
||||
describe("modelPricing", () => {
|
||||
it("converts backend mills per thousand tokens to credits per million tokens", () => {
|
||||
expect(millsPerThousandTokensToCreditsPerMillion(27)).toBe(2_700);
|
||||
expect(millsPerThousandTokensToCreditsPerMillion(108)).toBe(10_800);
|
||||
});
|
||||
|
||||
it("converts a token model price row to a text token credit rate", () => {
|
||||
expect(
|
||||
modelPriceToTextTokenCreditRate({
|
||||
modelKey: "gpt-4o",
|
||||
inputPriceMills: 27,
|
||||
outputPriceMills: 108,
|
||||
flatPriceMills: null,
|
||||
currency: "CNY",
|
||||
enabled: true,
|
||||
}),
|
||||
).toEqual({
|
||||
inputCreditsPerMillion: 2_700,
|
||||
outputCreditsPerMillion: 10_800,
|
||||
source: "server",
|
||||
modelKey: "gpt-4o",
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves token pricing by exact or fuzzy model key without accepting flat prices", () => {
|
||||
const prices = [
|
||||
{
|
||||
modelKey: "gemini-3-pro-image",
|
||||
inputPriceMills: null,
|
||||
outputPriceMills: null,
|
||||
flatPriceMills: 200,
|
||||
currency: "CNY",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
modelKey: "gemini-3.1-pro",
|
||||
inputPriceMills: 12,
|
||||
outputPriceMills: 48,
|
||||
flatPriceMills: null,
|
||||
currency: "CNY",
|
||||
enabled: true,
|
||||
},
|
||||
];
|
||||
|
||||
expect(resolveTextTokenCreditRate(prices, "gemini")).toEqual({
|
||||
inputCreditsPerMillion: 1_200,
|
||||
outputCreditsPerMillion: 4_800,
|
||||
source: "server",
|
||||
modelKey: "gemini-3.1-pro",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user