Add local Ollama as an AI Hub provider for claude-code
Ollama v0.14+ speaks the Anthropic Messages API natively, so the registry drives it with a fixed 'ollama' token and runtime-listed models: static_token skips secret storage everywhere keys resolve, models_dynamic defers model validation to the live /api/tags list, and the setup wizard installs the right GPU variant and starts the service before listing local models. Doctor stops treating the endpoint port as part of the hostname. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019hLK3wsDuKVAC37GgDqg6H
This commit is contained in:
+26
-2
@@ -24,7 +24,31 @@ provider=$(printf '%s\n' "${providers[@]}" | gum choose --header "选择 Provide
|
||||
|
||||
harness_proto=$(cn_ai_harness_field "$harness" protocol)
|
||||
allowlist=$(cn_ai_combo_models "$harness" "$provider")
|
||||
if [[ -n $allowlist ]]; then
|
||||
if cn_ai_models_dynamic "$provider"; then
|
||||
base=$(cn_ai_endpoint "$provider" "$harness_proto")
|
||||
if [[ $provider == "ollama" ]]; then
|
||||
if omarchy-cmd-missing ollama; then
|
||||
gum confirm "Ollama 未安装,现在安装本地服务?" || exit 1
|
||||
if omarchy-cmd-present nvidia-smi; then
|
||||
ollama_pkg=ollama-cuda
|
||||
elif omarchy-cmd-present rocminfo; then
|
||||
ollama_pkg=ollama-rocm
|
||||
else
|
||||
ollama_pkg=ollama
|
||||
fi
|
||||
omarchy-pkg-add "$ollama_pkg"
|
||||
fi
|
||||
if ! curl -sf --connect-timeout 3 "$base/api/tags" > /dev/null; then
|
||||
sudo systemctl enable --now ollama
|
||||
fi
|
||||
fi
|
||||
models=$(curl -sf --connect-timeout 3 "$base/api/tags" | jq -r '.models[].name' || true)
|
||||
if [[ -z $models ]]; then
|
||||
echo "无法列出本地模型(服务未运行或尚未拉取):先 ollama pull <模型>(如 qwen3-coder)再重试" >&2
|
||||
exit 1
|
||||
fi
|
||||
model=$(gum choose --header "选择本地模型" <<<"$models")
|
||||
elif [[ -n $allowlist ]]; then
|
||||
model=$(gum choose --header "选择模型" <<<"$allowlist")
|
||||
else
|
||||
# Hide models bound to a different wire protocol than the harness speaks
|
||||
@@ -48,7 +72,7 @@ if [[ $proto == "native" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! omarchy-cn-ai-secret get "$provider" > /dev/null 2>&1; then
|
||||
if ! cn_ai_resolve_key "$provider" > /dev/null 2>&1; then
|
||||
key=$(gum input --password --header "$provider API Key(获取: $(jq -r --arg p "$provider" '.providers[$p].key_url' "$CN_AI_PROVIDERS"))")
|
||||
printf '%s' "$key" | omarchy-cn-ai-secret set "$provider"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user