| 147 | } |
| 148 | |
| 149 | async function loadProviderBaseModelRefs(root: string) { |
| 150 | const refs = new Map<string, string>(); |
| 151 | const providersDirectory = path.join(root, "providers"); |
| 152 | if (!existsSync(providersDirectory)) return refs; |
| 153 | |
| 154 | for await (const modelPath of new Bun.Glob("*/models/**/*.toml").scan({ |
| 155 | cwd: providersDirectory, |
| 156 | absolute: true, |
| 157 | followSymlinks: true, |
| 158 | })) { |
| 159 | const parts = path.relative(providersDirectory, modelPath).split(path.sep); |
| 160 | const [providerId, modelsSegment, ...modelParts] = parts; |
| 161 | if (!providerId || modelsSegment !== "models" || modelParts.length === 0) { |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | const modelId = modelParts.join("/").slice(0, -5); |
| 166 | const toml = await import(modelPath, { |
| 167 | with: { |
| 168 | type: "toml", |
| 169 | }, |
| 170 | }).then((mod) => mod.default as { base_model?: unknown }); |
| 171 | |
| 172 | if (typeof toml.base_model === "string") { |
| 173 | refs.set(`${providerId}/${modelId}`, toml.base_model); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return refs; |
| 178 | } |
| 179 | |
| 180 | function buildModelEntries() { |
| 181 | const entries = new Map<string, ModelEntry>(); |