Spaces:
Runtime error
Runtime error
File size: 1,620 Bytes
077865a | 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { Router } from 'express';
import type { Request, Response } from 'express';
import { getDb } from '../db/index.js';
import { hasProvider } from '../providers/index.js';
export const modelsRouter = Router();
// List all models with availability info
modelsRouter.get('/', (_req: Request, res: Response) => {
const db = getDb();
const models = db.prepare(`
SELECT m.*, fc.priority, fc.enabled as fallback_enabled
FROM models m
LEFT JOIN fallback_config fc ON fc.model_db_id = m.id
ORDER BY COALESCE(fc.priority, m.intelligence_rank) ASC
`).all() as any[];
// Count keys per platform
const keyCounts = db.prepare(`
SELECT platform, COUNT(*) as count
FROM api_keys
WHERE enabled = 1
GROUP BY platform
`).all() as { platform: string; count: number }[];
const keyCountMap = new Map(keyCounts.map(k => [k.platform, k.count]));
const result = models.map(m => ({
id: m.id,
platform: m.platform,
modelId: m.model_id,
displayName: m.display_name,
intelligenceRank: m.intelligence_rank,
speedRank: m.speed_rank,
sizeLabel: m.size_label,
rpmLimit: m.rpm_limit,
rpdLimit: m.rpd_limit,
tpmLimit: m.tpm_limit,
tpdLimit: m.tpd_limit,
monthlyTokenBudget: m.monthly_token_budget,
contextWindow: m.context_window,
enabled: m.enabled === 1,
supportsVision: m.supports_vision === 1,
supportsTools: m.supports_tools === 1,
priority: m.priority,
fallbackEnabled: m.fallback_enabled === 1,
hasProvider: hasProvider(m.platform),
keyCount: keyCountMap.get(m.platform) ?? 0,
}));
res.json(result);
});
|