Preload fix

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