基于 Discord 的 Midjourney API。
添加 Midjourney 违禁词入口 issue
项目集成 Demo 参考:issue31
sequenceDiagram
participant ThirdServer
participant APIServer
participant DiscordAPI
ThirdServer->>APIServer: 请求接口触发任务
APIServer->>APIServer: 放入任务队列
APIServer->>DiscordAPI: 调接口触发绘画任务
APIServer-->>ThirdServer: 返回是否触发成功
DiscordAPI->>DiscordAPI: 触发Midjourney bot绘画任务
DiscordAPI->>DiscordAPI: 监听MidJourney bot消息
DiscordAPI-->>ThirdServer: 返回监听实时消息
DiscordAPI-->>APIServer: 清除队列任务
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请求,用于接收 midjourney 作图进度和结果的服务
# 启动监听机器人
python task_bot.py
# 启动http服务
python server.py
git pull
# 启动监听机器人
python task_bot.py
# 启动http服务
python server.py
填写 start.sh 中 -e
后的环境变量,直接启动:
sh start.sh
或者本地构建镜像:
# 构建镜像
sh build.sh
# 启动容器
sh start.sh
docker rmi kunyu/midjourney-api:1.0
sh start.sh
接口swagger
文档:http://127.0.0.1:8062/docs
midjourney-api
提供接口:
/v1/api/trigger/imagine
:触发绘画任务(图生图,Prompt 前加上图片链接即可)/v1/api/trigger/upscale
:U/v1/api/trigger/variation
:V/v1/api/trigger/solo_variation
:Make Variations/v1/api/trigger/solo_low_variation
:Vary(Subtle)/v1/api/trigger/solo_high_variation
:Vary(Strong)/v1/api/trigger/zoomout
:Zoom Out 2x/1.5x/v1/api/trigger/expand
:⬅️ ➡️ ⬆️ ⬇️/v1/api/trigger/reset
:重绘/v1/api/trigger/upload
:上传图片/v1/api/trigger/describe
:通过上传图片名,生成 Prompt/v1/api/trigger/message
:发送图片消息,返回图片链接,用于图生图功能文生图
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"
}'
图生图,需带上图片 URL
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",
"picurl": "https://xxxxxx/xxxxxxxxxxxx.jpg"
}'
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、4msg_id
: imagine
绘画完成后回调报文 id
字段msg_hash
: imagine
绘画完成后回调报文 attachments[0].filename.split("_")[-1].split(".").[0]
trigger_id
: imagine
绘画完成后回调报文 trigger_id
字段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"
}'
对 upscale
的单张图片进行 "Make Variations" 操作
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_variation' \
-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
: 图片索引,此处无用,取值:1msg_id
: upscale
绘画完成后回调报文 id
字段msg_hash
: upscale
绘画完成后回调报文 attachments[0].filename.split("_")[-1].split(".").[0]
trigger_id
: upscale
绘画完成后回调报文 trigger_id
字段对 upscale
的单张图片进行 "Vary(Subtle)" 操作
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_low_variation' \
-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
: 图片索引,此处无用,取值:1msg_id
: upscale
绘画完成后回调报文 id
字段msg_hash
: upscale
绘画完成后回调报文 attachments[0].filename.split("_")[-1].split(".").[0]
trigger_id
: upscale
绘画完成后回调报文 trigger_id
字段对 upscale
的单张图片进行 "Vary(Strong)" 操作
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_high_variation' \
-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
: 图片索引,此处无用,取值:1msg_id
: upscale
绘画完成后回调报文 id
字段msg_hash
: upscale
绘画完成后回调报文 attachments[0].filename.split("_")[-1].split(".").[0]
trigger_id
: upscale
绘画完成后回调报文 trigger_id
字段对 upscale
的单张图片进行 Zoom Out 2x/1.5x 操作
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/zoomout' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"zoomout": 50
"trigger_id": "xxxxxxxxxx"
}'
zoomout
: 图片扩大(Outpaint)系数,2x -> 50、1.5x -> 75对 upscale
的单张图片进行某方向的扩展操作
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/expand' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"direction": "up"
"trigger_id": "xxxxxxxxxx"
}'
direction
: 图片扩大方向,取值:left/right/up/downcurl -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"
}'
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/upload' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@cH16Ifh.jpg;type=image/jpeg'
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/describe' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"upload_filename": "b56ca21a-5fbe-40b4-89ab-6e0aa732f561/9231228408.jpg",
"trigger_id": "9231228408"
}'
trigger_id
先用 upload 返回的 trigger_idupload_filename
upload 返回的文件名和 describe
一样,先 /v1/api/trigger/upload
上传图片,然后根据返回文件名,发送消息:
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/message' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"upload_filename": "560a1e26-36a2-4d5f-a48d-9dd877642b51/7185811546.jpg"
}'
发送图片后,会返回图片链接。
该链接用于以图生图中,拼接 Prompt 形如 图片URL Prompt
,调用 /v1/api/trigger/imagine
。