Coder Social home page Coder Social logo

jing-jing510 / midjourney-proxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from novicezk/midjourney-proxy

0.0 0.0 0.0 3.36 MB

代理 MidJourney 的discord频道,实现api形式调用AI绘图

Shell 2.49% Java 95.34% HTML 0.41% Dockerfile 1.77%

midjourney-proxy's Introduction

midjourney-proxy

代理 MidJourney 的discord频道,实现api形式调用AI绘图

现有功能

  • 支持 Imagine、U、V 指令,绘图完成后回调
  • 支持 Describe 指令,根据图片生成 prompt
  • 支持中文 prompt 翻译,需配置百度翻译或 gpt
  • prompt 敏感词判断,支持覆盖调整

后续计划

  • 任务队列 Issue
  • 支持mysql存储,优化任务的查询方式
  • 支持配置账号池,分发绘图任务
  • Imagine 时支持上传图片,作为垫图

使用前提

  1. 科学上网
  2. docker环境
  3. 注册 MidJourney,创建自己的频道,参考 https://docs.midjourney.com/docs/quick-start
  4. 添加自己的机器人: 流程说明

快速启动

  1. 下载镜像
docker pull novicezk/midjourney-proxy
  1. 启动容器,并设置参数
# /xxx/xxx/config目录下创建 application.yml(配置项)、banned-words.txt(可选,覆盖默认的敏感词文件)
# 参考src/main/resources下的文件
docker run -d --name midjourney-proxy \
 -p 8080:8080 \
 -v /xxx/xxx/config:/home/spring/config \
 --restart=always \
 novicezk/midjourney-proxy

# 或者直接在启动命令中设置参数
docker run -d --name midjourney-proxy \
 -p 8080:8080 \
 -e mj.discord.guild-id=xxx \
 -e mj.discord.channel-id=xxx \
 -e mj.discord.user-token=xxx \
 -e mj.discord.bot-token=xxx \
 --restart=always \
 novicezk/midjourney-proxy
  1. 访问 http://localhost:8080/mj 提示 "项目启动成功"
  2. 检查discord频道中新创建的机器人是否在线
  3. 调用api接口的根路径为 http://ip:port/mj,接口测试地址:http://ip:port/mj/doc.html,具体API接口见下文

注意事项

  1. 启动失败请检查全局代理或HTTP代理,排查 JDA 连接问题
  2. 若回调通知接口失败,请检查网络设置,容器中的宿主机IP通常为172.17.0.1
  3. Issues 中提出其他问题或建议
  4. 感兴趣的朋友也欢迎加入交流群讨论一下

交流群二维码

配置项

变量名 非空 描述
mj.discord.guild-id discord服务器ID
mj.discord.channel-id discord频道ID
mj.discord.user-token discord用户Token
mj.discord.bot-token 自定义机器人Token
mj.discord.mj-bot-name mj机器人名称,默认 "Midjourney Bot"
mj.notify-hook 任务状态变更回调地址
mj.task-store.type 任务存储方式,默认in_memory(内存\重启后丢失),可选redis
mj.task-store.timeout 任务过期时间,过期后删除,默认30天
mj.translate-way 中文prompt翻译方式,可选null(默认)、baidu、gpt
mj.baidu-translate.appid 百度翻译的appid
mj.baidu-translate.app-secret 百度翻译的app-secret
mj.openai.gpt-api-key gpt的api-key
mj.openai.timeout openai调用的超时时间,默认30秒
mj.openai.model openai的模型,默认gpt-3.5-turbo
mj.openai.max-tokens 返回结果的最大分词数,默认2048
mj.openai.temperature 相似度(0-2.0),默认0
spring.redis 任务存储方式设置为redis,需配置redis相关属性

API接口说明

1. http://ip:port/mj/trigger/submit 提交任务

POST application/json

{
    // 动作: 必传,IMAGINE(绘图)、UPSCALE(选中放大)、VARIATION(选中变换)
    "action":"IMAGINE",
    // 绘图参数: IMAGINE时必传
    "prompt": "猫猫",
    // 任务ID: UPSCALE、VARIATION时必传
    "taskId": "1320098173412546",
    // 图序号: 1~4,UPSCALE、VARIATION时必传,表示第几张图
    "index": 3,
    // 自定义字符串: 非必传,供回调到业务系统里使用
    "state": "test:22",
    // 支持每个任务配置不同回调地址,非必传
    "notifyHook": "http://localhost:8113/notify"
}

返回 Message,code=1表示提交成功,其他时description为错误描述

{
  "code": 1,
  "description": "成功",
  "result": "8498455807619990"
}

result: 任务ID,用于后续查询任务或提交变换任务

2. http://ip:port/mj/trigger/submit-uv 提交选中放大或变换任务

POST application/json

{
    // 自定义参数,非必传
    "state": "test:22",
    // 任务描述: 选中ID为1320098173412546的第2张图片放大
    // 放大 U1~U4 ,变换 V1~V4
    "content": "1320098173412546 U2",
    // 支持每个任务配置不同回调地址,非必传
    "notifyHook": "http://localhost:8113/notify"
}

返回结果同 /trigger/submit

3. http://ip:port/mj/trigger/describe 提交describe任务

POST application/json

{
    // 自定义参数,非必传
    "state": "test:22",
    // 图片的base64字符串
    "base64": "data:image/png;base64,xxx",
    // 支持每个任务配置不同回调地址,非必传
    "notifyHook": "http://localhost:8113/notify"
}

返回结果同 /trigger/submit

后续任务完成后,task中prompt即为图片生成的prompt

{
  "action":"DESCRIBE",
  "id":"3856553004865376",
  "prompt":"1️⃣ xxx1 --ar 5:4\n\n2️⃣ xxx2 --ar 5:4\n\n3️⃣ xxx3 --ar 5:4\n\n4️⃣ xxx4 --ar 5:4",
  "promptEn":"1️⃣ xxx1 --ar 5:4\n\n2️⃣ xxx2 --ar 5:4\n\n3️⃣ xxx3 --ar 5:4\n\n4️⃣ xxx4 --ar 5:4",
  "description":"/describe 3856553004865376.png",
  "state":"test:22",
  "submitTime":1683779732983,
  "finishTime":1683779741711,
  "imageUrl":"https://cdn.discordapp.com/ephemeral-attachments/xxxx/xxxx/3856553004865376.png",
  "status":"SUCCESS"
}

4. http://ip:port/mj/task/{id}/fetch GET 查询单个任务

{
    // 动作: IMAGINE(绘图)、UPSCALE(选中放大)、VARIATION(选中变换)
    "action":"IMAGINE",
    // 任务ID
    "id":"8498455807628990",
    // 绘图参数
    "prompt":"猫猫",
    // 翻译后的绘图参数
    "promptEn": "Cat",
    // 执行的命令
    "description":"/imagine 猫猫",
    // 自定义参数
    "state":"test:22",
    // 提交时间
    "submitTime":1682473784826,
    // 结束时间
    "finishTime":null,
    // 生成图片的url, 成功时有值
    "imageUrl":"https://cdn.discordapp.com/attachments/xxx/xxx/xxxx_xxxx.png",
    // 任务状态: NOT_START(未启动)、IN_PROGRESS(执行中)、FAILURE(失败)、SUCCESS(成功)
    "status":"IN_PROGRESS"
}

5. http://ip:port/mj/task/list GET 查询所有任务

[
  {
    "action":"IMAGINE",
    "id":"8498455807628990",
    "prompt":"猫猫",
    "promptEn": "Cat",
    "description":"/imagine 猫猫",
    "state":"test:22",
    "submitTime":1682473784826,
    "finishTime":null,
    "imageUrl":null,
    "status":"IN_PROGRESS"
  }
]

mj.notify-hook 任务变更回调

POST application/json

{
    "action":"IMAGINE",
    "id":"8498455807628990",
    "prompt":"猫猫",
    "promptEn": "Cat",
    "description":"/imagine 猫猫",
    "state":"test:22",
    "submitTime":1682473784826,
    "finishTime":null,
    "imageUrl":null,
    "status":"IN_PROGRESS"
}

应用项目

midjourney-proxy's People

Contributors

jiangying000 avatar novicezk avatar plexpt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.