Skip to content

Commit

Permalink
🚧 refactor(cell): fix indentation and add docstrings
Browse files Browse the repository at this point in the history
🚀 refactor(task): handle exception when creating image and add logging
  • Loading branch information
sudoskys committed Apr 18, 2024
1 parent 00cbd7f commit fe102e2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 89 deletions.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ or [one-api](https://github.com/songquanpeng/one-api) independently.
### 🍔 Login Modes

- `Login via url`: Use `/login token$https://provider.com` to Login. The program posts the token to the interface to
retrieve configuration information
retrieve configuration
information, [how to develop this](https://github.com/LlmKira/Openaibot/blob/81eddbff0f136697d5ad6e13ee1a7477b26624ed/app/components/credential.py#L20).
- `Login`: Use `/login https://api.com/v1$key$model` to login

### 🧀 Plugin Previews
Expand Down Expand Up @@ -105,8 +106,18 @@ or [one-api](https://github.com/songquanpeng/one-api) independently.

Refer to the [🧀 Deployment Document](https://llmkira.github.io/Docs/) for more information.

### 📦 One-click Deployment

If you are using a brand-new server, you can use the following shell to automatically install this project.

```shell
curl -sSL https://raw.githubusercontent.com/LLMKira/Openaibot/main/deploy.sh | bash
```

### 📦 Manual Installation

```shell
# Install Telegram Voice dependencies
# Install Voice dependencies
apt install ffmpeg
# Install RabbitMQ
docker pull rabbitmq:3.10-management
Expand All @@ -118,30 +129,26 @@ docker run -d -p 5672:5672 -p 15672:15672 \
rabbitmq:3.10-management
docker ps -l
# Install Project
git clone https://github.com/LlmKira/Openaibot/
cd Openaibot
pip install pdm
pdm install -G bot
cp .env.exp .env && nano .env
# Test
pdm run python3 start_sender.py
pdm run python3 start_receiver.py
# Host
pdm start pm2.json
apt install npm
npm install pm2 -g
pm2 start pm2.json
```

### 🥣 Docker

Build Hub: [sudoskys/llmbot](https://hub.docker.com/repository/docker/sudoskys/llmbot/general)

#### Automatic Docker/Docker-compose Installation

If you are using a brand new server, you can use the following shell to automatically install this project.

This script automatically installs the required services and maps ports using Docker methods. If you have
deployed `redis`, `rabbitmq`, `mongodb`, please modify the `docker-compose.yml` file accordingly.

```shell
curl -sSL https://raw.githubusercontent.com/LLMKira/Openaibot/main/deploy.sh | bash
```
> Note that if you run this project using Docker, you will start Redis, MongoDB, and RabbitMQ. But if you're running
> locally, just RabbitMQ
#### Manual Docker-compose Installation

Expand Down
124 changes: 48 additions & 76 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,87 +1,59 @@
#!/bin/bash

# Check if the Openaibot directory exists
echo "$(tput setaf 6)Checking the Openaibot directory...$(tput sgr0)"
if [ -d "Openaibot" ]; then
# shellcheck disable=SC2164
pip uninstall llmkira
cd Openaibot && git pull && echo "$(tput setaf 6)Update successfully...$(tput sgr0)"
docker-compose -f docker-compose.yml down
docker-compose -f docker-compose.yml pull
docker-compose -f docker-compose.yml up -d
# Update the Openaibot project
exit 0
else
# Clone the project if not already cloned
git clone https://github.com/LlmKira/Openaibot.git
fi

echo "$(tput setaf 2)Openaibot directory check complete.$(tput sgr0)"
echo "$(tput setaf 6)Type yes will install Docker and the Openaibot project. Do you want to proceed? (y/n):$(tput sgr0) "
read -r choice
if [[ $choice =~ ^([yY][eE][sS]|[yY])$ ]]; then
sleep 1s
echo "Beginning the setup process..."

# Install Voice dependencies
echo "Installing Voice dependencies..."
apt install ffmpeg

# Pull RabbitMQ
echo "Pulling RabbitMQ..."
docker pull rabbitmq:3.10-management

# Check if RabbitMQ container exists
if [ "$(docker ps -a -f name=rabbitmq | grep rabbitmq | wc -l)" -eq 0 ]; then
# Run the RabbitMQ if not exist
echo "Running RabbitMQ..."
docker run -d -p 5672:5672 -p 15672:15672 \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=8a8a8a \
--hostname myRabbit \
--name rabbitmq \
rabbitmq:3.10-management
else
echo "$(tput setaf 1)Installation cancelled.$(tput sgr0)"
exit 0
echo "RabbitMQ already exists. Using it..."
fi

# Function to handle errors and exit
handle_error() {
echo "$(tput setaf 1)Error occurred during installation. Exiting...$(tput sgr0)"
exit 1
}

# Set error trap
trap 'handle_error' ERR

# Check if Docker is installed
if ! [ -x "$(command -v docker)" ]; then
# Install Docker
echo "$(tput setaf 6)Installing Docker...$(tput sgr0)"
curl -fsSL https://get.docker.com | bash -s docker
else
echo "$(tput setaf 2)Docker already installed.$(tput sgr0)"
fi
docker ps -l

# Run Docker Compose
echo "$(tput setaf 6)Running Docker Compose...$(tput sgr0)"
# 检查是否安装docker-compose
if ! [ -x "$(command -v docker-compose)" ]; then
# Install Docker
echo "$(tput setaf 6)Installing docker-compose...$(tput sgr0)"
curl -L "https://github.com/docker/compose/releases/download/v2.14.0/docker-compose-linux-$(uname -m)" >/usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Clone or update the project
if [ ! -d "Openaibot" ] ; then
echo "Cloning Openaibot..."
git clone https://github.com/LlmKira/Openaibot/
cd Openaibot || exit
else
echo "$(tput setaf 2)docker-compose already installed.$(tput sgr0)"
fi
# Change directory to the project
cd Openaibot || echo "DO NOT Exist Openaibot Dir" && exit

# Install project dependencies
echo "$(tput setaf 6)Installing project dependencies...$(tput sgr0)"
python3 -m pip install poetry
poetry config virtualenvs.in-project true &&
poetry install --all-extras
python3 -m pip install rich loguru && python3 start_tutorial.py
echo "$(tput setaf 2)Project dependencies installation complete.$(tput sgr0)"

# Copy .env.exp to .env if .env doesn't exist
if [ ! -f ".env" ]; then
echo "$(tput setaf 6)Copying .env.example to .env...$(tput sgr0)"
cp .env.exp .env
nano .env
echo "$(tput setaf 2).env file copy complete.$(tput sgr0)"
echo "Updating Openaibot..."
cd Openaibot || exit
git pull
fi

if [ ! -f "docker-compose.yml" ]; then
echo "$(tput setaf 6)Run docker-compose.yml...$(tput sgr0)"
docker-compose -f docker-compose.yml up -d
echo "Setting up Python dependencies..."
pip install pdm
pdm install -G bot
cp .env.exp .env && nano .env

# Test
echo "Testing setup..."
pdm run python3 start_sender.py &
pdm run python3 start_receiver.py &

# Install or update pm2
if ! [ -x "$(command -v pm2)" ]; then
echo "Installing npm and pm2..."
apt install npm
npm install pm2 -g
fi

echo "$(tput setaf 2)Docker Compose completed with:docker-compose -f docker-compose.yml up -d$(tput sgr0)"

# Remove the error trap
trap - ERR
echo "Starting application with pm2..."
pm2 start pm2.json

echo "$(tput setaf 2)Installation completed successfully.$(tput sgr0)"
echo "Setup complete!"

0 comments on commit fe102e2

Please sign in to comment.