forked from niuniu/llm-intelligence
fix deployment and frontend build regressions
This commit is contained in:
@@ -110,31 +110,35 @@ export function normalizeModel(raw: any): Model | null {
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadFallbackModels() {
|
||||
// latest_models.json is a local runtime snapshot when present.
|
||||
// models.json is the committed fixture fallback kept in the repo.
|
||||
const sources = [
|
||||
() => import('../data/latest_models.json'),
|
||||
() => import('../data/models.json'),
|
||||
]
|
||||
function normalizeModelList(raw: any) {
|
||||
const arr: any[] = Array.isArray(raw) ? raw : (raw?.models || [])
|
||||
return arr
|
||||
.map(normalizeModel)
|
||||
.filter((model: Model | null): model is Model => model !== null)
|
||||
}
|
||||
|
||||
for (const load of sources) {
|
||||
try {
|
||||
const module = await load()
|
||||
const raw = module.default as any
|
||||
const arr: any[] = Array.isArray(raw) ? raw : (raw.models || [])
|
||||
const normalized = arr
|
||||
.map(normalizeModel)
|
||||
.filter((model: Model | null): model is Model => model !== null)
|
||||
if (normalized.length > 0) {
|
||||
return normalized
|
||||
}
|
||||
} catch {
|
||||
// 继续尝试下一个回退源
|
||||
async function loadRuntimeSnapshot() {
|
||||
try {
|
||||
const response = await fetch('/latest_models.json', { cache: 'no-store' })
|
||||
if (!response.ok) {
|
||||
return []
|
||||
}
|
||||
|
||||
const raw = await response.json()
|
||||
return normalizeModelList(raw)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadFallbackModels() {
|
||||
const snapshot = await loadRuntimeSnapshot()
|
||||
if (snapshot.length > 0) {
|
||||
return snapshot
|
||||
}
|
||||
|
||||
return []
|
||||
const module = await import('../data/models.json')
|
||||
return normalizeModelList(module.default)
|
||||
}
|
||||
|
||||
export function formatPrice(model: Model, kind: 'input' | 'output') {
|
||||
|
||||
Reference in New Issue
Block a user