Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scripts/gen-models-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ type Row = {
recommendation_bucket: string | null;
};

const PAGE_SIZE = 10_000;

async function main() {
const url = new URL(`${SUPABASE_URL}/rest/v1/ai_models`);
url.searchParams.set('select', SELECT);
url.searchParams.set('is_hidden', 'eq.false');
url.searchParams.set('is_available', 'eq.true');
url.searchParams.set('order', 'provider.asc,name.asc');
url.searchParams.set('limit', String(PAGE_SIZE));

const res = await fetch(url, {
headers: {
Expand All @@ -76,10 +79,17 @@ async function main() {

const rows = (await res.json()) as Row[];

if (rows.length === 0) {
throw new Error('No rows returned — check RLS policies or filters.');
}
if (rows.length >= PAGE_SIZE) {
throw new Error(
`Received ${rows.length} rows — at or above PAGE_SIZE (${PAGE_SIZE}). Snapshot may be truncated; raise PAGE_SIZE or add pagination.`,
);
}

const snapshot = {
source: `${SUPABASE_URL}/rest/v1/ai_models`,
fetched_at: new Date().toISOString(),
count: rows.length,
models: rows,
};

Expand Down
10 changes: 6 additions & 4 deletions src/components/ai-models-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ type Model = {
};

type Snapshot = {
source: string;
fetched_at: string;
count: number;
models: Model[];
};

Expand All @@ -39,8 +37,12 @@ function formatContext(value: number | null): string {
function formatPrice(value: number | null): string {
if (value == null) return '—';
const perMtok = value * 1_000_000;
if (perMtok === 0) return '$0';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: perMtok === 0 strict-equality guard misses -0

The guard if (perMtok === 0) return '$0' is technically correct for +0 but Object.is(-0, 0) is false, so a value of 0 stored as -0 in the JSON would fall through. In practice, pricing data is never negative, but for robustness consider if (perMtok === 0 || Object.is(perMtok, -0)) return '$0', or more idiomatically if (!perMtok) return '$0' (which covers both 0 and -0 while being harmless here since null is already handled above). Low priority — just worth noting.

if (perMtok >= 1) return `$${perMtok.toFixed(2)}`;
return `$${perMtok.toFixed(3).replace(/0+$/, '').replace(/\.$/, '')}`;
if (perMtok >= 0.001) {
return `$${perMtok.toFixed(3).replace(/0+$/, '').replace(/\.$/, '')}`;
}
return `$${perMtok.toExponential(1)}`;
}

function formatFetched(iso: string): string {
Expand Down Expand Up @@ -133,7 +135,7 @@ export function AiModelsTable() {
/>

<p className="text-xs text-fd-muted-foreground">
Showing {filtered.length} of {DATA.count} models. Snapshot fetched{' '}
Showing {filtered.length} of {DATA.models.length} models. Snapshot fetched{' '}
{formatFetched(DATA.fetched_at)}. Pricing is per million tokens.
</p>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/data/ai-models.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"source": "https://enxvgkxsrpbtqlaeotjz.supabase.co/rest/v1/ai_models",
"fetched_at": "2026-05-18T21:17:53.304Z",
"count": 84,
"models": [
{
"id": "alibaba/qwen3-max-thinking",
Expand Down