fix: look for recent model in fallback in cli (#12582)
This commit is contained in:
@@ -14,6 +14,8 @@ import { Env } from "../env"
|
|||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { Flag } from "../flag/flag"
|
import { Flag } from "../flag/flag"
|
||||||
import { iife } from "@/util/iife"
|
import { iife } from "@/util/iife"
|
||||||
|
import { Global } from "../global"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
// Direct imports for bundled providers
|
// Direct imports for bundled providers
|
||||||
import { createAmazonBedrock, type AmazonBedrockProviderSettings } from "@ai-sdk/amazon-bedrock"
|
import { createAmazonBedrock, type AmazonBedrockProviderSettings } from "@ai-sdk/amazon-bedrock"
|
||||||
@@ -1229,9 +1231,21 @@ export namespace Provider {
|
|||||||
const cfg = await Config.get()
|
const cfg = await Config.get()
|
||||||
if (cfg.model) return parseModel(cfg.model)
|
if (cfg.model) return parseModel(cfg.model)
|
||||||
|
|
||||||
const provider = await list()
|
const providers = await list()
|
||||||
.then((val) => Object.values(val))
|
const recent = (await Bun.file(path.join(Global.Path.state, "model.json"))
|
||||||
.then((x) => x.find((p) => !cfg.provider || Object.keys(cfg.provider).includes(p.id)))
|
.json()
|
||||||
|
.then((x) => (Array.isArray(x.recent) ? x.recent : []))
|
||||||
|
.catch(() => [])) as { providerID: string; modelID: string }[]
|
||||||
|
for (const entry of recent) {
|
||||||
|
const provider = providers[entry.providerID]
|
||||||
|
if (!provider) continue
|
||||||
|
if (!provider.models[entry.modelID]) continue
|
||||||
|
return { providerID: entry.providerID, modelID: entry.modelID }
|
||||||
|
}
|
||||||
|
|
||||||
|
const provider = Object.values(providers).find(
|
||||||
|
(p) => !cfg.provider || Object.keys(cfg.provider).includes(p.id),
|
||||||
|
)
|
||||||
if (!provider) throw new Error("no providers found")
|
if (!provider) throw new Error("no providers found")
|
||||||
const [model] = sort(Object.values(provider.models))
|
const [model] = sort(Object.values(provider.models))
|
||||||
if (!model) throw new Error("no models found")
|
if (!model) throw new Error("no models found")
|
||||||
|
|||||||
Reference in New Issue
Block a user