Skip to content

Agent Zero AI framework

Preload fix

frdel2b94af895d51
diff --git a/docker/run/fs/exe/initialize.sh b/docker/run/fs/exe/initialize.sh
index 03cfdaf4f..a61e0566a 100644
--- a/docker/run/fs/exe/initialize.sh
+++ b/docker/run/fs/exe/initialize.sh
@@ -21,10 +21,10 @@ apt-get update &
/usr/sbin/sshd -D &
# Start searxng server in background
-sudo -H -u searxng -i bash /exe/run_searxng.sh &
+su - searxng -c "bash /exe/run_searxng.sh" &
# Start A0 and restart on exit
-bash /exe/run_A0.sh
+bash /exe/run_A0.sh "$@"
if [ $? -ne 0 ]; then
echo "A0 script exited with an error. Restarting container..."
exit 1
diff --git a/docker/run/fs/exe/run_A0.sh b/docker/run/fs/exe/run_A0.sh
index c0ff26bb1..80aaea7fe 100644
--- a/docker/run/fs/exe/run_A0.sh
+++ b/docker/run/fs/exe/run_A0.sh
@@ -6,15 +6,7 @@ TARGET_DIR="/a0"
function setup_venv() {
- # Create virtual environment if it doesn't exist
- if [ ! -d /opt/venv ]; then
- echo "Creating virtual environment..."
- python3 -m venv /opt/venv
- /opt/venv/bin/pip install ipython requests
- fi
-
- # Activate the virtual environment
- source /opt/venv/bin/activate
+ . "/ins/setup_venv.sh" "$@"
}
function clone_repo() {
diff --git a/docker/run/fs/ins/install_A0.sh b/docker/run/fs/ins/install_A0.sh
index cd96a8416..d4dd231d3 100644
--- a/docker/run/fs/ins/install_A0.sh
+++ b/docker/run/fs/ins/install_A0.sh
@@ -7,22 +7,11 @@ if [ -z "$1" ]; then
fi
BRANCH="$1"
-
+# clone project repo branch
git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero"
-
-# Create and activate Python virtual environment
-python3 -m venv /opt/venv
-source /opt/venv/bin/activate
-
-# Ensure the virtual environment and pip setup
-pip install --upgrade pip ipython requests
-
-# Install some packages in specific variants
-pip install torch --index-url https://download.pytorch.org/whl/cpu
-
-# Install remaining A0 python packages
-pip install -r /git/agent-zero/requirements.txt
+# setup python environment
+. "/ins/setup_venv.sh" "$@"
# Preload A0
-python /git/agent-zero/preload.py
+python /git/agent-zero/preload.py --dockerized=true
\ No newline at end of file
diff --git a/docker/run/fs/ins/install_A02.sh b/docker/run/fs/ins/install_A02.sh
index 9dab41592..2bc74757b 100644
--- a/docker/run/fs/ins/install_A02.sh
+++ b/docker/run/fs/ins/install_A02.sh
@@ -7,5 +7,5 @@ rm -rf /git/agent-zero
bash /ins/install_A0.sh "$@"
# remove python packages cache
-source /opt/venv/bin/activate
+. "/ins/setup_venv.sh" "$@"
pip cache purge
\ No newline at end of file
diff --git a/docker/run/fs/ins/install_additional.sh b/docker/run/fs/ins/install_additional.sh
index 8d017d160..e857ef471 100644
--- a/docker/run/fs/ins/install_additional.sh
+++ b/docker/run/fs/ins/install_additional.sh
@@ -1,4 +1,4 @@
#!/bin/bash
-# run the original install script again
+# searxng
bash /ins/install_searxng.sh "$@"
\ No newline at end of file
diff --git a/docker/run/fs/ins/install_searxng.sh b/docker/run/fs/ins/install_searxng.sh
index 8edf0aaa4..fdc7775ad 100644
--- a/docker/run/fs/ins/install_searxng.sh
+++ b/docker/run/fs/ins/install_searxng.sh
@@ -1,17 +1,23 @@
#!/bin/bash
-sudo -H apt-get install -y \
+# Install necessary packages
+apt-get install -y \
python3-dev python3-babel python3-venv \
uwsgi uwsgi-plugin-python3 \
git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev
-sudo -H useradd --shell /bin/bash --system \
+# Add the searxng system user
+useradd --shell /bin/bash --system \
--home-dir "/usr/local/searxng" \
--comment 'Privacy-respecting metasearch engine' \
searxng
-sudo -H mkdir "/usr/local/searxng"
-sudo -H chown -R "searxng:searxng" "/usr/local/searxng"
+# Add the searxng user to the sudo group
+usermod -aG sudo searxng
-# Start a new shell from new created user and clone SearXNG:
-sudo -H -u searxng -i bash /ins/install_searxng2.sh
+# Create the searxng directory and set ownership
+mkdir "/usr/local/searxng"
+chown -R "searxng:searxng" "/usr/local/searxng"
+
+# Start a new shell as the searxng user and run the installation script
+su - searxng -c "bash /ins/install_searxng2.sh"
\ No newline at end of file
diff --git a/docker/run/fs/ins/setup_venv.sh b/docker/run/fs/ins/setup_venv.sh
new file mode 100644
index 000000000..1a403d45d
--- /dev/null
+++ b/docker/run/fs/ins/setup_venv.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [ ! -d /opt/venv ]; then
+ # Create and activate Python virtual environment
+ python3 -m venv /opt/venv
+ source /opt/venv/bin/activate
+
+ # Ensure the virtual environment and pip setup
+ pip install --upgrade pip ipython requests
+
+ # Install some packages in specific variants
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
+
+ # Install remaining A0 python packages
+ pip install -r /git/agent-zero/requirements.txt
+else
+ source /opt/venv/bin/activate
+fi
\ No newline at end of file
diff --git a/preload.py b/preload.py
index d6e75663f..f5c77fc97 100644
--- a/preload.py
+++ b/preload.py
@@ -6,12 +6,15 @@ runtime.initialize()
async def preload():
- set = settings.get_default_settings()
+ try:
+ set = settings.get_default_settings()
- # async tasks to preload
- tasks = [whisper.preload(set["stt_model_size"])]
+ # async tasks to preload
+ tasks = [whisper.preload(set["stt_model_size"])]
- return asyncio.gather(*tasks, return_exceptions=True)
+ return asyncio.gather(*tasks, return_exceptions=True)
+ except Exception as e:
+ print(f"Error in preload: {e}")
# preload transcription model
diff --git a/prepare.py b/prepare.py
index 062ac633d..1853ca16e 100644
--- a/prepare.py
+++ b/prepare.py
@@ -3,11 +3,17 @@ import string
import random
print("Preparing environment...")
-runtime.initialize()
-
-# generate random root password if not set (for SSH)
-root_pass = dotenv.get_dotenv_value(dotenv.KEY_ROOT_PASSWORD)
-if not root_pass:
- root_pass = ''.join(random.choices(string.ascii_letters + string.digits, k=32))
-print("Changing root password...")
-settings.set_root_password(root_pass)
\ No newline at end of file
+
+try:
+
+ runtime.initialize()
+
+ # generate random root password if not set (for SSH)
+ root_pass = dotenv.get_dotenv_value(dotenv.KEY_ROOT_PASSWORD)
+ if not root_pass:
+ root_pass = "".join(random.choices(string.ascii_letters + string.digits, k=32))
+ print("Changing root password...")
+ settings.set_root_password(root_pass)
+
+except Exception as e:
+ print(f"Error in preload: {e}")