Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f1f1e1c1
authored
Mar 13, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 操作细分
parent
62bca310
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
90 deletions
+123
-90
Midjourney.md
+44
-12
constant/midjourney.go
+13
-9
controller/relay.go
+1
-31
relay/constant/relay_mode.go
+31
-0
relay/relay-mj.go
+28
-38
web/src/components/MjLogsTable.js
+6
-0
No files found.
Midjourney.md
View file @
f1f1e1c1
...
@@ -4,31 +4,62 @@
...
@@ -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
```
json
{
{
"gpt-4-gizmo-*"
:
0.1
,
"mj_imagine"
:
0.1
,
"mj_imagine"
:
0.1
,
"mj_variation"
:
0.1
,
"mj_variation"
:
0.1
,
"mj_reroll"
:
0.1
,
"mj_reroll"
:
0.1
,
"mj_blend"
:
0.1
,
"mj_blend"
:
0.1
,
"mj_inpaint"
:
0.1
,
"mj_inpaint"
:
0.1
,
"mj_zoom"
:
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_inpaint_pre"
:
0
,
"mj_describe"
:
0.05
,
"mj_describe"
:
0.05
,
"mj_upscale"
:
0.05
,
"mj_upscale"
:
0.05
,
"swap_face"
:
0.05
"swap_face"
:
0.05
}
}
```
```
## 渠道设置
## 渠道设置
### 对接 midjourney-proxy(plus)
### 对接 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
3.
地址填写midjourney-proxy部署的地址,例如:http://localhost:8080
4.
密钥填写midjourney-proxy的密钥,如果没有设置密钥,可以随便填
4.
密钥填写midjourney-proxy的密钥,如果没有设置密钥,可以随便填
### 对接上游new api
### 对接上游new api
1.
在渠道管理中添加渠道,渠道类型选择
**Midjourney Proxy Plus**
,模型选择midjourney,如果有换脸模型,可以选择swap_face
1.
在渠道管理中添加渠道,渠道类型选择
**Midjourney Proxy Plus**
,模型选择midjourney,如果有换脸模型,可以选择swap_face
2.
地址填写上游new api的地址,例如:http://localhost:3000
2.
地址填写上游new api的地址,例如:http://localhost:3000
3.
密钥填写上游new api的密钥
3.
密钥填写上游new api的密钥
\ No newline at end of file
constant/midjourney.go
View file @
f1f1e1c1
...
@@ -6,13 +6,17 @@ const (
...
@@ -6,13 +6,17 @@ const (
)
)
const
(
const
(
MjActionImagine
=
"IMAGINE"
MjActionImagine
=
"IMAGINE"
MjActionDescribe
=
"DESCRIBE"
MjActionDescribe
=
"DESCRIBE"
MjActionBlend
=
"BLEND"
MjActionBlend
=
"BLEND"
MjActionUpscale
=
"UPSCALE"
MjActionUpscale
=
"UPSCALE"
MjActionVariation
=
"VARIATION"
MjActionVariation
=
"VARIATION"
MjActionInPaint
=
"INPAINT"
MjActionInPaint
=
"INPAINT"
MjActionInPaintPre
=
"INPAINT_PRE"
MjActionInPaintPre
=
"INPAINT_PRE"
MjActionZoom
=
"ZOOM"
MjActionZoom
=
"ZOOM"
MjActionShorten
=
"SHORTEN"
MjActionShorten
=
"SHORTEN"
MjActionHighVariation
=
"HIGH_VARIATION"
MjActionLowVariation
=
"LOW_VARIATION"
MjActionPan
=
"PAN"
SwapFace
=
"SWAP_FACE"
)
)
controller/relay.go
View file @
f1f1e1c1
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
relayconstant
"one-api/relay/constant"
relayconstant
"one-api/relay/constant"
"one-api/service"
"one-api/service"
"strconv"
"strconv"
"strings"
)
)
func
Relay
(
c
*
gin
.
Context
)
{
func
Relay
(
c
*
gin
.
Context
)
{
...
@@ -61,42 +60,13 @@ func Relay(c *gin.Context) {
...
@@ -61,42 +60,13 @@ func Relay(c *gin.Context) {
}
}
func
RelayMidjourney
(
c
*
gin
.
Context
)
{
func
RelayMidjourney
(
c
*
gin
.
Context
)
{
relayMode
:=
relayconstant
.
RelayModeUnknown
relayMode
:=
constant
.
Path2RelayModeMidjourney
(
c
.
Request
.
URL
.
Path
)
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
}
var
err
*
dto
.
MidjourneyResponse
var
err
*
dto
.
MidjourneyResponse
switch
relayMode
{
switch
relayMode
{
case
relayconstant
.
RelayModeMidjourneyNotify
:
case
relayconstant
.
RelayModeMidjourneyNotify
:
err
=
relay
.
RelayMidjourneyNotify
(
c
)
err
=
relay
.
RelayMidjourneyNotify
(
c
)
case
relayconstant
.
RelayModeMidjourneyTaskFetch
,
relayconstant
.
RelayModeMidjourneyTaskFetchByCondition
:
case
relayconstant
.
RelayModeMidjourneyTaskFetch
,
relayconstant
.
RelayModeMidjourneyTaskFetchByCondition
:
err
=
relay
.
RelayMidjourneyTask
(
c
,
relayMode
)
err
=
relay
.
RelayMidjourneyTask
(
c
,
relayMode
)
//case relayconstant.RelayModeMidjourneyModal:
// err = relay.RelayMidjournneyModal(c)
default
:
default
:
err
=
relay
.
RelayMidjourneySubmit
(
c
,
relayMode
)
err
=
relay
.
RelayMidjourneySubmit
(
c
,
relayMode
)
}
}
...
...
relay/constant/relay_mode.go
View file @
f1f1e1c1
...
@@ -51,3 +51,34 @@ func Path2RelayMode(path string) int {
...
@@ -51,3 +51,34 @@ func Path2RelayMode(path string) int {
}
}
return
relayMode
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
}
relay/relay-mj.go
View file @
f1f1e1c1
...
@@ -22,16 +22,20 @@ import (
...
@@ -22,16 +22,20 @@ import (
)
)
var
DefaultModelPrice
=
map
[
string
]
float64
{
var
DefaultModelPrice
=
map
[
string
]
float64
{
"mj_imagine"
:
0.1
,
"mj_imagine"
:
0.1
,
"mj_variation"
:
0.1
,
"mj_variation"
:
0.1
,
"mj_reroll"
:
0.1
,
"mj_reroll"
:
0.1
,
"mj_blend"
:
0.1
,
"mj_blend"
:
0.1
,
"mj_inpaint"
:
0.1
,
"mj_inpaint"
:
0.1
,
"mj_zoom"
:
0.1
,
"mj_zoom"
:
0.1
,
"mj_inpaint_pre"
:
0
,
"mj_shorten"
:
0.1
,
"mj_describe"
:
0.05
,
"mj_high_variation"
:
0.1
,
"mj_upscale"
:
0.05
,
"mj_low_variation"
:
0.1
,
"swap_face"
:
0.05
,
"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
)
{
func
RelayMidjourneyImage
(
c
*
gin
.
Context
)
{
...
@@ -151,31 +155,6 @@ func coverMidjourneyTaskDto(c *gin.Context, originTask *model.Midjourney) (midjo
...
@@ -151,31 +155,6 @@ func coverMidjourneyTaskDto(c *gin.Context, originTask *model.Midjourney) (midjo
return
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
{
func
RelayMidjourneyTask
(
c
*
gin
.
Context
,
relayMode
int
)
*
dto
.
MidjourneyResponse
{
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
var
err
error
var
err
error
...
@@ -274,7 +253,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
...
@@ -274,7 +253,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyShorten
{
//缩短任务,此类任务可重复,plus only
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyShorten
{
//缩短任务,此类任务可重复,plus only
midjRequest
.
Action
=
constant
.
MjActionShorten
midjRequest
.
Action
=
constant
.
MjActionShorten
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyBlend
{
//绘画任务,此类任务可重复
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyBlend
{
//绘画任务,此类任务可重复
midjRequest
.
Action
=
"BLEND"
midjRequest
.
Action
=
constant
.
MjActionBlend
}
else
if
midjRequest
.
TaskId
!=
""
{
//放大、变换任务,此类任务,如果重复且已有结果,远端api会直接返回最终结果
}
else
if
midjRequest
.
TaskId
!=
""
{
//放大、变换任务,此类任务,如果重复且已有结果,远端api会直接返回最终结果
mjId
:=
""
mjId
:=
""
if
relayMode
==
relayconstant
.
RelayModeMidjourneyChange
{
if
relayMode
==
relayconstant
.
RelayModeMidjourneyChange
{
...
@@ -634,10 +613,21 @@ func coverPlusActionToNormalAction(midjRequest *dto.MidjourneyRequest) *dto.Midj
...
@@ -634,10 +613,21 @@ func coverPlusActionToNormalAction(midjRequest *dto.MidjourneyRequest) *dto.Midj
midjRequest
.
Index
=
index
midjRequest
.
Index
=
index
midjRequest
.
Action
=
constant
.
MjActionUpscale
midjRequest
.
Action
=
constant
.
MjActionUpscale
}
else
if
strings
.
Contains
(
action
,
"variation"
)
{
}
else
if
strings
.
Contains
(
action
,
"variation"
)
{
midjRequest
.
Action
=
constant
.
MjActionVariation
midjRequest
.
Index
=
1
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"
)
{
}
else
if
strings
.
Contains
(
action
,
"pan"
)
{
midjRequest
.
Action
=
constant
.
MjAction
Variatio
n
midjRequest
.
Action
=
constant
.
MjAction
Pa
n
midjRequest
.
Index
=
1
midjRequest
.
Index
=
1
}
else
if
action
==
"Outpaint"
||
action
==
"CustomZoom"
{
}
else
if
action
==
"Outpaint"
||
action
==
"CustomZoom"
{
midjRequest
.
Action
=
constant
.
MjActionZoom
midjRequest
.
Action
=
constant
.
MjActionZoom
...
...
web/src/components/MjLogsTable.js
View file @
f1f1e1c1
...
@@ -31,6 +31,12 @@ function renderType(type) {
...
@@ -31,6 +31,12 @@ function renderType(type) {
return
<
Tag
color
=
"orange"
size
=
'large'
>
放大
<
/Tag>
;
return
<
Tag
color
=
"orange"
size
=
'large'
>
放大
<
/Tag>
;
case
'VARIATION'
:
case
'VARIATION'
:
return
<
Tag
color
=
"purple"
size
=
'large'
>
变换
<
/Tag>
;
return
<
Tag
color
=
"purple"
size
=
'large'
>
变换
<
/Tag>
;
case
'HIGH_VARIATION'
:
return
<
Tag
color
=
"purple"
size
=
'large'
>
强变换
<
/Tag>
;
case
'LOW_VARIATION'
:
return
<
Tag
color
=
"purple"
size
=
'large'
>
弱变换
<
/Tag>
;
case
'PAN'
:
return
<
Tag
color
=
"cyan"
size
=
'large'
>
平移
<
/Tag>
;
case
'DESCRIBE'
:
case
'DESCRIBE'
:
return
<
Tag
color
=
"yellow"
size
=
'large'
>
图生文
<
/Tag>
;
return
<
Tag
color
=
"yellow"
size
=
'large'
>
图生文
<
/Tag>
;
case
'BLEAND'
:
case
'BLEAND'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment