Skip to content

Commit c597917

Browse files
author
zhukai
committed
doc: 添加相关文档
1 parent 99a94a0 commit c597917

File tree

11 files changed

+553
-1
lines changed

11 files changed

+553
-1
lines changed

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**
4+
!**/src/test/**
5+
bin/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/
32+
33+
### Macos ###
34+
.DS_Store
35+
36+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
37+
hs_err_pid*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ midjourney-proxy的先行版,采用了全新架构,降低了封号的几率
1010
- [x] 支持 Blend(图片混合) 指令和相关动作
1111
- [x] 支持 Describe(图生文) 指令和相关动作
1212
- [x] 支持任务实时进度
13-
- [x] 支持中文 prompt 翻译,需配置百度翻译或 gpt
13+
- [x] 支持中英文翻译,需配置百度翻译、deepl翻译或gpt
1414
- [x] prompt 敏感词判断,支持覆盖调整
1515
- [x] 任务队列,默认队列10,并发3。可参考 [MidJourney订阅级别](https://docs.midjourney.com/docs/plans) 调整mj.queue
1616
- [x] user-token 连接 wss,可以获取错误信息和完整功能

docs/api.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# API接口说明
2+
3+
`http://ip:port/mj` 已有api文档,此处仅作补充
4+
5+
## 1. 数据结构
6+
7+
### 任务
8+
| 字段 | 类型 | 示例 | 描述 |
9+
|:-----:|:----:|:----|:----|
10+
| id | string | 1689231405853400 | 任务ID |
11+
| action | string | IMAGINE | 任务类型: IMAGINE(绘图)、UPSCALE(选中放大)、VARIATION(选中变换)、REROLL(重新生成)、ZOOM(图片变焦)、PAN(焦点移动)、DESCRIBE(图生文)、BLEAND(图片混合)、SHORTEN(prompt分析) |
12+
| status | string | SUCCESS | 任务状态: NOT_START(未启动)、SUBMITTED(已提交处理)、MODAL(窗口等待)、IN_PROGRESS(执行中)、FAILURE(失败)、SUCCESS(成功) |
13+
| prompt | string | 猫猫 | 提示词 |
14+
| promptEn | string | Cat | 英文提示词 |
15+
| description | string | /imagine 猫猫 | 任务描述 |
16+
| submitTime | number | 1689231405854 | 提交时间 |
17+
| startTime | number | 1689231442755 | 开始执行时间 |
18+
| finishTime | number | 1689231544312 | 结束时间 |
19+
| progress | string | 100% | 任务进度 |
20+
| imageUrl | string | https://cdn.discordapp.com/attachments/xxx/xxx/xxxx.png | 生成图片的url, 成功或执行中时有值,可能为png或webp |
21+
| failReason | string | [Invalid parameter] Invalid value | 失败原因, 失败时有值 |
22+
| properties | object | {"finalPrompt": "Cat"} | 任务的扩展属性,系统内部使用 |
23+
| buttons | Button[] | [] | 任务完成后的可执行按钮 |
24+
25+
### Button
26+
| 字段 | 类型 | 示例 | 描述 |
27+
|:-----:|:----:|:----|:----|
28+
| customId | string | MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 | 动作标识 |
29+
| emoji | string | 🪄 | 图标 |
30+
| label | string | Make Variations | 文本 |
31+
| type | number | 2 | 类型,系统内部使用 |
32+
| style | number | 2 | 样式: 2(Primary)、3(Green) |
33+
34+
## 2. 任务提交返回
35+
- code=1: 提交成功,result为任务ID
36+
```json
37+
{
38+
"code": 1,
39+
"description": "提交成功",
40+
"result": "14001929738841620"
41+
}
42+
```
43+
- code=22: 提交成功,进入队列等待
44+
```json
45+
{
46+
"code": 22,
47+
"description": "排队中,前面还有1个任务",
48+
"result": "14001929738841620",
49+
"properties": {
50+
"numberOfQueues": 1
51+
}
52+
}
53+
```
54+
- other: 提交错误,description为错误描述
55+
56+
## 3. 执行任务的关联动作
57+
调用 `/mj/submit/action`,几乎所有的button都做了支持,除了以下情况:
58+
- 图生文结果的 `🎉Imagine all`
59+
- 图片放大后的 `❤️`
60+
61+
```json
62+
{
63+
// 关联任务的ID
64+
"taskId": "1689216801333574",
65+
// 动作标识
66+
"customId": "MJ::JOB::reroll::0::1c6dff5e-5632-40c6-9d4c-afb261705313::SOLO"
67+
}
68+
```
69+
⚠️ 注意: 某些场景需要modal确认,提交后任务状态会变为MODAL,需调用`/mj/submit/modal`进行二次提交
70+
- 账号开启了Remix & 配置remix为true & 执行Reroll、Variation
71+
- 执行CustomZoom(自定义变焦)或PicReader(Describe后选择生图)
72+
73+
调用 `/mj/submit/modal`
74+
```json
75+
{
76+
// 需确认的任务ID
77+
"taskId": "1689228047868174",
78+
// prompt: 为空时使用原任务的prompt
79+
"prompt": "Cat"
80+
}
81+
```
82+
CustomZoom的prompt需要设置--ar 和 --zoom(1到2之间),例如: `Cat --ar 1:1 --zoom 1.5`
83+
84+
## 4. `/mj/submit/describe` 图生文
85+
```json
86+
{
87+
// 图片的base64字符串
88+
"base64": "data:image/png;base64,xxx"
89+
}
90+
```
91+
92+
后续任务完成后,properties中finalPrompt即为图片生成的prompt,finalZhPrompt为翻译的中文
93+
```json
94+
{
95+
"id":"14001929738841620",
96+
"action":"DESCRIBE",
97+
"status": "SUCCESS",
98+
"description":"/describe 14001929738841620.png",
99+
"imageUrl":"https://cdn.discordapp.com/attachments/xxx/xxx/14001929738841620.png",
100+
"properties": {
101+
"finalPrompt": "1️⃣ Cat --ar 5:4\n\n2️⃣ Cat2 --ar 5:4\n\n3️⃣ Cat3 --ar 5:4\n\n4️⃣ Cat4 --ar 5:4",
102+
"finalZhPrompt": "1️⃣ 猫 --ar 5:4\n\n2️⃣ 猫2 --ar 5:4\n\n3️⃣ 猫3 --ar 5:4\n\n4️⃣ 猫4 --ar 5:4"
103+
}
104+
// ...
105+
}
106+
```
107+
108+
## 5. `/mj/submit/shorten` prompt分析
109+
```json
110+
{
111+
"prompt": "️appdash appdash, in the style of expert draftsmanship, commission for, ethereal, dreamlike quality, dadaistic, toonami"
112+
}
113+
```
114+
115+
后续任务完成后,properties中finalPrompt即为分析结果,finalZhPrompt为翻译的中文
116+
```json
117+
{
118+
"id":"1689252749098647",
119+
"action":"SHORTEN",
120+
"status": "SUCCESS",
121+
"description":"/shorten appdash appdash, in the style of expert draftsmanship, commission for, ethereal, dreamlike quality, dadaistic, toonami",
122+
"properties": {
123+
"finalPrompt": "## Important tokens\n**appdash** **appdash**, in the ~~style~~ of ~~expert~~ **draftsmanship**, commission for, ethereal, dreamlike quality, ~~dadaistic~~, **toonami**\n## Shortened prompts\n1️⃣ appdash appdash, draftsmanship, commission for, ethereal, toonami\n\n2️⃣ appdash appdash, draftsmanship, commission, toonami\n\n3️⃣ appdash appdash, draftsmanship, toonami\n\n4️⃣ appdash appdash, toonami\n\n5️⃣ appdash appdash",
124+
"finalZhPrompt": "## 重要词汇\n**appdash** **appdash**,以专家的绘画风格,委托制作,飘渺的,梦幻般的质感,达达主义的,**toonami**\n## 简化提示\n1️⃣ appdash appdash,绘画风格,委托制作,飘渺的,toonami\n\n2️⃣ appdash appdash,绘画风格,委托制作,toonami\n\n3️⃣ appdash appdash,绘画风格,toonami\n\n4️⃣ appdash appdash,toonami\n\n5️⃣ appdash appdash"
125+
}
126+
// ...
127+
}
128+
```
129+
对该任务执行 `Show Details` 动作,能获得进一步的分析结果
130+
```json
131+
{
132+
"id":"1689253263953453",
133+
"action":"SHORTEN",
134+
"status": "SUCCESS",
135+
"description":"/up 168925266642808397 Show Details",
136+
"properties": {
137+
"finalPrompt": "## Important tokens\n**appdash** (1.00) **appdash** (0.79), in the style (0.01) of expert (0.00) **draftsmanship** (0.09), commission (0.08) for, ethereal (0.05), dreamlike (0.02) quality (0.01), dadaistic (0.01), **toonami** (0.19)\n\n██████████ appdash\n████████░░ appdash\n██░░░░░░░░ toonami\n█░░░░░░░░░ draftsmanship\n█░░░░░░░░░ commission\n█░░░░░░░░░ ethereal\n## Shortened prompts\n1️⃣ appdash appdash, draftsmanship, commission for, ethereal, toonami\n\n2️⃣ appdash appdash, draftsmanship, commission, toonami\n\n3️⃣ appdash appdash, draftsmanship, toonami\n\n4️⃣ appdash appdash, toonami\n\n5️⃣ appdash app",
138+
"finalZhPrompt": "## 重要的词语\n**appdash** (1.00) **appdash** (0.79),以专家级(0.01) **绘画技巧** (0.09) 的风格,委托(0.08) 制作,飘渺的(0.05),梦幻般的(0.02) 质感(0.01),达达主义的(0.01),**toonami** (0.19)\n\n██████████ appdash\n████████░░ appdash\n██░░░░░░░░ toonami\n█░░░░░░░░░ draftsmanship\n█░░░░░░░░░ commission\n█░░░░░░░░░ ethereal\n## 简化的提示\n1️⃣ appdash appdash,绘画技巧,委托制作,飘渺,toonami\n\n2️⃣ appdash appdash,绘画技巧,委托制作,toonami\n\n3️⃣ appdash appdash,绘画技巧,toonami\n\n4️⃣ appdash appdash,toonami\n\n5️⃣ appdash appdash"
139+
}
140+
// ...
141+
}
142+
```
143+
144+
## 6. 任务变更回调
145+
任务状态变化或进度改变时,会调用业务系统的接口
146+
- 接口地址为配置的 mj.notify-hook,任务提交时支持传`notifyHook`以改变此任务的回调地址
147+
- 两者都为空时,不触发回调
148+
149+
POST application/json
150+
```json
151+
{
152+
"id": "14001929738841620",
153+
"action": "IMAGINE",
154+
"status": "SUCCESS",
155+
"prompt": "猫猫",
156+
"promptEn": "Cat",
157+
"description": "/imagine 猫猫",
158+
"submitTime": 1689231405854,
159+
"startTime": 1689231442755,
160+
"finishTime": 1689231544312,
161+
"progress": "100%",
162+
"imageUrl": "https://cdn.discordapp.com/attachments/xxx/xxx/xxxx.png",
163+
"failReason": null,
164+
"properties": {
165+
"finalPrompt": "Cat"
166+
},
167+
"buttons": []
168+
}
169+
```

docs/config.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## 配置项
2+
3+
| 变量名 | 非空 | 描述 |
4+
| :-----| :----: | :---- |
5+
| mj.accounts || 参考 [账号池配置](./config.md#%E8%B4%A6%E5%8F%B7%E6%B1%A0%E9%85%8D%E7%BD%AE%E5%8F%82%E8%80%83),配置后不需要额外设置mj.discord |
6+
| mj.discord.guild-id || discord服务器ID |
7+
| mj.discord.channel-id || discord频道ID |
8+
| mj.discord.user-token || discord用户Token |
9+
| mj.discord.session-id || discord用户SessionId,建议从interactions请求中复制替换掉 |
10+
| mj.discord.user-agent || 调用discord接口、连接wss时的user-agent,建议从浏览器network复制 |
11+
| mj.discord.remix || 是否启用了remix,默认false。与账号的Remix模式开关保持一致 |
12+
| mj.api-secret || 接口密钥,为空不启用鉴权;调用接口时需要加请求头 mj-api-secret |
13+
| mj.notify-hook || 全局的任务状态变更回调地址 |
14+
| mj.notify-notify-pool-size || 通知回调线程池大小,默认10 |
15+
| mj.task-store.type || 任务存储方式,默认in_memory(内存\重启后丢失),可选redis |
16+
| mj.task-store.timeout || 任务过期时间,过期后删除,默认30天 |
17+
| mj.queue.core-size || 并发数,默认为3 |
18+
| mj.queue.queue-size || 等待队列,默认长度10 |
19+
| mj.queue.timeout-minutes || 任务超时时间,默认为5分钟 |
20+
| mj.proxy.host || 代理host,全局代理不生效时设置 |
21+
| mj.proxy.port || 代理port,全局代理不生效时设置 |
22+
| mj.ng-discord.server || https://discord.com 反代地址 |
23+
| mj.ng-discord.cdn || https://cdn.discordapp.com 反代地址 |
24+
| mj.ng-discord.wss || wss://gateway.discord.gg 反代地址 |
25+
| mj.translate-way || 中文prompt翻译方式,可选null(默认)、baidu、gpt、deepl |
26+
| mj.translate-zh-way || describe、shorten等结果转中文的方式,可选null(默认)、baidu、gpt、deepl |
27+
| mj.baidu-translate.appid || 百度翻译的appid |
28+
| mj.baidu-translate.app-secret || 百度翻译的app-secret |
29+
| mj.openai.gpt-api-url || 自定义gpt的接口地址,默认不需要配置 |
30+
| mj.openai.gpt-api-key || gpt的api-key |
31+
| mj.openai.timeout || openai调用的超时时间,默认30秒 |
32+
| mj.openai.model || openai的模型,默认gpt-3.5-turbo |
33+
| mj.openai.max-tokens || 返回结果的最大分词数,默认2048 |
34+
| mj.openai.temperature || 相似度(0-2.0),默认0 |
35+
| mj.deepl-translate.auth-key || DEEPL翻译的鉴权密钥 |
36+
| mj.error-desc || 任务错误原因转换,默认使用mj提供的英文描述 |
37+
| spring.redis || 任务存储方式设置为redis,需配置redis相关属性 |
38+
39+
### 账号池配置参考
40+
设置账号池后,调整`mj.queue`以实现更多任务并发
41+
```yaml
42+
mj:
43+
accounts:
44+
- guild-id: xxx
45+
channel-id: xxx
46+
user-token: xxxx
47+
session-id: xxxx
48+
user-agent: xxxx
49+
remix: false
50+
- guild-id: xxx
51+
channel-id: xxx
52+
user-token: xxxx
53+
session-id: xxxx
54+
user-agent: xxxx
55+
remix: false
56+
```
57+
58+
### spring.redis配置参考
59+
```yaml
60+
spring:
61+
redis:
62+
host: 10.107.xxx.xxx
63+
port: 6379
64+
password: xxx
65+
```
66+
67+
### mj.error-desc配置参考
68+
```yaml
69+
mj:
70+
error-desc:
71+
- en: "against our community standards"
72+
zh: "可能包含违规信息"
73+
- en: "Invalid parameter"
74+
zh: "无效的参数"
75+
```

docs/discord-params.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## 获取discord配置参数
2+
3+
### 1. 获取用户Token
4+
进入频道,打开network,刷新页面,找到 `messages` 的请求
5+
- Authorization 即用户Token,后续设置到 `user-token`
6+
- User-Agent 后续设置到 `user-agent`
7+
8+
![User Token](params_user.png)
9+
10+
### 2. 获取用户sessionId
11+
进入频道,打开network,发送/imagine作图指令,找到 `interactions` 的请求,这里的 session_id 即用户sessionId,后续设置到 `session-id`
12+
13+
![User Session](params_session_id.png)
14+
15+
### 3. 获取服务器ID、频道ID
16+
17+
频道的url里取出 服务器ID、频道ID,后续设置到配置项
18+
![Guild Channel ID](img_9.png)

docs/docker-start.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Docker 部署教程
2+
3+
1. /xxx/xxx/config目录下创建 application.yml(mj配置项)、banned-words.txt(可选,覆盖默认的敏感词文件);参考resources下的文件
4+
2. 启动容器,映射config目录
5+
```shell
6+
docker run -d --name midjourney-proxy \
7+
-p 8080:8080 \
8+
-v /xxx/xxx/config:/home/spring/config \
9+
--restart=always \
10+
novicezk/midjourney-proxy-pilot:3.0.1
11+
```
12+
3. 访问 `http://ip:port/mj` 查看API文档
13+
14+
附: 不映射config目录方式,直接在启动命令中设置参数
15+
```shell
16+
docker run -d --name midjourney-proxy \
17+
-p 8080:8080 \
18+
-e mj.discord.guild-id=xxx \
19+
-e mj.discord.channel-id=xxx \
20+
-e mj.discord.user-token=xxx \
21+
--restart=always \
22+
novicezk/midjourney-proxy-pilot:3.0.1
23+
```

docs/img_9.png

7.92 KB
Loading

docs/params_session_id.png

181 KB
Loading

docs/params_user.png

164 KB
Loading

resources/application.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
mj:
2+
accounts:
3+
- guild-id: xxx
4+
channel-id: xxx
5+
user-token: xxx
6+
session-id: 9c4055428e13bcbf2248a6b36084c5f3
7+
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
8+
remix: false
9+
task-store:
10+
type: in_memory
11+
timeout: 30d
12+
translate-way: null
13+
queue:
14+
timeout-minutes: 5
15+
core-size: 3
16+
queue-size: 10
17+
error-desc:
18+
- en: "against our community standards"
19+
zh: "可能包含违规信息"

0 commit comments

Comments
 (0)