integrate with models.dev

This commit is contained in:
Dax Raad
2025-06-05 14:59:07 -04:00
parent 1384a5e3e6
commit db2bb32bcf
11 changed files with 212 additions and 180 deletions

View File

@@ -0,0 +1,29 @@
import { Global } from "../global"
import { Log } from "../util/log"
import path from "path"
export namespace ModelsDev {
const log = Log.create({ service: "models.dev" })
function filepath() {
return path.join(Global.Path.data, "models.json")
}
export async function get() {
const file = Bun.file(filepath())
if (await file.exists()) {
refresh()
return file.json()
}
await refresh()
return get()
}
async function refresh() {
log.info("refreshing")
const result = await fetch("https://models.dev/api.json")
if (!result.ok)
throw new Error(`Failed to fetch models.dev: ${result.statusText}`)
await Bun.write(filepath(), result)
}
}