Skip to content

Commit

Permalink
corrected loyal agent
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Feb 18, 2025
1 parent 09a645a commit f34cc05
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

set -e

# Define variables
DOWNLOAD_URL="https://functionyard.fx.land/deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm"
MODEL_DIR="/uniondrive/loyal-agent/model"
MODEL_FILE="$MODEL_DIR/deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm"
LOG_FILE="$MODEL_DIR/wget.log"
SERVICE_NAME="loyal-agent.service"
SIZE_LIMIT=7500000000 # Size in bytes (7.5 GB)

# Create necessary directories
mkdir -p "$MODEL_DIR"

# Check if the model file exists
if [ -f "$MODEL_FILE" ]; then
# Get the file size in bytes
FILE_SIZE=$(stat -c%s "$MODEL_FILE")

# Compare the file size with the size limit
if [ "$FILE_SIZE" -lt "$SIZE_LIMIT" ]; then
echo "Model file exists but is smaller than $SIZE_LIMIT bytes. Deleting it..."
rm -f "$MODEL_FILE"
else
echo "Model file exists and meets the size requirement."
fi
else
echo "Model file does not exist."
fi

# Start downloading in the background
nohup wget -b -N -P "$MODEL_DIR" "$DOWNLOAD_URL" &> "$LOG_FILE" &
WGET_PID=$!

# Wait for the file to finish downloading
echo "Waiting for the file to be fully downloaded..."
RETRY_COUNT=0
while true; do
# Check if wget is still running
if pgrep -f "wget.*deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm" > /dev/null; then
echo "Download in progress..."
sleep 10 # Wait for 10 seconds before checking again
else
FILE_SIZE=0
if [ -f "$MODEL_FILE" ]; then
FILE_SIZE=$(stat -c%s "$MODEL_FILE")
fi
# Check if the file exists and is fully downloaded
if [ -f "$MODEL_FILE" ] && [ "$FILE_SIZE" -ge "$SIZE_LIMIT" ]; then
echo "File downloaded successfully."
break
else
echo "Download failed or incomplete."
if [ $RETRY_COUNT -lt 3 ]; then
echo "Retrying..."
kill "$WGET_PID" 2>/dev/null
nohup wget -b -N -P "$MODEL_DIR" "$DOWNLOAD_URL" &> "$LOG_FILE" &
WGET_PID=$!
RETRY_COUNT=$((RETRY_COUNT + 1))
else
echo "Max retries reached. Exiting."
exit 1
fi
fi
fi
done

# Start the service after download is complete
echo "Starting $SERVICE_NAME..."
systemctl restart "$SERVICE_NAME"
echo "Loyal agent installed successfully."

exit 0
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
loyal-agent:
image: functionland/loyal-agent:latest
container_name: loyal-agent
security_opt:
- systempaths=unconfined
devices:
Expand Down
4 changes: 4 additions & 0 deletions docker/fxsupport/linux/plugins/loyal-agent/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
{
"order": 2,
"description": "Click Install"
},
{
"order": 3,
"description": "After installation is finished, please give it some minutes to finalize downloading hte model before using it"
}
],
"requiredInputs": [
Expand Down
26 changes: 2 additions & 24 deletions docker/fxsupport/linux/plugins/loyal-agent/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ sudo bash ${PLUGIN_EXEC_DIR}/custom/fix_freq_rk3588.sh

mkdir -p /uniondrive/loyal-agent
mkdir -p /uniondrive/loyal-agent/model
nohup wget -b -N -P /uniondrive/loyal-agent/model/ https://functionyard.fx.land/deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm &> /uniondrive/loyal-agent/model/wget.log &

# Copy service file
cp "${PLUGIN_EXEC_DIR}/loyal-agent.service" "/etc/systemd/system/"
Expand All @@ -59,28 +58,7 @@ sleep 1
# Enable the service
systemctl enable loyal-agent.service

# Wait for the file to finish downloading
echo "Waiting for the file to be fully downloaded..."
while true; do
# Check if wget is still running
if pgrep -f "wget.*deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm" > /dev/null; then
echo "Download in progress..."
sleep 10 # Wait for 10 seconds before checking again
else
# Check if the file exists and is fully downloaded
if [ -f "/uniondrive/loyal-agent/model/deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm" ]; then
echo "File downloaded successfully."
break
else
echo "Download failed or incomplete. Exiting."
exit 1
fi
fi
done

echo "Loyal agent installed successfully."
sync
sleep 1
systemctl start loyal-agent.service
# Run the download and setup script in the background using nohup and &
nohup bash "${PLUGIN_EXEC_DIR}/custom/download_model.sh" &

exit 0
22 changes: 19 additions & 3 deletions docker/fxsupport/linux/plugins/loyal-agent/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ if systemctl is-active --quiet loyal-agent.service; then
exit 0
fi

# start the service
systemctl start loyal-agent.service
MODEL_DIR="/uniondrive/loyal-agent/model"
MODEL_FILE="$MODEL_DIR/deepseek-llm-7b-chat-rk3588-w8a8_g256-opt-1-hybrid-ratio-0.5.rkllm"
SIZE_LIMIT=7500000000 # Size in bytes (7.5 GB)

echo "Loyal agent started successfully."
# Wait for the file to finish downloading
echo "Checking for the file to be fully downloaded..."

FILE_SIZE=0
if [ -f "$MODEL_FILE" ]; then
FILE_SIZE=$(stat -c%s "$MODEL_FILE")
fi

if [ -f "$MODEL_FILE" ] && [ "$FILE_SIZE" -ge "$SIZE_LIMIT" ]; then
echo "File downloaded successfully."
# start the service
systemctl start loyal-agent.service
echo "Loyal agent started successfully."
else
echo "Download failed or incomplete."
fi

0 comments on commit f34cc05

Please sign in to comment.