wantt / midjourney-api

midjourney in discord api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

midjourney-api

基于 Discord 的 Midjourney API。

使用教程参考:Midjourney|如何集成到自己的平台

UML

sequenceDiagram
    participant ThirdServer
    participant APIServer
    participant DiscordAPI

    ThirdServer->>APIServer: 请求接口传入提示词
    APIServer->>DiscordAPI: 调接口触发绘画任务
    APIServer-->>ThirdServer: 返回是否触发成功

    DiscordAPI->>DiscordAPI: 触发Midjourney bot绘画任务
    DiscordAPI->>DiscordAPI: 监听MidJourney bot消息
    DiscordAPI-->>APIServer: 返回监听实时消息

	APIServer-->>ThirdServer: 回调,传输结果

安装启动

git clone
pip install -r requirements.txt

将文件.env.template重命名为.env,并填入参数值:

USER_TOKEN=用户token
BOT_TOKEN=机器人token
GUILD_ID=服务器ID
CHANNEL_ID=频道ID
CALLBACK_URL=回调地址,默认http post请求

直接启动

# 启动监听机器人
python task_bot.py
# 启动http服务
python server.py

docker 启动

填写 start.sh-e 后的环境变量,直接启动:

sh start.sh

或者本地构建镜像:

# 构建镜像
sh build.sh
# 启动容器
sh start.sh

接口swagger文档:http://127.0.0.1:8062/docs

midjourney-api 提供接口:

  • /v1/api/trigger/imagine:触发绘画任务
  • /v1/api/trigger/upscale:U
  • /v1/api/trigger/variation:V
  • /v1/api/trigger/reset:重绘
  • /v1/api/upload:上传图片,触发任务,待开发

使用

imagine

curl -X 'POST' \
  'http://127.0.0.1:8062/v1/api/trigger/imagine' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "prompt": "a cute cat"
}'

upscale

curl -X 'POST' \
  'http://127.0.0.1:8062/v1/api/trigger/upscale' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "index": 1,
  "msg_id": "xxxxxxxxxx",
  "msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
  "trigger_id": "xxxxxxxxxx"
}'
  • index: 图片索引,取值:1、2、3、4
  • msg_id: imagine 绘画完成后回调报文 id 字段
  • msg_hash: imagine 绘画完成后回调报文 attachments[0].filename.split("_")[-1].split(".").[0]
  • trigger_id: imagine 绘画完成后回调报文 trigger_id 字段

variation

curl -X 'POST' \
  'http://127.0.0.1:8062/v1/api/trigger/variation' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "index": 2,
  "msg_id": "xxxxxxxxxx",
  "msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
  "trigger_id": "xxxxxxxxxx"
}'

reset

curl -X 'POST' \
  'http://127.0.0.1:8062/v1/api/trigger/reset' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "msg_id": "xxxxxxxxxx",
  "msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
  "trigger_id": "xxxxxxxxxx"
}'

功能

  • 文生图
  • upscale
  • variation
  • reset
  • 图生图

enjoy it


About

midjourney in discord api


Languages

Language:Python 95.0%Language:Shell 3.4%Language:Dockerfile 1.6%