forked from techjarves/Portable-AI-USB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-windows.bat
More file actions
150 lines (128 loc) · 5.05 KB
/
Copy pathstart-windows.bat
File metadata and controls
150 lines (128 loc) · 5.05 KB
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
@echo off
title Portable Uncensored AI - Launcher
color 0A
echo ===================================================
echo Launching Portable AI Engine from USB...
echo ===================================================
:: -------------------------------------------------------
:: IMPORTANT: All paths must point to USB, not the PC!
:: -------------------------------------------------------
:: Set Ollama model data path to the USB drive
set "OLLAMA_MODELS=%~dp0ollama\data"
:: Tell AnythingLLM to store ALL its data on the USB
:: STORAGE_DIR is the official AnythingLLM portable env var
set "STORAGE_DIR=%~dp0anythingllm_data"
set "ANYTHINGLLM_PROFILE=%STORAGE_DIR%\anythingllm-desktop"
set "ROAMING_PROFILE=%USERPROFILE%\AppData\Roaming\anythingllm-desktop"
set "PROFILE_BACKUP=%USERPROFILE%\AppData\Roaming\anythingllm-desktop.host-backup"
:: Also override APPDATA AND XDG paths for Electron safety net
set "APPDATA=%~dp0anythingllm_data"
set "LOCALAPPDATA=%~dp0anythingllm_data"
:: Create the data folder on USB if it doesn't exist
if not exist "%~dp0anythingllm_data" mkdir "%~dp0anythingllm_data"
if not exist "%ANYTHINGLLM_PROFILE%" mkdir "%ANYTHINGLLM_PROFILE%"
:: -------------------------------------------------------
:: ENSURE ANYTHINGLLM USES EXTERNAL OLLAMA (not built-in)
:: -------------------------------------------------------
set "ENV_FILE=%~dp0anythingllm_data\storage\.env"
if not exist "%~dp0anythingllm_data\storage" mkdir "%~dp0anythingllm_data\storage"
:: Read the first model from installed-models.txt if it exists
set "DEFAULT_MODEL=nemomix-local"
if exist "%~dp0models\installed-models.txt" (
for /f "usebackq tokens=1 delims=|" %%a in ("%~dp0models\installed-models.txt") do (
set "DEFAULT_MODEL=%%a"
goto :GotModel
)
)
:GotModel
:: Check if .env needs fixing (missing or using built-in ollama)
set "NEEDS_FIX=0"
if not exist "%ENV_FILE%" set "NEEDS_FIX=1"
if exist "%ENV_FILE%" (
findstr /C:"LLM_PROVIDER=ollama" "%ENV_FILE%" >nul 2>&1
if errorlevel 1 (
findstr /C:"LLM_PROVIDER=anythingllm_ollama" "%ENV_FILE%" >nul 2>&1
if not errorlevel 1 set "NEEDS_FIX=1"
)
)
if "%NEEDS_FIX%"=="1" (
echo Configuring AnythingLLM to use external Ollama engine...
(
echo LLM_PROVIDER=ollama
echo OLLAMA_BASE_PATH=http://127.0.0.1:11434
echo OLLAMA_MODEL_PREF=%DEFAULT_MODEL%
echo OLLAMA_MODEL_TOKEN_LIMIT=4096
echo EMBEDDING_ENGINE=native
echo VECTOR_DB=lancedb
) > "%ENV_FILE%"
echo Done. Default model: %DEFAULT_MODEL%
)
:: -------------------------------------------------------
:: PROFILE REDIRECT PREVENTED
:: -------------------------------------------------------
:: Electron '--user-data-dir' completely overrides profile creation,
:: ensuring Everything is purely portable on the USB drive.
:: -------------------------------------------------------
:: SHOW INSTALLED MODELS
:: -------------------------------------------------------
if exist "%~dp0models\installed-models.txt" (
echo.
echo Installed models:
for /f "usebackq tokens=1,2,3 delims=|" %%a in ("%~dp0models\installed-models.txt") do (
echo - %%b [%%c]
)
echo.
)
:: Start Ollama Engine silently in the background
echo Starting Ollama Engine...
start "" /B "%~dp0ollama\ollama.exe" serve
:: Give it a few seconds to boot up
timeout /t 3 >nul
:: Find and launch AnythingLLM
echo Starting AnythingLLM Interface...
if exist "%~dp0anythingllm\AnythingLLM.exe" (
set "APP_PATH=%~dp0anythingllm\AnythingLLM.exe"
goto LaunchApp
)
echo.
echo ERROR: AnythingLLM was not found in 'anythingllm' folder!
echo.
echo Directory Listing for Diagnostic:
dir "%~dp0anythingllm"
echo.
echo Please run install.bat first to download and extract everything.
echo.
pause
exit /b
:LaunchApp
:: CRITICAL: We MUST wipe Electron path caches for true portability!
:: This fixes the "JavaScript error (ENOENT)" when moving USBs between PCs.
if exist "%~dp0anythingllm_data\config.json" del /q "%~dp0anythingllm_data\config.json"
if exist "%~dp0anythingllm_data\Cache" rmdir /s /q "%~dp0anythingllm_data\Cache"
if exist "%~dp0anythingllm_data\Code Cache" rmdir /s /q "%~dp0anythingllm_data\Code Cache"
if exist "%~dp0anythingllm_data\GPUCache" rmdir /s /q "%~dp0anythingllm_data\GPUCache"
:: CRITICAL: We MUST pushd into the app directory for the portable app to find its own resources!
pushd "%~dp0anythingllm"
:: Pass --user-data-dir
start "" "AnythingLLM.exe" --user-data-dir="%~dp0anythingllm_data"
popd
:Running
echo.
echo ===================================================
echo SYSTEM ONLINE: Your AI is running from the USB!
echo ===================================================
echo.
echo You can now use the AnythingLLM window to chat.
echo Keep this black window open to keep the AI engine running!
echo.
echo TIP: Go to Settings ^> LLM to switch between models.
echo.
echo Press any key to SHUT DOWN the AI safely...
echo.
pause
:: Clean shutdown
taskkill /F /IM "ollama.exe" >nul 2>&1
taskkill /F /IM "AnythingLLM.exe" >nul 2>&1
echo.
echo AI Engine shut down. You may safely eject the USB.
timeout /t 3 >nul