BobMaster's Blog

生活的点滴-是热爱呀

为Matrix聊天室集成AI对话,GPT Vision以及作图机器人

这篇文章向大家介绍如何在Matrix聊天室里集成AI对话和作图机器人。

使用到的项目 matrix_chatgpt_bot: https://github.com/hibobmaster/matrix_chatgpt_bot

为了方便,我们采用docker部署机器人,SSH连上服务器后,假设工作目录是 /opt/matrix_bot ,在此目录下创建一个 compose.yaml 文件

services:
  app:
    image: hibobmaster/matrixchatgptbot:latest
    container_name: matrix_chatgpt_bot
    restart: unless-stopped
    volumes:
      - ./config.json:/app/config.json
      - ./sync_db:/app/sync_db
      # - ./element-keys.txt:/app/element-keys.txt
    networks:
      - matrix_network

networks:
  matrix_network:

然后创建一个空文件,用于当作数据库

touch sync_db

接着创建配置文件 config.json

{
    "homeserver": "https://matrix.qqs.tw",
    "user_id": "@ai:matrix.qqs.tw",
    "access_token": "xxxxxxxxxxxxxxxxxxxxxxx",
    "device_id": "xxxxxxxxxxxxx",
    "gpt_api_endpoint": "https://xxxxxxxxxxxxxxxxxxxxxx/v1/chat/completions",
    "openai_api_key": "xxxxxxxxxxxxxxxxxxxxxxxx",
    "image_generation_endpoint": "https://xxxxxxxxxxxxxxxxxxxxxx/v1/images/generations",
    "image_generation_backend": "localai",
    "gpt_model": "mistral",
    "gpt_vision_api_endpoint": "https://api.openai.com/v1/chat/completions",
    "gpt_vision_model": "gpt-4-vision-preview",
    "image_format": "webp"
}

这里简单解释一下

user_id: 机器人账号的用户名
access_token: 机器人账号访问element-web,关于->高级->访问令牌
device_id: 同上面的access_token对应,隐私安全->加密->会话ID
gpt_api_endpoint: 支持与openai api兼容的各种后端,去除该选项默认为官方接口
openai_api_key: 如果需要的话就填写在这里
gpt_model: AI对话所用到的模型,我这里是使用localai自建的,默认为gpt-3.5-turbo
image_generation_endpoint: 作图后端地址
image_generation_backend: openai或sdwui或localai,分别对应不同的服务
gpt_vision_api_endpoint: openai或自建localai的gpt vision后端地址
gpt_vision_model: openai的gpt-4-vision-preview或自建的llava等模型
image_format: AI作图附件上传到Matrix聊天室所使用的格式,jpeg或png或webp

更多详细配置见: https://github.com/hibobmaster/matrix_chatgpt_bot/wiki

都配置好后,我们启动容器

docker compose up

如果一切正常,Ctrl+C终止容器,最后将容器运行在后台模式

docker compose up -d

在聊天室中可以使用!help指令获取帮助,AI对话,GPT Vision以及作图的效果如下


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注


©BobMaster 2018~2024