Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python/llm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ http://<device-hostname>:{{.PORT}}

The first start downloads the model in the background — watch the `[ollama]`
log lines for pull progress. The model list in the UI populates once the pull
completes.
completes. If the device does not have network/DNS when the app first starts,
the Ollama service keeps retrying instead of giving up, so the model appears
automatically once connectivity is restored. If Open WebUI shows an empty model
picker, the model is still downloading or the puller is retrying; check the
Ollama service logs before pulling manually.

> On the device each service runs in its own network namespace, so the
> Docker service-name URL (`http://ollama:11434`) does not resolve. The
Expand All @@ -88,6 +92,6 @@ built-in service-name DNS.

```sh
wendy run --detach # start and return; stream later with:
wendy device logs
wendy device ps # list both containers
wendy device logs {{.APP_ID}} --service ollama --tail 100
wendy device apps list # list both containers
```
39 changes: 34 additions & 5 deletions python/llm/ollama/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,44 @@ mkdir -p "$OLLAMA_MODELS"

# Pull the configured model in the background once the server is up, so the
# API is reachable immediately and the (potentially large) download streams
# its progress to the service log.
# its progress to the service log. Keep retrying because first boot often races
# network readiness; without retries Open WebUI can stay up with an empty model
# picker forever after a transient DNS or connectivity failure.
(
export OLLAMA_HOST=127.0.0.1:11434

echo "Waiting for Ollama API before pulling ${OLLAMA_MODEL}..."
until curl -fsS "http://127.0.0.1:11434/api/tags" >/dev/null 2>&1; do
sleep 2
done
if ! OLLAMA_HOST=127.0.0.1:11434 ollama list | awk '{print $1}' | grep -qx "$OLLAMA_MODEL"; then
echo "Pulling ${OLLAMA_MODEL} into ${OLLAMA_MODELS}"
OLLAMA_HOST=127.0.0.1:11434 ollama pull "$OLLAMA_MODEL"
fi

retry_delay=10
max_retry_delay=60

while true; do
if ollama list | awk 'NR > 1 { print $1 }' | grep -qx "$OLLAMA_MODEL"; then
echo "Ollama model ${OLLAMA_MODEL} is available in ${OLLAMA_MODELS}."
break
fi

echo "First-run setup: pulling ${OLLAMA_MODEL} into ${OLLAMA_MODELS}."
echo "Open WebUI may show an empty model list until this download completes."

if ollama pull "$OLLAMA_MODEL"; then
echo "Finished pulling ${OLLAMA_MODEL}."
retry_delay=10
continue
fi

echo "Pulling ${OLLAMA_MODEL} failed. Network/DNS may not be ready yet, or the model name may be unavailable."
echo "Retrying in ${retry_delay}s..."
sleep "$retry_delay"

retry_delay=$((retry_delay * 2))
if ((retry_delay > max_retry_delay)); then
retry_delay=$max_retry_delay
fi
done
) &

exec ollama serve
Loading