feat(ai): add Hugging Face provider support

- Add huggingface to KnownProvider type
- Add HF_TOKEN env var mapping
- Process huggingface models from models.dev (14 models)
- Use openai-completions API with compat settings
- Add tests for all provider test suites
- Update documentation

fixes #994
This commit is contained in:
Mario Zechner 2026-01-29 02:40:14 +01:00
parent f3cfb7e1ae
commit c808de605a
16 changed files with 562 additions and 23 deletions

View file

@ -474,6 +474,35 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
}
}
// Process Hugging Face models
if (data.huggingface?.models) {
for (const [modelId, model] of Object.entries(data.huggingface.models)) {
const m = model as ModelsDevModel;
if (m.tool_call !== true) continue;
models.push({
id: modelId,
name: m.name || modelId,
api: "openai-completions",
provider: "huggingface",
baseUrl: "https://router.huggingface.co/v1",
reasoning: m.reasoning === true,
input: m.modalities?.input?.includes("image") ? ["text", "image"] : ["text"],
cost: {
input: m.cost?.input || 0,
output: m.cost?.output || 0,
cacheRead: m.cost?.cache_read || 0,
cacheWrite: m.cost?.cache_write || 0,
},
compat: {
supportsDeveloperRole: false,
},
contextWindow: m.limit?.context || 4096,
maxTokens: m.limit?.output || 4096,
});
}
}
// Process OpenCode Zen models
// API mapping based on provider.npm field:
// - @ai-sdk/openai → openai-responses