@@ -4,6 +4,8 @@ source "$OMC_APP_BUNDLE_PATH/Contents/Resources/Scripts/aichat.library.sh"
44
55echo " [$( /usr/bin/basename " $0 " ) ]"
66
7+ webui_dir_path=" $OMC_APP_BUNDLE_PATH /Contents/Resources/WebUI"
8+
79register_started_server ()
810{
911 local host_pid=" $1 "
@@ -90,7 +92,9 @@ stop_orphaned_servers()
9092
9193wait_for_server_response ()
9294{
95+ local result=0
9396 local seconds_count=0
97+
9498 while true ; do
9599 # wait until we get a response from server
96100 /usr/bin/curl " http://localhost:$port_num /slots" > /dev/null 2>&1
@@ -100,24 +104,38 @@ wait_for_server_response()
100104 break
101105 fi
102106
103- # or 5 seconds pass
107+ # or 20 seconds pass
104108 seconds_count=$(( seconds_count + 1 ))
105- if [ " $seconds_count " -ge 5 ]; then
106- echo " warning: timed out after $seconds_count seconds while waiting for server response"
109+ if [ " $seconds_count " -ge 20 ]; then
110+ local message=$( echo " Timed out after $seconds_count seconds while waiting for llama-server response.\n\nPlease try again" )
111+ echo " $message "
112+ " $alert " --level " stop" --title " $APPLET_NAME " --ok " OK" " $message "
113+ result=13
107114 break
115+ elif [ " $seconds_count " -eq 5 ]; then
116+ echo " $dialog $OMC_NIB_DLG_GUID 2 file://${webui_dir_path} /start_slow.html"
117+ " $dialog " " $OMC_NIB_DLG_GUID " 2 " file://${webui_dir_path} /start_slow.html"
108118 fi
109119
110120 sleep 1
111121 done
122+
123+ return " $result "
112124}
113125
114126report_server_launch_failure ()
115127{
116128 local message=$( echo " llama-server failed to launch! \n\nVerify if the selected large language model is supported by llama.cpp engine." )
117129 echo " $message "
118130 " $alert " --level " stop" --title " $APPLET_NAME " --ok " OK" " $message "
131+ return 11
119132}
120133
134+
135+ echo " $dialog $OMC_NIB_DLG_GUID 2 file://${webui_dir_path} /start.html"
136+ " $dialog " " $OMC_NIB_DLG_GUID " 2 " file://${webui_dir_path} /start.html"
137+ echo " "
138+
121139echo " OMC_CURRENT_COMMAND_GUID: ${OMC_CURRENT_COMMAND_GUID} "
122140echo " OMC_NIB_DLG_GUID: ${OMC_NIB_DLG_GUID} "
123141echo " OMC_FRONT_PROCESS_ID: ${OMC_FRONT_PROCESS_ID} "
@@ -148,13 +166,14 @@ stop_orphaned_servers
148166
149167# /usr/bin/curl "http://localhost:$port_num/slots" > /dev/null 2>&1
150168
169+ server_result=0
170+
151171echo " Check if the required llama-server with selected model is already running"
152172running_process=$( /bin/ps -U $USER | /usr/bin/grep -E " $OMC_APP_BUNDLE_PATH /Contents/Support/Llama.cpp/llama-server" | /usr/bin/grep -E " $port_num " | /usr/bin/grep -E " $AICHAT_MODEL_PATH " )
153173
154174if [ $? != 0 ]; then
155175 echo " Starting llama-server..."
156176 # start the server
157- webui_dir_path=" $OMC_APP_BUNDLE_PATH /Contents/Resources/WebUI"
158177 " $OMC_APP_BUNDLE_PATH /Contents/Support/Llama.cpp/llama-server" --host 127.0.0.1 --port $port_num --path " $webui_dir_path " --model " $AICHAT_MODEL_PATH " &
159178 llama_server_pid=$!
160179 if [ " $llama_server_pid " != " " ]; then
@@ -164,23 +183,33 @@ if [ $? != 0 ]; then
164183 if [ " $server_process_exists " != 0 ]; then
165184 # server exited. most likely something wrong with selected gguf model
166185 report_server_launch_failure
186+ server_result=$?
167187 else
168188 # server process running, check if it is responsive
169189 wait_for_server_response
190+ server_result=$?
170191
171192 echo " Register server with pid $llama_server_pid "
172193 register_started_server " ${OMC_FRONT_PROCESS_ID} " " ${llama_server_pid} " " $AICHAT_MODEL_PATH "
173194 fi
174195 else
175196 report_server_launch_failure
197+ server_result=$?
176198 fi
177199
178200else
179201 llama_server_pid=$( echo " $running_process " | /usr/bin/grep -E --only-matching ' ^ *[[:digit:]]+ ' | /usr/bin/tr -d ' ' )
180202 echo " llama-server already running with pid: $running_process "
203+ server_result=0
181204fi
182205
183- echo " "
184- echo " $dialog $OMC_NIB_DLG_GUID 2 http://localhost:$port_num /"
185- " $dialog " " $OMC_NIB_DLG_GUID " 2 " http://localhost:$port_num /"
206+ if [ " $server_result " = 0 ]; then
207+ echo " "
208+ echo " $dialog $OMC_NIB_DLG_GUID 2 http://localhost:$port_num /"
209+ " $dialog " " $OMC_NIB_DLG_GUID " 2 " http://localhost:$port_num /"
210+ else
211+ echo " "
212+ echo " $dialog $OMC_NIB_DLG_GUID 2 file://${webui_dir_path} /start_error.html?port=$port_num "
213+ " $dialog " " $OMC_NIB_DLG_GUID " 2 " file://${webui_dir_path} /start_error.html?port=$port_num "
214+ fi
186215
0 commit comments