-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOllama - Open WebUI Script.ahk
338 lines (275 loc) · 9.95 KB
/
Ollama - Open WebUI Script.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
Ollama - Open WebUI Script
Copyright(C) 2024 Special-Niewbie Softwares
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#Persistent
global ProgressGui, ProgressBar, AIListDialogOpen := false
OllamaExePath := "C:\Users\" . A_UserName . "\AppData\Local\Programs\Ollama\ollama app.exe"
OllamaProcessName := "ollama app.exe"
DockerExePath := "C:\Program Files\Docker\Docker\Docker Desktop.exe"
DockerProcessName := "Docker Desktop.exe"
TempBatchFile := A_Temp . "\temp_update_models.ps1"
Menu, Tray, NoStandard
; Menu System Tray
Menu, Tray, Add, Update all Ollama Models, UpdateModels
Menu, Tray, Add, Check New Models Online, CheckModels
Menu, Tray, Add, AI Installed List, ShowAIList
Menu, Tray, Add, , Separator
Menu, Tray, Add, Reload Script, ReloadScript
Menu, Tray, Add, , Separator
Menu, Tray, Add, Script site for Updates / Donate, OpenScriptSite
Menu, Tray, Add, Show Version, ShowVersionInfo
Menu, Tray, Add, , Separator
Menu, Tray, Add, Exit, ExitApp
; Function to create and update the progress bar
ShowProgress(percentage, text := "") {
global ProgressGui, ProgressBar
if !IsObject(ProgressGui) {
Progress, B2 W600, % text
ProgressGui := true
}
Progress, % percentage
}
; Function to hide the progress bar
HideProgress() {
global ProgressGui
if (ProgressGui) {
Progress, Off
ProgressGui := false
}
}
; Function to check if a process exists
ProcessExist(ProcessName) {
Process, Exist, %ProcessName%
return ErrorLevel
}
; Function to run batch code
UpdateModels() {
global TempBatchFile
FileAppend, $models = (ollama list | Select-Object -Skip 1 | ForEach-Object { $_.Split()[0] })`nforeach ($model in $models) { ollama pull $model }`nPause, %TempBatchFile%
RunWait, powershell.exe -NoExit -File "%TempBatchFile%"
FileDelete, %TempBatchFile%
MsgBox, All Models are updated!
}
CheckModels() {
Run, https://ollama.com/library
}
; Check if Ollama is installed
if !FileExist(OllamaExePath) {
MsgBox, 0x40030, Ollama Not Installed, Ollama is not installed on your system. Please install Ollama first before proceeding to open the Open WebUI.
ExitApp
}
; Check if Ollama is already running
if !ProcessExist(OllamaProcessName) {
; Starting the progress bar
ShowProgress(0, "Checking Ollama AI server..")
Sleep, 500
ShowProgress(50, "Ollama AI server is not running...")
Sleep, 500
; Try starting Ollama app.exe
Run, %ComSpec% /c ""%OllamaExePath%"", , Hide
; Wait for some time to check if the application is launched
Sleep, 5000
; Check if the application has started
if !ProcessExist(OllamaProcessName) {
MsgBox, 0x40030, Ollama Launch Failed, Ollama app failed to start. Please check the installation and try again.
ExitApp
}
ShowProgress(50, "Starting Ollama AI server..")
Sleep, 500
ShowProgress(65, "Booting AI...")
Sleep, 500
ShowProgress(75, "Booting AI....")
Sleep, 500
ShowProgress(90, "AI almost ready for Open WebUI.....")
Sleep, 150
ShowProgress(100, "Startup completed!")
; Check if Docker Desktop is installed
if !FileExist(DockerExePath) {
MsgBox, 0x40030, Docker Not Installed, Docker Desktop is not installed on your system. Please install Docker Desktop first before proceeding to open the Open WebUI.
ExitApp
}
; Check if Docker Desktop is already running
if !ProcessExist(DockerProcessName) {
Run, % DockerExePath
Sleep, 500
ShowProgress(50, "Starting Docker AI server..")
Sleep, 5000
ShowProgress(65, "Booting AI...")
Sleep, 5000
ShowProgress(75, "Booting AI....")
Sleep, 5000
ShowProgress(90, "AI almost ready for Open WebUI.....")
Sleep, 1500
ShowProgress(100, "Startup completed!")
Run, http://localhost:3000/
Sleep, 500
HideProgress()
} else {
ShowProgress(50, "Checking Docker AI server..")
Sleep, 500
ShowProgress(75, "Docker AI is already running, booting Open WebUI...")
Sleep, 500
ShowProgress(100, "Startup completed!")
Run, http://localhost:3000/
Sleep, 500
HideProgress()
}
} else {
ShowProgress(0, "Checking Ollama AI server...")
Sleep, 500
ShowProgress(50, "Ollama AI is already running, checking Docker AI server...")
Sleep, 500
; Check if Docker Desktop is installed
if !FileExist(DockerExePath) {
MsgBox, 0x40030, Docker Not Installed, Docker Desktop is not installed on your system. Please install Docker Desktop first before proceeding to open the Open WebUI.
ExitApp
}
; Check if Docker Desktop is already running
if !ProcessExist(DockerProcessName) {
Run, % DockerExePath
Sleep, 500
ShowProgress(50, "Starting Docker AI server..")
Sleep, 5000
ShowProgress(65, "Booting AI...")
Sleep, 5000
ShowProgress(75, "Booting AI....")
Sleep, 5000
ShowProgress(90, "AI almost ready for Open WebUI.....")
Sleep, 1500
ShowProgress(100, "Startup completed!")
Run, http://localhost:3000/
Sleep, 500
HideProgress()
} else {
ShowProgress(50, "Checking Docker AI server...")
Sleep, 500
ShowProgress(80, "Docker AI is already running, booting Open WebUI...")
Sleep, 500
ShowProgress(100, "Startup completed!")
Run, http://localhost:3000/
Sleep, 500
HideProgress()
}
}
; Handles the "Windows+a" key combination
#a::
Run, http://localhost:3000/
return
ShowToolTip() {
ToolTip, Window Minimized
SetTimer, RemoveToolTip, 1500
CloseButtonTooltipActive := true
}
RemoveToolTip() {
ToolTip
CloseButtonTooltipActive := false
}
#If WinActive("Installed AI List") And CloseUnderMouse()
LButton::WinMinimize
#If
CloseUnderMouse()
{
CoordMode, Mouse, Window
MouseGetPos, x, y
WinGetPos,,, w,, A
If (w - x <= 46) And (y <= 30) {
If (!CloseButtonTooltipActive) {
ShowToolTip()
}
return True
}
Return False
}
Return
ShowAIList:
WebUIcommands := "serve - Start ollama`n"
. "create - Create a model from a Modelfile`n"
. "show - Show information for a model`n"
. "run - Run a model`n"
. "pull - Pull a model from a registry`n"
. "push - Push a model to a registry`n"
. "list - List models`n"
. "ps - List running models`n"
. "cp - Copy a model`n"
. "rm - Remove a model`n"
. "help - Help about any command`n`n"
. "Just insert the command above to get the results, no need to write `ollama `:"
; Check if the dialog is already open
if AIListDialogOpen
return
; Set the List Dialog Open variable to true
AIListDialogOpen := true
; Creating the dialog box
Gui, AIListDialog:Add, Text, x5 y5 w300 h20, Available Commands:`n
Gui, AIListDialog:Add, Text, x20 y20 w400 h180, %WebUIcommands%
Gui, AIListDialog:Add, Edit, x20 y210 w275 h20 vCommandText
Gui, AIListDialog:Add, Button, x312 y207 w60 h25 gRunCommand, Enter >
Gui, AIListDialog:Add, Text, x5 y245 w300 h20, Result:
Gui, AIListDialog:Add, ListBox, x5 y265 w410 h200 vAIListText, % StrReplace(RunAIListCommand("ollama list"), "`n", "|")
Gui, AIListDialog:Add, Button, x172.5 y535 w75 h30 Default gCloseAIList, Close
Gui, AIListDialog:Show, w420 h580, Installed AI List
Return
CloseAIList:
; Close the dialog window
Gui, AIListDialog:Destroy
; Kill the CMD process in the background
if (cmdPID) {
Process, Close, %cmdPID% ; Uses the cmd PID variable stored in RunE List Command
cmdPID := ""
}
; Resets the List Dialog Open variable to false
AIListDialogOpen := false
return
RunAIListCommand(command) {
; Run the ollama list command and capture the output
commandOutput := ""
RunWait, %comspec% /c %command%,, Hide, pid
Process, WaitClose, %pid%
file := A_Temp . "\ollama_list_output.txt"
FileDelete, %file%
RunWait, %comspec% /c %command% > %file%,, Hide
FileRead, commandOutput, %file%
FileDelete, %file%
; Remove the first line from the output
StringSplit, lines, commandOutput, `n
outputWithoutFirstLine := ""
Loop, % lines0 {
if (A_Index != 1) {
outputWithoutFirstLine .= lines%A_Index% "`n"
}
}
return outputWithoutFirstLine
}
RunCommand:
; Get text from writing bar
GuiControlGet, Command, , CommandText
; Add "ollama " to the command
command := "ollama " . Command
; Run the command
AIList := RunAIListCommand(command)
; Update the text with the result
GuiControl,, AIListText, %AIList%
Return
ReloadScript:
Reload
return
OpenScriptSite() {
Run, https://github.com/Special-Niewbie/Ollama-Open-WebUI-Script
}
; Function to show version information
ShowVersionInfo:
MsgBox, 64, Version Info, Script Version: 1.0.0 `nAuthor: Special-Niewbie Softwares `nCopyright(C) 2024 Special-Niewbie Softwares
return
ExitApp:
ExitApp