forked from Josh-XT/AGiXT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGiXT.sh
executable file
·346 lines (325 loc) · 12.8 KB
/
AGiXT.sh
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
339
340
341
342
343
344
345
346
#!/bin/bash
# Define colors and formatting
BOLD=$(tput bold)
GREEN=$(tput setaf 2)
CYAN=$(tput setaf 6)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
MAGENTA=$(tput setaf 5)
BLUE=$(tput setaf 4)
RESET=$(tput sgr0)
# Check if .env file exists
environment_setup() {
if [[ ! -f ".env" ]]; then
clear
echo "${BOLD}${CYAN}"
echo " ___ _______ _ ________"
echo " / | / ____(_) |/ /_ __/"
echo " / /| |/ / __/ /| / / / "
echo " / ___ / /_/ / // | / / "
echo "/_/ |_\____/_//_/|_|/_/ "
echo " "
echo "----------------------------------------------------${RESET}"
echo "${BOLD}${MAGENTA}Visit our documentation at https://AGiXT.com ${RESET}"
echo "${BOLD}${MAGENTA}Welcome to the AGiXT Environment Setup!${RESET}"
read -p "Do you want AGiXT to automatically update when launched? AGiXT Hubs always update automatically. (Y for yes, N for No): " auto_update
if [[ "$auto_update" == [Yy]* ]]; then
auto_update="true"
else
auto_update="false"
fi
read -p "Do you want to set an API key for AGiXT? (Y for yes, N for No): " use_api_key
if [[ "$use_api_key" == [Yy]* ]]; then
read -p "Enter API key: " api_key
fi
read -p "Do you have your own AGiXT Hub fork that you would like to install with? (Y for yes, N for No): " hub_repo
if [[ "$hub_repo" == [Yy]* ]]; then
read -p "Enter your AGiXT Hub fork repo name (e.g. AGiXT/light-hub): " github_repo
read -p "Is your AGiXT Hub fork private? It will require credentials if it is not public. (Y for yes, N for No): " is_private
if [[ "$is_private" == [Yy]* ]]; then
read -p "Enter your GitHub username: " github_username
read -p "Enter your GitHub token: " github_token
fi
fi
read -p "Enter the number of AGiXT workers to run with, default is 4: " workers
if [[ "$workers" != "" ]]; then
if [[ $workers =~ ^[0-9]+$ && $workers -gt 0 ]]; then
agixt_workers=$workers
else
echo "Invalid number of workers, defaulting to 4"
agixt_workers=4
fi
fi
read -p "Do you intend to run local models? (Y for yes, N for No): " local_models
if [[ "$local_models" == [Yy]* ]]; then
read -p "Do you want to use a local Text generation web UI? (Only works with NVIDIA currently) (Y for yes, N for No): " local_textgen
if [[ "$local_textgen" == [Yy]* ]]; then
read -p "Enter your CUDA version, you can find it here: https://developer.nvidia.com/cuda-gpus (Example: RTX3000-5000 series are version 7.5): " cuda_version
if [[ "$cuda_version" != "" ]]; then
if [[ $cuda_version =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "TORCH_CUDA_ARCH_LIST=${cuda_version:-7.5}" >> .env
fi
fi
cli_args_default='--listen --listen-host 0.0.0.0 --api --chat'
read -p "Default Text generation web UI startup parameters: ${cli_args_default} (prese Enter for defaults or overwrite with yours): " local_textgen_startup_params
echo "CLI_ARGS='${local_textgen_startup_params:-${cli_args_default}}'" >> .env
fi
fi
read -p "Do you want to use postgres? (Y for yes, N for No and to use file structure instead): " use_db
if [[ "$use_db" == [Yy]* ]]; then
db_connection="true"
read -p "Do you want to use an existing postgres database? (Y for yes, N for No and to create a new one automatically): " use_own_db
if [[ "$use_own_db" == [Yy]* ]]; then
read -p "Enter postgres host: " postgres_host
read -p "Enter postgres port: " postgres_port
read -p "Enter postgres database name: " postgres_database
read -p "Enter postgres username: " postgres_username
fi
read -p "Enter postgres password: " postgres_password
fi
echo "DB_CONNECTED=${db_connection:-false}" >> .env
echo "AGIXT_AUTO_UPDATE=${auto_update:-true}" >> .env
echo "AGIXT_HUB=${github_repo:-AGiXT/light-hub}" >> .env
echo "AGIXT_URI=${agixt_uri:-http://localhost:7437}" >> .env
echo "AGIXT_API_KEY=${api_key:-}" >> .env
echo "UVICORN_WORKERS=${agixt_workers:-4}" >> .env
echo "GITHUB_USER=${github_username:-}" >> .env
echo "GITHUB_TOKEN=${github_token:-}" >> .env
echo "POSTGRES_SERVER=${postgres_host:-db}" >> .env
echo "POSTGRES_PORT=${postgres_port:-5432}" >> .env
echo "POSTGRES_DB=${postgres_database:-postgres}" >> .env
echo "POSTGRES_USER=${postgres_username:-postgres}" >> .env
echo "POSTGRES_PASSWORD=${postgres_password:-postgres}" >> .env
fi
source .env
}
# Function to display the menu
display_menu() {
clear
echo "${BOLD}${CYAN}"
echo " ___ _______ _ ________"
echo " / | / ____(_) |/ /_ __/"
echo " / /| |/ / __/ /| / / / "
echo " / ___ / /_/ / // | / / "
echo "/_/ |_\____/_//_/|_|/_/ "
echo " "
echo "----------------------------------------------------${RESET}"
echo "${BOLD}${MAGENTA}Visit our documentation at https://AGiXT.com ${RESET}"
echo "${BOLD}${MAGENTA}Welcome to the AGiXT Installer!${RESET}"
echo "${BOLD}${GREEN}Please choose an option:${RESET}"
echo " ${BOLD}${YELLOW}1.${RESET} ${YELLOW}Run AGiXT with Docker (Recommended)${RESET}"
echo " ${BOLD}${YELLOW}2.${RESET} ${YELLOW}Run AGiXT Locally (Developers Only - Not Recommended or Supported) ${RESET}"
echo " ${BOLD}${YELLOW}3.${RESET} ${YELLOW}Run AGiXT and Text generation web UI with Docker (NVIDIA Only)${RESET}"
echo " ${BOLD}${YELLOW}4.${RESET} ${YELLOW}Update AGiXT ${RESET}"
echo " ${BOLD}${RED}5.${RESET} ${RED}Wipe AGiXT Hub (Irreversible)${RESET}"
echo " ${BOLD}${RED}6.${RESET} ${RED}Exit${RESET}"
echo ""
}
# Function to perform the Update
update() {
echo "${BOLD}${GREEN}Running Updates...${RESET}"
echo "${BOLD}${YELLOW}Updating AGiXT Core...${RESET}"
git pull
echo "${BOLD}${YELLOW}Updating AGiXT Streamlit Web UI...${RESET}"
if [ ! -d "streamlit" ]; then
git clone https://github.com/AGiXT/streamlit
fi
cd streamlit
git pull
cd ..
# Check if TORCH_CUDA_ARCH_LIST is defined from the env, only update Text generation web UI if it is.
if [[ -z "${TORCH_CUDA_ARCH_LIST}" ]]; then
echo "${BOLD}${YELLOW}Please wait...${RESET}"
else
if [ ! -d "text-generation-webui" ]; then
echo "${BOLD}${YELLOW}Updating Oobabooga Text generation web UI Repository...${RESET}"
git clone https://github.com/oobabooga/text-generation-webui
fi
cd text-generation-webui
git pull
cd ..
fi
echo "${BOLD}${YELLOW}Updating Docker Images...${RESET}"
docker-compose pull
echo "${BOLD}${YELLOW}Updates Completed...${RESET}"
}
# Function to perform the Docker install
docker_install() {
sed -i '/^AGIXT_URI=/d' .env
echo "AGIXT_URI=http://agixt:7437" >> .env
sed -i '/^TEXTGEN_URI=/d' .env
echo "TEXTGEN_URI=http://text-generation-webui:5000" >> .env
source .env
if [[ "$AGIXT_AUTO_UPDATE" == "true" ]]; then
update
fi
if [ ! -d "streamlit" ]; then
echo "${BOLD}${YELLOW}Cloning Streamlit Repository...${RESET}"
git clone https://github.com/AGiXT/streamlit
fi
echo "${BOLD}${GREEN}Running Docker install...${RESET}"
echo "${BOLD}${YELLOW}Starting Docker Compose...${RESET}"
if [[ "$DB_CONNECTED" == "true" ]]; then
docker-compose -f docker-compose-postgres.yml up
else
docker-compose up
fi
}
# Function to perform the Docker install
docker_install_local_nvidia() {
sed -i '/^AGIXT_URI=/d' .env
echo "AGIXT_URI=http://agixt:7437" >> .env
sed -i '/^TEXTGEN_URI=/d' .env
echo "TEXTGEN_URI=http://text-generation-webui:5000" >> .env
source .env
# Check if TORCH_CUDA_ARCH_LIST is defined from the env, ask user to enter it if not.
if [[ -z "${TORCH_CUDA_ARCH_LIST}" ]]; then
echo "${BOLD}${YELLOW}Please enter your CUDA version, you can find it here: https://developer.nvidia.com/cuda-gpus (Example: RTX3000-5000 series are version 7.5): ${RESET}"
read -p "Enter your CUDA version: " cuda_version
if [[ "$cuda_version" != "" ]]; then
if [[ $cuda_version =~ ^[0-9]+\.[0-9]+$ ]]; then
echo "TORCH_CUDA_ARCH_LIST=${cuda_version}" >> .env
fi
fi
fi
# Check if nvidia-container-toolkit is installed
if dpkg -l | grep -iq "nvidia-container-toolkit"; then
echo "Confirmed NVIDIA Container Toolkit is installed."
else
echo "NVIDIA Container Toolkit is not installed. Installing now..."
# Install a new GPU Docker container
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
echo "NVIDIA Container Toolkit has been installed."
fi
if [[ "$AGIXT_AUTO_UPDATE" == "true" ]]; then
update
fi
if [ ! -d "streamlit" ]; then
echo "${BOLD}${YELLOW}Cloning Streamlit Repository...${RESET}"
git clone https://github.com/AGiXT/streamlit
fi
if [ ! -d "text-generation-webui" ]; then
echo "${BOLD}${YELLOW}Cloning Oobabooga Text generation web UI Repository...${RESET}"
git clone https://github.com/oobabooga/text-generation-webui
fi
echo "${BOLD}${GREEN}Running Docker install...${RESET}"
echo "${BOLD}${YELLOW}Starting Docker Compose...${RESET}"
if [[ "$DB_CONNECTED" == "true" ]]; then
docker-compose -f docker-compose-postgres-local-nvidia.yml up
else
docker-compose -f docker-compose-local-nvidia.yml up
fi
}
# Function to perform the local install
local_install() {
sed -i '/^AGIXT_URI=/d' .env
echo "AGIXT_URI=http://localhost:7437" >> .env
sed -i '/^TEXTGEN_URI=/d' .env
echo "TEXTGEN_URI=http://localhost:5000" >> .env
source .env
if [[ "$AGIXT_AUTO_UPDATE" == "true" ]]; then
echo "${BOLD}${YELLOW}Checking for updates...${RESET}"
git pull
if [ ! -d "streamlit" ]; then
echo "${BOLD}${YELLOW}Installing Streamlit dependencies...${RESET}"
git clone https://github.com/AGiXT/streamlit
fi
cd streamlit
git pull
cd ..
fi
echo "${BOLD}${GREEN}Running local install...${RESET}"
echo "${BOLD}${YELLOW}Updating the repository...${RESET}"
git pull
sleep 1
# Check if the directory exists
if [ ! -d "agixt/providers" ]; then
echo "${BOLD}${YELLOW}Upgrading pip...${RESET}"
pip install --upgrade pip
sleep 1
echo "${BOLD}${YELLOW}Installing requirements...${RESET}"
pip install -r static-requirements.txt
sleep 1
pip install -r requirements.txt
sleep 1
echo "${BOLD}${YELLOW}Installing Playwright dependencies...${RESET}"
playwright install --with-deps
sleep 1
fi
if [ ! -d "streamlit" ]; then
echo "${BOLD}${YELLOW}Installing Streamlit dependencies...${RESET}"
git clone https://github.com/AGiXT/streamlit
cd streamlit
pip install -r requirements.txt
sleep 1
fi
echo "${BOLD}${YELLOW}Running AGiXT Core...${RESET}"
cd agixt && ./launch-backend.sh &
echo "${BOLD}${YELLOW}Please wait...${RESET}"
sleep 10
echo "${BOLD}${YELLOW}Running Streamlit Web UI...${RESET}"
cd streamlit && streamlit run Main.py
}
wipe_hub() {
read -p "Are you sure you want to wipe your AGiXT Hub? This is irreversible. (Y for yes, N for No): " wipe_hub
if [[ "$wipe_hub" == [Yy]* ]]; then
docker-compose down --remove-orphans
echo "${BOLD}${YELLOW}Wiping AGiXT Hub...${RESET}"
files=(
"agixt/extensions"
"agixt/chains"
"agixt/.github"
"agixt/prompts"
"agixt/providers"
"agixt/LICENSE"
"agixt/README.md"
"agixt/"*_main.zip
)
# Recursively delete files and folders
for file in "${files[@]}"; do
if [ -e "$file" ]; then
echo "Deleting: $file"
rm -rf "$file"
else
echo "File or folder not found: $file"
fi
done
fi
}
environment_setup
# Main loop to display the menu and handle user input
while true; do
display_menu
read -p "${BOLD}${CYAN}Enter your choice:${RESET} " choice
case "$choice" in
1)
docker_install
break
;;
2)
local_install
break
;;
3)
docker_install_local_nvidia
break
;;
4)
update
echo "${BOLD}${GREEN}Update complete.${RESET}"
sleep 2
;;
5)
wipe_hub
break
;;
*)
echo "${BOLD}${MAGENTA}Thank you for using AGiXT Installer. Goodbye!${RESET}"
break
;;
esac
done