Skip to content

Commit

Permalink
Merge pull request #56 from ericcurtin/browser
Browse files Browse the repository at this point in the history
Open links in browser
  • Loading branch information
ericcurtin committed May 7, 2024
2 parents d5840cf + bd71bc4 commit e659d87
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions podman-ollama
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ cleanup_impl() {
$SUDO $CONMAN rm -f $CON_PS
$SUDO $CONMAN rm -f $CHATBOT_PS
$SUDO $CONMAN pod rm -f $POD_PS
trap - SIGTERM
kill -- -$$
}

cleanup() {
Expand Down Expand Up @@ -128,7 +130,7 @@ server_init() {
gpu_setup

if [ "$OLLAMA_CMD" != "serve" ]; then
trap cleanup EXIT
trap cleanup SIGINT SIGTERM EXIT
fi

if [ -n "$OLLAMA_HOST" ]; then
Expand All @@ -140,7 +142,8 @@ server_init() {
fi

if $CHATBOT || $OPEN_WEBUI; then
for PORT in {8501..9001}; do
PORT_IN_END=$((PORT_IN+100))
for (( PORT=$PORT_IN; PORT<=$PORT_IN_END; ++PORT )); do
POD_PS="$($SUDO $CONMAN pod create -p $PORT:$PORT_IN)"
ADD="$ADD --pod $POD_PS"
if $SUDO $CONMAN pod start $POD_PS > /dev/null 2>&1; then
Expand Down Expand Up @@ -277,6 +280,20 @@ set_config_vals() {
fi
}

open_browser_when_ready() {
sleep 4

for i in {1..1024}; do
if curl -s http://localhost:$PORT > /dev/null; then
break
fi

sleep 1
done

xdg-open http://localhost:$PORT || true
}

set -e -o pipefail
shopt -s nocasematch

Expand Down Expand Up @@ -386,6 +403,7 @@ if [ -t 1 ]; then
fi

if $CHATBOT || $OPEN_WEBUI; then
open_browser_when_ready &
echo -e "\n Local URL: http://localhost:$PORT\n"
$SUDO $CONMAN run --rm $PRIV --security-opt=label=disable --pod $POD_PS -v"$HOME":"$HOME" -v/tmp:/tmp $ADD_UI
elif [ "$PODMAN_CMD" = "generate" ]; then
Expand Down

0 comments on commit e659d87

Please sign in to comment.