Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Readme #394

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the command by using grep -c instead of grep | wc -l for counting occurrences.

- if [ "$(docker ps -a -f name=rabbitmq | grep rabbitmq | wc -l)" -eq 0 ]; then
+ if [ "$(docker ps -a -f name=rabbitmq | grep -c rabbitmq)" -eq 0 ]; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if [ "$(docker ps -a -f name=rabbitmq | grep rabbitmq | wc -l)" -eq 0 ]; then
if [ "$(docker ps -a -f name=rabbitmq | grep -c rabbitmq)" -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
Comment on lines +16 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that sensitive information such as the default RabbitMQ user password is not hardcoded in scripts. Consider using environment variables or secure vault solutions.

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!"
13 changes: 13 additions & 0 deletions llmkira/openai/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ def check_content(cls, v):
raise ValueError("content must be a string or a list of ContentPart")

def add_text(self, text: str):
"""
Add a text to the message
:param text: text
:return: self
"""
self.content.append(ContentPart.create_text(text=text))
return self

Expand All @@ -255,6 +260,14 @@ def add_image(
image_url: Union[str, bytes],
detail: Literal["low", "high", "auto"] = "auto",
):
"""
Add an image to the message
:param image_url: image url or image bytes
:param detail: image detail
:return: self
:raises ValueError: detail must be low, high or auto
:raises ValueError: url must be a http url or `data:image/jpeg;base64,` as base64 image
"""
self.content.append(ContentPart.create_image(url=image_url, detail=detail))
return self

Expand Down
5 changes: 4 additions & 1 deletion llmkira/task/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ async def format_user_message(self, name: str = None) -> UserMessage:
for file in self.files:
if file.file_name.endswith((".jpg", ".jpeg", ".png")):
file_bytes = await file.download_file()
content_list.append(ContentPart.create_image(file_bytes))
try:
content_list.append(ContentPart.create_image(file_bytes))
except Exception as e:
logger.error(f"Error when create image: {e}")
return UserMessage(
role="user",
name=name,
Expand Down
Loading