fix(site/src/modules/aiModels): show exact token counts below 1K in formatContextLimit
This commit is contained in:
1 parent
4e172ab5ff
commit
d5888ce15d
2 files changed
+23
-4
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatContextLimit } from "./ModelSelector";
|
||||
|
||||
describe("formatContextLimit", () => {
|
||||
it.each([
|
||||
{ tokens: 800, expected: "800" },
|
||||
{ tokens: 999.6, expected: "1K" },
|
||||
{ tokens: 128_000, expected: "128K" },
|
||||
{ tokens: 999_999, expected: "1.0M" },
|
||||
{ tokens: 1_000_000, expected: "1M" },
|
||||
{ tokens: 1_500_000, expected: "1.5M" },
|
||||
])("formats $tokens tokens as $expected", ({ tokens, expected }) => {
|
||||
expect(formatContextLimit(tokens)).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -71,12 +71,16 @@ type ModelSelectorProps = {
|
||||
};
|
||||
|
||||
export const formatContextLimit = (tokens: number): string => {
|
||||
if (tokens >= 1_000_000) {
|
||||
const m = tokens / 1_000_000;
|
||||
return `${Number.isInteger(m) ? m : m.toFixed(1)}M`;
|
||||
const roundedTokens = Math.round(tokens);
|
||||
if (roundedTokens < 1_000) {
|
||||
return `${roundedTokens}`;
|
||||
}
|
||||
const k = Math.round(tokens / 1_000);
|
||||
return `${k}K`;
|
||||
if (k < 1_000) {
|
||||
return `${k}K`;
|
||||
}
|
||||
const m = tokens / 1_000_000;
|
||||
return `${Number.isInteger(m) ? m : m.toFixed(1)}M`;
|
||||
};
|
||||
|
||||
const getProviderLabel = (
|
||||
|
||||
Reference in new issue
Block a user