-
-
Notifications
You must be signed in to change notification settings - Fork 406
/
setup.sh
476 lines (424 loc) · 14.6 KB
/
setup.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/bin/bash
# Exit on any error
set -e
# Function to print messages
print_message() {
echo "==> $1"
}
# Function to print usage
print_usage() {
echo "Usage: $0 [-u|--ui] [-c|--chat] [-d|--code] [-r|--realtime] [-a|--all] [--run] [--quick] [--model MODEL] [--base URL]"
echo "Options:"
echo " -u, --ui Install UI dependencies for Multi Agents (CrewAI/AutoGen)"
echo " -c, --chat Install Chat interface for single AI Agent"
echo " -d, --code Install Code interface for codebase interaction"
echo " -r, --realtime Install Realtime voice interaction interface"
echo " -a, --all Install all interfaces"
echo " --run Run the interface after installation"
echo " --quick Quick start the UI interface with chainlit"
echo " --model Set custom model name (e.g., mistral-large)"
echo " --base Set custom API base URL (e.g., https://api.mistral.ai/v1)"
echo " --cicd Run in CI/CD mode (skip repository cloning)"
echo " -h, --help Show this help message"
}
# Function to prompt for OpenAI API key if not set
check_openai_key() {
if [ -z "$OPENAI_API_KEY" ]; then
print_message "OpenAI API key not found"
read -p "Enter your API key: " api_key
export OPENAI_API_KEY="$api_key"
fi
}
# Function to setup model configuration
setup_model_config() {
if [ ! -z "$MODEL_NAME" ]; then
print_message "Setting custom model: $MODEL_NAME"
export OPENAI_MODEL_NAME="$MODEL_NAME"
fi
if [ ! -z "$API_BASE" ]; then
print_message "Setting custom API base: $API_BASE"
# Set both variables for compatibility
export OPENAI_API_BASE="$API_BASE"
export OPENAI_API_BASE_URL="$API_BASE"
fi
}
# Function to setup chainlit authentication
setup_chainlit() {
print_message "Setting up chainlit authentication..."
# Check if .env file exists
if [ ! -f .env ]; then
print_message "Creating new chainlit secret..."
touch .env
# Generate a secure random secret
SECRET=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32)
echo "CHAINLIT_AUTH_SECRET=\"$SECRET\"" > .env
fi
# Source the secret from .env
if [ -f .env ]; then
source .env
if [ -z "$CHAINLIT_AUTH_SECRET" ]; then
print_message "Error: CHAINLIT_AUTH_SECRET not found in .env file"
exit 1
else
print_message "Chainlit authentication configured successfully"
export CHAINLIT_AUTH_SECRET
fi
else
print_message "Error: Failed to create .env file"
exit 1
fi
}
# Function to run UI interface
run_ui_interface() {
check_openai_key
setup_model_config
if [[ $QUICK == true ]]; then
print_message "Quick starting UI interface with chainlit..."
setup_chainlit
praisonai ui
else
print_message "Starting UI interface..."
read -p "Use chainlit interface? (y/N): " use_chainlit
if [[ $use_chainlit =~ ^[Yy]$ ]]; then
setup_chainlit
praisonai ui
else
read -p "Enter your initial prompt (or press enter for default): " prompt
if [ -z "$prompt" ]; then
prompt="create a movie script about dog in moon"
fi
read -p "Use AutoGen framework? (y/N): " use_autogen
if [[ $use_autogen =~ ^[Yy]$ ]]; then
praisonai --framework autogen --init "$prompt"
else
praisonai --init "$prompt"
fi
fi
fi
}
# Function to run Chat interface
run_chat_interface() {
check_openai_key
setup_model_config
print_message "Starting Chat interface..."
python3 -m praisonai chat
}
# Function to run Code interface
run_code_interface() {
check_openai_key
setup_model_config
print_message "Starting Code interface..."
praisonai code
}
# Function to run Realtime interface
run_realtime_interface() {
check_openai_key
setup_model_config
print_message "Starting Realtime voice interaction..."
python3 -m praisonai realtime
}
# Function to check system dependencies
check_system_deps() {
print_message "Checking system dependencies..."
# Check RHEL version
if [ -f /etc/redhat-release ]; then
RHEL_VERSION=$(cat /etc/redhat-release)
print_message "Detected Red Hat Enterprise Linux: $RHEL_VERSION"
# Extract major version number
RHEL_MAJOR=$(echo "$RHEL_VERSION" | grep -oP '(?<=release )\d+')
if [ -z "$RHEL_MAJOR" ] || [ "$RHEL_MAJOR" -lt 9 ]; then
print_message "Warning: This script is tested on RHEL 9.x. Your version: $RHEL_VERSION"
read -p "Do you want to continue? (y/N): " continue_install
if [[ ! $continue_install =~ ^[Yy]$ ]]; then
print_message "Installation aborted by user"
exit 1
fi
fi
fi
# Detect package manager
if command -v dnf &> /dev/null; then
PKG_MANAGER="dnf"
elif command -v apt-get &> /dev/null; then
PKG_MANAGER="apt"
else
print_message "Unsupported package manager. This script supports Fedora (dnf) and Debian/Ubuntu (apt)."
exit 1
fi
# Install specifically
if [ "$PKG_MANAGER" = "dnf" ]; then
print_message "Installing Python 3.11 and pip..."
# For RHEL systems
if [ -f /etc/redhat-release ]; then
# Enable EPEL repository for RHEL 9
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm
# Update package list
sudo dnf update -y
# Install Python 3.11
if ! sudo dnf install -y python3.11; then
print_message "Python 3.11 not found in default repositories. Trying alternative installation..."
# Try installing from EPEL
sudo dnf install -y python3.11 || {
print_message "Failed to install Python 3.11. Please install manually."
exit 1
}
fi
else
# For other dnf-based systems (Fedora)
sudo dnf update -y
sudo dnf install -y python3.11
fi
# Install pip
sudo dnf install -y python3-pip
# Try to set Python 3.11 as default if it exists
if [ -f "/usr/bin/python3.11" ]; then
sudo alternatives --set python3 /usr/bin/python3.11 || true
fi
else
print_message "Installing Python 3.11 and pip..."
# Install Python 3.11 without using add-apt-repository
echo "deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F23C5A6CF475977595C89F51BA6932366A755776
sudo apt-get update || true # Continue even if there are some update errors
# Install required packages
sudo apt-get install -y python3.11 python3.11-venv python3.11-distutils
# Set Python 3.11 as the default python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo update-alternatives --set python3 /usr/bin/python3.11
fi
# Verify Python version is exactly 3.11
PYTHON_VERSION=$(python3 --version)
if [[ ! $PYTHON_VERSION =~ "Python 3.11" ]]; then
print_message "Error: Python version must be 3.11. Current version: $PYTHON_VERSION"
exit 1
fi
# Check for poetry and add to PATH if needed
if ! command -v poetry &> /dev/null; then
print_message "Poetry not found. Installing with Python 3.11..."
curl -sSL https://install.python-poetry.org | python3.11 -
export PATH="$HOME/.local/bin:$PATH"
source $HOME/.profile
fi
# Verify poetry installation
if ! command -v poetry &> /dev/null; then
print_message "Failed to install Poetry. Please install it manually."
exit 1
fi
}
# Function to setup virtual environment
setup_venv() {
print_message "Setting up virtual environment..."
# Skip venv setup if running in CI/CD mode
if [[ "$CICD" == "true" ]]; then
print_message "Running in CI/CD mode, skipping venv setup..."
return 0
fi
# Only run these steps for local development
poetry config virtualenvs.in-project true
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
poetry install --no-root
fi
# Activate virtual environment
source .venv/bin/activate
}
# Function to check and install interface dependencies
install_interface_deps() {
# Skip if poetry.lock exists (dependencies already installed)
if [ -f "poetry.lock" ]; then
print_message "Dependencies for $1 interface already installed. Skipping..."
return
fi
if [[ $1 == "ui" ]]; then
print_message "Installing UI interface dependencies..."
poetry install -E ui -E crewai -E autogen
elif [[ $1 == "chat" ]]; then
print_message "Installing Chat interface dependencies..."
poetry install -E chat
elif [[ $1 == "code" ]]; then
print_message "Installing Code interface dependencies..."
poetry install -E code
elif [[ $1 == "realtime" ]]; then
print_message "Installing Realtime interface dependencies..."
poetry install -E realtime
fi
}
# Parse command line arguments
UI=false
CHAT=false
CODE=false
REALTIME=false
RUN=false
QUICK=false
CICD=false
TAG="v2.0.16"
MODEL_NAME=""
API_BASE=""
while [[ $# -gt 0 ]]; do
case $1 in
--cicd)
CICD=true
shift
;;
-u|--ui)
UI=true
shift
;;
-c|--chat)
CHAT=true
shift
;;
-d|--code)
CODE=true
shift
;;
-r|--realtime)
REALTIME=true
shift
;;
-a|--all)
UI=true
CHAT=true
CODE=true
REALTIME=true
shift
;;
--run)
RUN=true
shift
;;
--quick)
QUICK=true
UI=true
RUN=true
shift
;;
--model)
shift
MODEL_NAME="$1"
shift
;;
--base)
shift
API_BASE="$1"
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
print_message "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Clone repository and checkout tag if not in CICD mode
if [[ $CICD == false ]]; then
print_message "Cloning PraisonAI repository and checking out ${TAG}..."
if [ ! -d "PraisonAI" ]; then
git clone https://github.com/MervinPraison/PraisonAI.git
cd PraisonAI
git checkout ${TAG}
else
cd PraisonAI
git checkout ${TAG}
fi
fi
# If no options specified, show usage
if [[ $UI == false && $CHAT == false && $CODE == false && $REALTIME == false ]]; then
print_message "No interface selected"
print_usage
exit 1
fi
# Detect OS and check dependencies only if installation is needed
if [[ $UI == true || $CHAT == true || $CODE == true || $REALTIME == true ]]; then
check_system_deps
setup_venv
# Install interface-specific dependencies only if needed
if [[ $UI == true ]]; then
install_interface_deps "ui"
fi
if [[ $CHAT == true ]]; then
install_interface_deps "chat"
fi
if [[ $CODE == true ]]; then
install_interface_deps "code"
fi
if [[ $REALTIME == true ]]; then
install_interface_deps "realtime"
fi
# Check if praisonai is already installed
if ! pip show praisonai &> /dev/null; then
print_message "Installing PraisonAI components..."
pip install praisonai
pip install praisonaiagents
# Install only the required components based on selected interfaces
components=()
[[ $UI == true ]] && components+=("ui" "crewai" "autogen")
[[ $CHAT == true ]] && components+=("chat")
[[ $CODE == true ]] && components+=("code")
[[ $REALTIME == true ]] && components+=("realtime")
# Install selected components
for component in "${components[@]}"; do
pip install "praisonai[$component]"
done
else
print_message "PraisonAI is already installed. Skipping installation."
fi
print_message "Setup completed successfully!"
fi
# Run interfaces if requested
if [[ $RUN == true ]]; then
# Check for OPENAI_API_KEY
if [ -z "$OPENAI_API_KEY" ]; then
print_message "OpenAI API key not found. Please set it before running interfaces."
print_message "You can set it by running: export OPENAI_API_KEY='your-api-key'"
exit 1
fi
if [[ $UI == true ]]; then
run_ui_interface
fi
if [[ $CHAT == true ]]; then
run_chat_interface
fi
if [[ $CODE == true ]]; then
run_code_interface
fi
if [[ $REALTIME == true ]]; then
run_realtime_interface
fi
else
# Display next steps and current configuration
print_message "Configuration:"
if [ ! -z "$OPENAI_API_KEY" ]; then
echo "API Key: [Set]"
fi
if [ ! -z "$MODEL_NAME" ]; then
echo "Model: $MODEL_NAME"
fi
if [ ! -z "$API_BASE" ]; then
echo "API Base: $API_BASE"
fi
print_message "Next steps:"
if [[ $UI == true ]]; then
echo "- To start the UI interface:"
echo " Quick start: ./setup.sh --quick"
echo " Interactive: ./setup.sh -u --run"
echo " With custom model: ./setup.sh --quick --model mistral-large --base https://api.mistral.ai/v1"
echo " Or visit: https://docs.praison.ai/ui/ui"
fi
if [[ $CHAT == true ]]; then
echo "- To start the Chat interface: ./setup.sh -c --run"
echo " Or visit: https://docs.praison.ai/ui/chat"
fi
if [[ $CODE == true ]]; then
echo "- To start the Code interface: ./setup.sh -d --run"
echo " Or visit: https://docs.praison.ai/ui/code"
fi
if [[ $REALTIME == true ]]; then
echo "- To start the Realtime interface: ./setup.sh -r --run"
echo " Or visit: https://docs.praison.ai/ui/realtime"
fi
fi