From d5ffaf25027feb11e0564febb4fb31b6d3abdb56 Mon Sep 17 00:00:00 2001
From: CaIon <1808837298@qq.com>
Date: Wed, 13 Mar 2024 18:26:16 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=93=8D=E4=BD=9C=E7=BB=86=E5=88=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Midjourney.md | 55 ++++++++++++++++++++------
constant/midjourney.go | 22 ++++++-----
controller/relay.go | 32 +--------------
relay/constant/relay_mode.go | 31 +++++++++++++++
relay/relay-mj.go | 66 +++++++++++++------------------
web/src/components/MjLogsTable.js | 6 +++
6 files changed, 122 insertions(+), 90 deletions(-)
diff --git a/Midjourney.md b/Midjourney.md
index becc9c9b..d495e841 100644
--- a/Midjourney.md
+++ b/Midjourney.md
@@ -4,31 +4,62 @@
## 模型价格设置(在设置-运营设置-模型固定价格设置中设置)
+### 模型列表
+
+### midjourney-proxy支持
+
+- mj_imagine (绘图)
+- mj_variation (变换)
+- mj_reroll (重绘)
+- mj_blend (混合)
+- mj_upscale (放大)
+- mj_describe (图生文)
+
+### 仅midjourney-proxy-plus支持
+
+- mj_zoom (比例变焦)
+- mj_shorten (提示词缩短)
+- mj_inpaint_pre (发起局部重绘,必须和mj_inpaint一同添加)
+- mj_inpaint (局部重绘提交,必须和mj_inpaint_pre一同添加)
+- mj_high_variation (强变换)
+- mj_low_variation (弱变换)
+- mj_pan (平移)
+- swap_face (换脸)
+
```json
{
- "gpt-4-gizmo-*": 0.1,
- "mj_imagine": 0.1,
- "mj_variation": 0.1,
- "mj_reroll": 0.1,
- "mj_blend": 0.1,
- "mj_inpaint": 0.1,
- "mj_zoom": 0.1,
+ "mj_imagine": 0.1,
+ "mj_variation": 0.1,
+ "mj_reroll": 0.1,
+ "mj_blend": 0.1,
+ "mj_inpaint": 0.1,
+ "mj_zoom": 0.1,
+ "mj_shorten": 0.1,
+ "mj_high_variation": 0.1,
+ "mj_low_variation": 0.1,
+ "mj_pan": 0.1,
"mj_inpaint_pre": 0,
- "mj_describe": 0.05,
- "mj_upscale": 0.05,
- "swap_face": 0.05
+ "mj_describe": 0.05,
+ "mj_upscale": 0.05,
+ "swap_face": 0.05
}
```
## 渠道设置
### 对接 midjourney-proxy(plus)
-1. 部署Midjourney-Proxy,并配置好midjourney账号等(强烈建议设置密钥),[项目地址](https://github.com/novicezk/midjourney-proxy)
-2. 在渠道管理中添加渠道,渠道类型选择**Midjourney Proxy**,如果是plus版本选择**Midjourney Proxy Plus**,模型选择midjourney,如果有换脸模型,可以选择swap_face
+
+1.
+
+部署Midjourney-Proxy,并配置好midjourney账号等(强烈建议设置密钥),[项目地址](https://github.com/novicezk/midjourney-proxy)
+
+2. 在渠道管理中添加渠道,渠道类型选择**Midjourney Proxy**,如果是plus版本选择**Midjourney Proxy Plus**
+ ,模型选择midjourney,如果有换脸模型,可以选择swap_face
3. 地址填写midjourney-proxy部署的地址,例如:http://localhost:8080
4. 密钥填写midjourney-proxy的密钥,如果没有设置密钥,可以随便填
### 对接上游new api
+
1. 在渠道管理中添加渠道,渠道类型选择**Midjourney Proxy Plus**,模型选择midjourney,如果有换脸模型,可以选择swap_face
2. 地址填写上游new api的地址,例如:http://localhost:3000
3. 密钥填写上游new api的密钥
\ No newline at end of file
diff --git a/constant/midjourney.go b/constant/midjourney.go
index a5bccb76..5435a430 100644
--- a/constant/midjourney.go
+++ b/constant/midjourney.go
@@ -6,13 +6,17 @@ const (
)
const (
- MjActionImagine = "IMAGINE"
- MjActionDescribe = "DESCRIBE"
- MjActionBlend = "BLEND"
- MjActionUpscale = "UPSCALE"
- MjActionVariation = "VARIATION"
- MjActionInPaint = "INPAINT"
- MjActionInPaintPre = "INPAINT_PRE"
- MjActionZoom = "ZOOM"
- MjActionShorten = "SHORTEN"
+ MjActionImagine = "IMAGINE"
+ MjActionDescribe = "DESCRIBE"
+ MjActionBlend = "BLEND"
+ MjActionUpscale = "UPSCALE"
+ MjActionVariation = "VARIATION"
+ MjActionInPaint = "INPAINT"
+ MjActionInPaintPre = "INPAINT_PRE"
+ MjActionZoom = "ZOOM"
+ MjActionShorten = "SHORTEN"
+ MjActionHighVariation = "HIGH_VARIATION"
+ MjActionLowVariation = "LOW_VARIATION"
+ MjActionPan = "PAN"
+ SwapFace = "SWAP_FACE"
)
diff --git a/controller/relay.go b/controller/relay.go
index 76528400..d35c6a2d 100644
--- a/controller/relay.go
+++ b/controller/relay.go
@@ -12,7 +12,6 @@ import (
relayconstant "one-api/relay/constant"
"one-api/service"
"strconv"
- "strings"
)
func Relay(c *gin.Context) {
@@ -61,42 +60,13 @@ func Relay(c *gin.Context) {
}
func RelayMidjourney(c *gin.Context) {
- relayMode := relayconstant.RelayModeUnknown
- if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/action") {
- // midjourney plus
- relayMode = relayconstant.RelayModeMidjourneyAction
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/modal") {
- // midjourney plus
- relayMode = relayconstant.RelayModeMidjourneyModal
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/shorten") {
- // midjourney plus
- relayMode = relayconstant.RelayModeMidjourneyShorten
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/imagine") {
- relayMode = relayconstant.RelayModeMidjourneyImagine
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/blend") {
- relayMode = relayconstant.RelayModeMidjourneyBlend
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/describe") {
- relayMode = relayconstant.RelayModeMidjourneyDescribe
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/notify") {
- relayMode = relayconstant.RelayModeMidjourneyNotify
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/change") {
- relayMode = relayconstant.RelayModeMidjourneyChange
- } else if strings.HasPrefix(c.Request.URL.Path, "/mj/submit/simple-change") {
- relayMode = relayconstant.RelayModeMidjourneyChange
- } else if strings.HasSuffix(c.Request.URL.Path, "/fetch") {
- relayMode = relayconstant.RelayModeMidjourneyTaskFetch
- } else if strings.HasSuffix(c.Request.URL.Path, "/list-by-condition") {
- relayMode = relayconstant.RelayModeMidjourneyTaskFetchByCondition
- }
-
+ relayMode := constant.Path2RelayModeMidjourney(c.Request.URL.Path)
var err *dto.MidjourneyResponse
switch relayMode {
case relayconstant.RelayModeMidjourneyNotify:
err = relay.RelayMidjourneyNotify(c)
case relayconstant.RelayModeMidjourneyTaskFetch, relayconstant.RelayModeMidjourneyTaskFetchByCondition:
err = relay.RelayMidjourneyTask(c, relayMode)
- //case relayconstant.RelayModeMidjourneyModal:
- // err = relay.RelayMidjournneyModal(c)
default:
err = relay.RelayMidjourneySubmit(c, relayMode)
}
diff --git a/relay/constant/relay_mode.go b/relay/constant/relay_mode.go
index d8dc7eeb..9f13726f 100644
--- a/relay/constant/relay_mode.go
+++ b/relay/constant/relay_mode.go
@@ -51,3 +51,34 @@ func Path2RelayMode(path string) int {
}
return relayMode
}
+
+func Path2RelayModeMidjourney(path string) int {
+ relayMode := RelayModeUnknown
+ if strings.HasPrefix(path, "/mj/submit/action") {
+ // midjourney plus
+ relayMode = RelayModeMidjourneyAction
+ } else if strings.HasPrefix(path, "/mj/submit/modal") {
+ // midjourney plus
+ relayMode = RelayModeMidjourneyModal
+ } else if strings.HasPrefix(path, "/mj/submit/shorten") {
+ // midjourney plus
+ relayMode = RelayModeMidjourneyShorten
+ } else if strings.HasPrefix(path, "/mj/submit/imagine") {
+ relayMode = RelayModeMidjourneyImagine
+ } else if strings.HasPrefix(path, "/mj/submit/blend") {
+ relayMode = RelayModeMidjourneyBlend
+ } else if strings.HasPrefix(path, "/mj/submit/describe") {
+ relayMode = RelayModeMidjourneyDescribe
+ } else if strings.HasPrefix(path, "/mj/notify") {
+ relayMode = RelayModeMidjourneyNotify
+ } else if strings.HasPrefix(path, "/mj/submit/change") {
+ relayMode = RelayModeMidjourneyChange
+ } else if strings.HasPrefix(path, "/mj/submit/simple-change") {
+ relayMode = RelayModeMidjourneyChange
+ } else if strings.HasSuffix(path, "/fetch") {
+ relayMode = RelayModeMidjourneyTaskFetch
+ } else if strings.HasSuffix(path, "/list-by-condition") {
+ relayMode = RelayModeMidjourneyTaskFetchByCondition
+ }
+ return relayMode
+}
diff --git a/relay/relay-mj.go b/relay/relay-mj.go
index a1f6ed48..f391f142 100644
--- a/relay/relay-mj.go
+++ b/relay/relay-mj.go
@@ -22,16 +22,20 @@ import (
)
var DefaultModelPrice = map[string]float64{
- "mj_imagine": 0.1,
- "mj_variation": 0.1,
- "mj_reroll": 0.1,
- "mj_blend": 0.1,
- "mj_inpaint": 0.1,
- "mj_zoom": 0.1,
- "mj_inpaint_pre": 0,
- "mj_describe": 0.05,
- "mj_upscale": 0.05,
- "swap_face": 0.05,
+ "mj_imagine": 0.1,
+ "mj_variation": 0.1,
+ "mj_reroll": 0.1,
+ "mj_blend": 0.1,
+ "mj_inpaint": 0.1,
+ "mj_zoom": 0.1,
+ "mj_shorten": 0.1,
+ "mj_high_variation": 0.1,
+ "mj_low_variation": 0.1,
+ "mj_pan": 0.1,
+ "mj_inpaint_pre": 0,
+ "mj_describe": 0.05,
+ "mj_upscale": 0.05,
+ "swap_face": 0.05,
}
func RelayMidjourneyImage(c *gin.Context) {
@@ -151,31 +155,6 @@ func coverMidjourneyTaskDto(c *gin.Context, originTask *model.Midjourney) (midjo
return
}
-func RelayMidjournneyModal(c *gin.Context) *dto.MidjourneyResponse {
- userId := c.GetInt("id")
- var midjRequest dto.MidjourneyRequest
- err := common.UnmarshalBodyReusable(c, &midjRequest)
- if err != nil {
- return service.MidjourneyErrorWrapper(constant.MjRequestError, "bind_request_body_failed")
- }
- originTask := model.GetByMJId(userId, midjRequest.TaskId)
- if originTask == nil {
- return service.MidjourneyErrorWrapper(constant.MjRequestError, "task_no_found")
- }
-
- respBody, err := json.Marshal(midjRequest)
- if err != nil {
- return service.MidjourneyErrorWrapper(constant.MjRequestError, "unmarshal_response_body_failed")
- }
- c.Writer.Header().Set("Content-Type", "application/json")
- _, err = io.Copy(c.Writer, bytes.NewBuffer(respBody))
- if err != nil {
- return service.MidjourneyErrorWrapper(constant.MjRequestError, "copy_response_body_failed")
- }
- return nil
-
-}
-
func RelayMidjourneyTask(c *gin.Context, relayMode int) *dto.MidjourneyResponse {
userId := c.GetInt("id")
var err error
@@ -274,7 +253,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
} else if relayMode == relayconstant.RelayModeMidjourneyShorten { //缩短任务,此类任务可重复,plus only
midjRequest.Action = constant.MjActionShorten
} else if relayMode == relayconstant.RelayModeMidjourneyBlend { //绘画任务,此类任务可重复
- midjRequest.Action = "BLEND"
+ midjRequest.Action = constant.MjActionBlend
} else if midjRequest.TaskId != "" { //放大、变换任务,此类任务,如果重复且已有结果,远端api会直接返回最终结果
mjId := ""
if relayMode == relayconstant.RelayModeMidjourneyChange {
@@ -634,10 +613,21 @@ func coverPlusActionToNormalAction(midjRequest *dto.MidjourneyRequest) *dto.Midj
midjRequest.Index = index
midjRequest.Action = constant.MjActionUpscale
} else if strings.Contains(action, "variation") {
- midjRequest.Action = constant.MjActionVariation
midjRequest.Index = 1
+ if action == "variation" {
+ index, err := strconv.Atoi(splits[3])
+ if err != nil {
+ return service.MidjourneyErrorWrapper(constant.MjRequestError, "index_parse_failed")
+ }
+ midjRequest.Index = index
+ midjRequest.Action = constant.MjActionVariation
+ } else if action == "low_variation" {
+ midjRequest.Action = constant.MjActionLowVariation
+ } else if action == "high_variation" {
+ midjRequest.Action = constant.MjActionHighVariation
+ }
} else if strings.Contains(action, "pan") {
- midjRequest.Action = constant.MjActionVariation
+ midjRequest.Action = constant.MjActionPan
midjRequest.Index = 1
} else if action == "Outpaint" || action == "CustomZoom" {
midjRequest.Action = constant.MjActionZoom
diff --git a/web/src/components/MjLogsTable.js b/web/src/components/MjLogsTable.js
index fe6554ee..603d345b 100644
--- a/web/src/components/MjLogsTable.js
+++ b/web/src/components/MjLogsTable.js
@@ -31,6 +31,12 @@ function renderType(type) {
return 放大;
case 'VARIATION':
return 变换;
+ case 'HIGH_VARIATION':
+ return 强变换;
+ case 'LOW_VARIATION':
+ return 弱变换;
+ case 'PAN':
+ return 平移;
case 'DESCRIBE':
return 图生文;
case 'BLEAND':