fix: discover Ollama on Docker host
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user