Add Hugging Face as a chat provider

Lets users with an existing Hugging Face account chat through HF's
Inference Providers router without signing up for another provider.
Model IDs are namespaced hf:org/model-name to avoid inferProvider's
OpenRouter "/" heuristic misrouting them; curated model list plus a
"Custom Model ID…" entry point stand in for HF's lack of a catalog/
pricing API.
This commit is contained in:
2026-08-28 07:54:22 +02:00
parent 017a0dbd9d
commit 0035340f2e
14 changed files with 624 additions and 4 deletions
+4
View File
@@ -639,6 +639,10 @@ Don't narrate future actions ("Let me...") - just use the tools.
nonisolated static func inferProvider(from modelId: String) -> Settings.Provider? {
// Apple Foundation Models
if modelId.hasPrefix("apple-") { return .appleOnDevice }
// Hugging Face models are namespaced "hf:org/model-name" must be checked before the
// generic "/"-contains heuristic below, since HF IDs are structurally identical to
// OpenRouter's "vendor/model" shape and would otherwise be misrouted.
if modelId.hasPrefix(HuggingFaceProvider.idPrefix) { return .huggingface }
// OpenRouter models always contain a "/" (e.g. "anthropic/claude-3-5-sonnet")
if modelId.contains("/") { return .openrouter }
// Anthropic direct (e.g. "claude-sonnet-4-5-20250929")