fix: discover Ollama on Docker host

This commit is contained in:
Hermes Agent
2026-08-24 20:47:46 +10:00
parent 7def2990ce
commit 3bee6ac48c
5 changed files with 28 additions and 8 deletions
+10 -5
View File
@@ -14,19 +14,24 @@ is_container() {
[[ -f /run/.containerenv ]]
}
ollama_endpoint() {
ollama_endpoints() {
if [[ -n "${OLLAMA_HOST:-}" ]]; then
printf '%s' "${OLLAMA_HOST%/}"
printf '%s\n' "${OLLAMA_HOST%/}"
elif is_container; then
printf '%s' 'http://ollama:11434'
printf '%s\n' 'http://ollama:11434' 'http://host.docker.internal:11434'
else
printf '%s' 'http://localhost:11434'
printf '%s\n' 'http://localhost:11434'
fi
}
check_endpoint() {
command -v curl >/dev/null 2>&1 || return 1
curl --fail --silent --show-error --max-time 5 "$(ollama_endpoint)/api/version" >/dev/null
while IFS= read -r endpoint; do
if curl --fail --silent --show-error --max-time 5 "${endpoint}/api/version" >/dev/null; then
return 0
fi
done < <(ollama_endpoints)
return 1
}
if [[ "${1:-}" == "--check" ]]; then