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
825f59e1
authored
Jan 01, 2024
by
Xyfacai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize: MJ 部分调整、优化
MJ 增加simple-change、list接口, 变换和重试操作区别出来,价格与绘图一样 优化图片返回
parent
abe948c5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
217 additions
and
56 deletions
+217
-56
common/model-ratio.go
+7
-1
controller/relay-mj.go
+177
-52
controller/relay.go
+10
-2
model/midjourney.go
+21
-1
router/relay-router.go
+2
-0
No files found.
common/model-ratio.go
View file @
825f59e1
...
...
@@ -14,7 +14,7 @@ import (
// 1 === $0.002 / 1K tokens
// 1 === ¥0.014 / 1k tokens
var
ModelRatio
=
map
[
string
]
float64
{
"midjourney"
:
50
,
//
"midjourney": 50,
"gpt-4-gizmo-*"
:
15
,
"gpt-4"
:
15
,
"gpt-4-0314"
:
15
,
...
...
@@ -80,6 +80,12 @@ var ModelRatio = map[string]float64{
var
ModelPrice
=
map
[
string
]
float64
{
"gpt-4-gizmo-*"
:
0.1
,
"mj_imagine"
:
0.1
,
"mj_variation"
:
0.1
,
"mj_reroll"
:
0.1
,
"mj_blend"
:
0.1
,
"mj_describe"
:
0.05
,
"mj_upscale"
:
0.05
,
}
func
ModelPrice2JSONString
()
string
{
...
...
controller/relay-mj.go
View file @
825f59e1
This diff is collapsed.
Click to expand it.
controller/relay.go
View file @
825f59e1
...
...
@@ -95,8 +95,10 @@ const (
RelayModeMidjourneyDescribe
RelayModeMidjourneyBlend
RelayModeMidjourneyChange
RelayModeMidjourneySimpleChange
RelayModeMidjourneyNotify
RelayModeMidjourneyTaskFetch
RelayModeMidjourneyTaskFetchByCondition
RelayModeAudio
)
...
...
@@ -263,6 +265,7 @@ type MidjourneyRequest struct {
State
string
`json:"state"`
TaskId
string
`json:"taskId"`
Base64Array
[]
string
`json:"base64Array"`
Content
string
`json:"content"`
}
type
MidjourneyResponse
struct
{
...
...
@@ -342,14 +345,19 @@ func RelayMidjourney(c *gin.Context) {
relayMode
=
RelayModeMidjourneyNotify
}
else
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/mj/submit/change"
)
{
relayMode
=
RelayModeMidjourneyChange
}
else
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/mj/task"
)
{
}
else
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/mj/submit/simple-change"
)
{
relayMode
=
RelayModeMidjourneyChange
}
else
if
strings
.
HasSuffix
(
c
.
Request
.
URL
.
Path
,
"/fetch"
)
{
relayMode
=
RelayModeMidjourneyTaskFetch
}
else
if
strings
.
HasSuffix
(
c
.
Request
.
URL
.
Path
,
"/list-by-condition"
)
{
relayMode
=
RelayModeMidjourneyTaskFetchByCondition
}
var
err
*
MidjourneyResponse
switch
relayMode
{
case
RelayModeMidjourneyNotify
:
err
=
relayMidjourneyNotify
(
c
)
case
RelayModeMidjourneyTaskFetch
:
case
RelayModeMidjourneyTaskFetch
,
RelayModeMidjourneyTaskFetchByCondition
:
err
=
relayMidjourneyTask
(
c
,
relayMode
)
default
:
err
=
relayMidjourneySubmit
(
c
,
relayMode
)
...
...
model/midjourney.go
View file @
825f59e1
...
...
@@ -96,7 +96,7 @@ func GetAllUnFinishTasks() []*Midjourney {
return
tasks
}
func
GetByMJId
(
mjId
string
)
*
Midjourney
{
func
GetBy
Only
MJId
(
mjId
string
)
*
Midjourney
{
var
mj
*
Midjourney
var
err
error
err
=
DB
.
Where
(
"mj_id = ?"
,
mjId
)
.
First
(
&
mj
)
.
Error
...
...
@@ -106,6 +106,26 @@ func GetByMJId(mjId string) *Midjourney {
return
mj
}
func
GetByMJId
(
userId
int
,
mjId
string
)
*
Midjourney
{
var
mj
*
Midjourney
var
err
error
err
=
DB
.
Where
(
"user_id = ? and mj_id = ?"
,
userId
,
mjId
)
.
First
(
&
mj
)
.
Error
if
err
!=
nil
{
return
nil
}
return
mj
}
func
GetByMJIds
(
userId
int
,
mjIds
[]
string
)
[]
*
Midjourney
{
var
mj
[]
*
Midjourney
var
err
error
err
=
DB
.
Where
(
"user_id = ? and mj_id in (?)"
,
userId
,
mjIds
)
.
Find
(
&
mj
)
.
Error
if
err
!=
nil
{
return
nil
}
return
mj
}
func
GetMjByuId
(
id
int
)
*
Midjourney
{
var
mj
*
Midjourney
var
err
error
...
...
router/relay-router.go
View file @
825f59e1
...
...
@@ -49,10 +49,12 @@ func SetRelayRouter(router *gin.Engine) {
{
relayMjRouter
.
POST
(
"/submit/imagine"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/submit/change"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/submit/simple-change"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/submit/describe"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/submit/blend"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/notify"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
GET
(
"/task/:id/fetch"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/task/list-by-condition"
,
controller
.
RelayMidjourney
)
}
//relayMjRouter.Use()
}
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