lapis

lapis

理解以真实为本,但真实本身不会自动呈现

Deploying ChatGPT Bot on Feishu

Deploying ChatGPT Bot on Feishu#

date: April 7, 2023
slug: 21
status: Published
tags: Technology
type: Post

Project open source link: Open Source Link

Introduction and Features of the Bot#

FeishuX (GPT-3.5+DALL·E+Whisper) is an intelligent office assistant.

Features:#

  • 🗣 Voice Communication: Have private conversations with the bot
  • 💬 Multi-topic Conversations: Support private and group chat discussions on multiple topics, ensuring efficiency and coherence
  • 🖼 Text to Image: Support converting text to images and reverse image search
  • 🛖 Predefined Scenarios: Built-in rich scenario list for easy switching of AI roles
  • 🎭 Role-playing: Support scenario mode to add fun and creativity to discussions
  • 🔄 Context Preservation: Reply in the dialogue box to continue the discussion on the same topic
  • ⏰ Automatic Termination: Automatically end the conversation after a timeout, with support for clearing discussion history
  • 📝 Rich Text Cards: Support rich text card replies for more informative and colorful information
  • 👍 Interactive Feedback: Get instant feedback on the bot's processing results
  • 🎰 Balance Inquiry: Get real-time token consumption information
  • 🔙 History Rollback: Easily rollback to previous conversations and continue the discussion 🚧
  • 🔒 Administrator Mode: Built-in administrator mode for safer and more reliable usage 🚧
  • 🌐 Multi-token Load Balancing: Optimize high-frequency production-level API calls
  • ↩️ ️Support Reverse Proxy: Provide faster and more stable access experience for users in different regions
  • 📚 Interact with Feishu Documents: Become a super assistant for enterprise employees 🚧
  • 🎥 Instant PPT Conversion: Make your presentations easier with topic-to-PPT conversion 🚧
  • 📊 Table Analysis: Easily import Feishu tables to improve data analysis efficiency 🚧
  • 🍊 Private Data Training: Utilize company product information for secondary training of GPT to better meet individual customer needs 🚧

Project Features#

  • 🍏 Dialogue based on OpenAI-gpt-3.5-turbo API
  • 🍎 Integrated ChatGPT with Feishu and Feishu International Edition through Lark
  • 🥒 Support deployment through various channels such as Serverless cloud functions, local environment, Docker, and binary installation package
  • 🍋 Based on goCache key-value pair cache

Deployment Tutorial#

Open Ai#

This step requires obtaining the Open Ai API, which has been discussed before and will not be repeated here.

Project Deployment#

1. Docker Deployment#

docker run -d --restart=always --name feishu-chatgpt2 -p 9000:9000 -v /etc/localtime:/etc/localtim:ro  \
--env APP_ID=xxx \
--env APP_SECRET=xxx \
--env APP_ENCRYPT_KEY=xxx \
--env APP_VERIFICATION_TOKEN=xxx \
--env BOT_NAME=chatGpt \
--env OPENAI_KEY="sk-xxx1,sk-xxx2,sk-xxx3" \
--env API_URL=https://api.openai.com \
--env HTTP_PROXY="" \
dockerproxy.com/leizhenpeng/feishu-chatgpt:latest

Note

  • BOT_NAME is the name of the Feishu bot, for example, 韵酱的猫娘P60 E 青春探索版
  • OPENAI_KEY is the OpenAI key, multiple keys are separated by commas, for example, sk-xxx1,sk-xxx2,sk-xxx3
  • HTTP_PROXY is the proxy address of the host machine, for example, http://host.docker.internal:7890. If there is no proxy, it can be left unset.
  • API_URL is the OpenAI API endpoint, for example, https://api.openai.com. If there is no reverse proxy, it can be left unset.

Event callback URL: http://IP:9000/webhook/event Card callback URL: http://IP:9000/webhook/card Fill in these URLs in the Feishu backend later.

2. Docker Compose Deployment#

Edit docker-compose.yaml, configure the corresponding environment variables through the environment section (or mount the configuration file through volumes), and then run the following commands:

# Build the image
docker compose build

# Start the service
docker compose up -d

# Stop the service
docker compose down

Event callback URL: http://IP:9000/webhook/event Card callback URL: http://IP:9000/webhook/card

3. Deployment using Railway#

Simply configure the environment variables and deploy through the open source project address, I'm too lazy to write it.

Railway is a foreign Serverless platform that supports multiple languages. It allows you to deploy code repositories from Github to the Railway platform with just one click, and then configure the environment variables on the Railway platform.

This project also supports local deployment, serverless cloud function deployment, and binary installation package deployment, but I think Docker is convenient enough.

Feishu Bot Configuration#

Summary: Fill in the callback URL in the "Event Subscription" section and the request URL for message cards in the "Bot" section in the Feishu bot backend, and finally set the permissions for the bot.

1. Create an application on the developer platform and obtain the APPID and Secret#

2. Go to Application Features - Bot and create a bot#

3. Specific Configuration#

Event Subscription Obtain the public address from cpolar, serverless, or Railway, and fill it in the "Event Subscription" section in the Feishu bot backend. For example, http://xxxx.r6.cpolar.top is the public address exposed by cpolar, and /webhook/event is the unified application route. The final callback URL is http://xxxx.r6.cpolar.top/webhook/event**Card Messages** In the "Bot" section of the Feishu bot backend, fill in the request URL for message cards. For example, http://xxxx.r6.cpolar.top is the public address exposed by cpolar, and /webhook/card is the unified application route. The final request URL for message cards is http://xxxx.r6.cpolar.top/webhook/card**Bot Permissions** In the "Event Subscription" section, search for the three words "Bot Join Group", "Receive Messages", and "Message Read", and check all the permissions behind them. Go to the permission management page, search for images, and check "Get and upload image or file resources". Finally, the following callback events will be added:

  • im (Get and upload image or file resources)
  • im
  • im.group_at_msg (Get all messages in a group)
  • im.group_at_msg (Receive @bot messages in group chat)
  • im.p2p_msg (Get user-to-bot messages in private chat)
  • im.p2p_msg (Read user-to-bot messages in private chat)
  • im:message (Get messages where users @bot in a group)
  • im:chat (Get group information)
  • im (Get and update group information)

Publication#

After configuring the bot, publish it and wait for administrator approval.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.