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
bb8923e7
authored
May 29, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/ui/refactor' into ui/refactor
parents
8f6b0ede
66927d05
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
147 additions
and
80 deletions
+147
-80
dto/openai_request.go
+1
-1
relay/channel/api_request.go
+6
-5
relay/relay-image.go
+29
-63
web/src/index.css
+111
-11
web/src/pages/Playground/Playground.js
+0
-0
No files found.
dto/openai_request.go
View file @
bb8923e7
...
...
@@ -43,7 +43,7 @@ type GeneralOpenAIRequest struct {
ResponseFormat
*
ResponseFormat
`json:"response_format,omitempty"`
EncodingFormat
any
`json:"encoding_format,omitempty"`
Seed
float64
`json:"seed,omitempty"`
ParallelTooCalls
bool
`json:"parallel_tool_calls,omitempty"`
ParallelTooCalls
*
bool
`json:"parallel_tool_calls,omitempty"`
Tools
[]
ToolCallRequest
`json:"tools,omitempty"`
ToolChoice
any
`json:"tool_choice,omitempty"`
User
string
`json:"user,omitempty"`
...
...
relay/channel/api_request.go
View file @
bb8923e7
...
...
@@ -122,11 +122,13 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
var
pingerWg
sync
.
WaitGroup
if
info
.
IsStream
{
helper
.
SetEventStreamHeaders
(
c
)
pingInterval
:=
time
.
Duration
(
generalSettings
.
PingIntervalSeconds
)
*
time
.
Second
var
pingerCtx
context
.
Context
pingerCtx
,
stopPinger
=
context
.
WithCancel
(
c
.
Request
.
Context
())
if
pingEnabled
{
pingInterval
:=
time
.
Duration
(
generalSettings
.
PingIntervalSeconds
)
*
time
.
Second
var
pingerCtx
context
.
Context
pingerCtx
,
stopPinger
=
context
.
WithCancel
(
c
.
Request
.
Context
())
// 退出时清理 pingerCtx 防止泄露
defer
stopPinger
()
pingerWg
.
Add
(
1
)
gopool
.
Go
(
func
()
{
defer
pingerWg
.
Done
()
...
...
@@ -166,9 +168,8 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
}
resp
,
err
:=
client
.
Do
(
req
)
// request结束后
停止ping
// request结束后
等待 ping goroutine 完成
if
info
.
IsStream
&&
pingEnabled
{
stopPinger
()
pingerWg
.
Wait
()
}
if
err
!=
nil
{
...
...
relay/relay-image.go
View file @
bb8923e7
...
...
@@ -46,11 +46,23 @@ func getAndValidImageRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.
if
err
!=
nil
{
return
nil
,
err
}
if
imageRequest
.
Model
==
""
{
imageRequest
.
Model
=
"dall-e-3"
}
if
strings
.
Contains
(
imageRequest
.
Size
,
"×"
)
{
return
nil
,
errors
.
New
(
"size an unexpected error occurred in the parameter, please use 'x' instead of the multiplication sign '×'"
)
}
// Not "256x256", "512x512", or "1024x1024"
if
imageRequest
.
Model
==
"dall-e-2"
||
imageRequest
.
Model
==
"dall-e"
{
if
imageRequest
.
Size
!=
""
&&
imageRequest
.
Size
!=
"256x256"
&&
imageRequest
.
Size
!=
"512x512"
&&
imageRequest
.
Size
!=
"1024x1024"
{
return
nil
,
errors
.
New
(
"size must be one of 256x256, 512x512, or 1024x1024 for dall-e-2 or dall-e"
)
}
if
imageRequest
.
Size
==
""
{
imageRequest
.
Size
=
"1024x1024"
}
}
else
if
imageRequest
.
Model
==
"dall-e-3"
{
if
imageRequest
.
Size
!=
""
&&
imageRequest
.
Size
!=
"1024x1024"
&&
imageRequest
.
Size
!=
"1024x1792"
&&
imageRequest
.
Size
!=
"1792x1024"
{
return
nil
,
errors
.
New
(
"size must be one of 1024x1024, 1024x1792 or 1792x1024 for dall-e-3"
)
...
...
@@ -58,74 +70,24 @@ func getAndValidImageRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.
if
imageRequest
.
Quality
==
""
{
imageRequest
.
Quality
=
"standard"
}
// N should between 1 and 10
//if imageRequest.N != 0 && (imageRequest.N < 1 || imageRequest.N > 10) {
// return service.OpenAIErrorWrapper(errors.New("n must be between 1 and 10"), "invalid_field_value", http.StatusBadRequest)
//}
if
imageRequest
.
Size
==
""
{
imageRequest
.
Size
=
"1024x1024"
}
}
else
if
imageRequest
.
Model
==
"gpt-image-1"
{
if
imageRequest
.
Quality
==
""
{
imageRequest
.
Quality
=
"auto"
}
}
}
if
imageRequest
.
Prompt
==
""
{
return
nil
,
errors
.
New
(
"prompt is required"
)
}
if
imageRequest
.
Model
==
""
{
imageRequest
.
Model
=
"dall-e-2"
}
if
strings
.
Contains
(
imageRequest
.
Size
,
"×"
)
{
return
nil
,
errors
.
New
(
"size an unexpected error occurred in the parameter, please use 'x' instead of the multiplication sign '×'"
)
}
if
imageRequest
.
N
==
0
{
imageRequest
.
N
=
1
}
if
imageRequest
.
Size
==
""
{
imageRequest
.
Size
=
"1024x1024"
}
err
:=
common
.
UnmarshalBodyReusable
(
c
,
imageRequest
)
if
err
!=
nil
{
return
nil
,
err
}
if
imageRequest
.
Prompt
==
""
{
return
nil
,
errors
.
New
(
"prompt is required"
)
}
if
strings
.
Contains
(
imageRequest
.
Size
,
"×"
)
{
return
nil
,
errors
.
New
(
"size an unexpected error occurred in the parameter, please use 'x' instead of the multiplication sign '×'"
)
}
if
imageRequest
.
N
==
0
{
imageRequest
.
N
=
1
}
if
imageRequest
.
Size
==
""
{
imageRequest
.
Size
=
"1024x1024"
}
if
imageRequest
.
Model
==
""
{
imageRequest
.
Model
=
"dall-e-2"
}
// x.ai grok-2-image not support size, quality or style
if
imageRequest
.
Size
==
"empty"
{
imageRequest
.
Size
=
""
}
// Not "256x256", "512x512", or "1024x1024"
if
imageRequest
.
Model
==
"dall-e-2"
||
imageRequest
.
Model
==
"dall-e"
{
if
imageRequest
.
Size
!=
""
&&
imageRequest
.
Size
!=
"256x256"
&&
imageRequest
.
Size
!=
"512x512"
&&
imageRequest
.
Size
!=
"1024x1024"
{
return
nil
,
errors
.
New
(
"size must be one of 256x256, 512x512, or 1024x1024, dall-e-3 1024x1792 or 1792x1024"
)
if
imageRequest
.
Prompt
==
""
{
return
nil
,
errors
.
New
(
"prompt is required"
)
}
}
else
if
imageRequest
.
Model
==
"dall-e-3"
{
if
imageRequest
.
Size
!=
""
&&
imageRequest
.
Size
!=
"1024x1024"
&&
imageRequest
.
Size
!=
"1024x1792"
&&
imageRequest
.
Size
!=
"1792x1024"
{
return
nil
,
errors
.
New
(
"size must be one of 256x256, 512x512, or 1024x1024, dall-e-3 1024x1792 or 1792x1024"
)
}
if
imageRequest
.
Quality
==
""
{
imageRequest
.
Quality
=
"standard"
if
imageRequest
.
N
==
0
{
imageRequest
.
N
=
1
}
//if imageRequest.N != 1 {
// return nil, errors.New("n must be 1")
//}
}
// N should between 1 and 10
//if imageRequest.N != 0 && (imageRequest.N < 1 || imageRequest.N > 10) {
// return service.OpenAIErrorWrapper(errors.New("n must be between 1 and 10"), "invalid_field_value", http.StatusBadRequest)
//}
if
setting
.
ShouldCheckPromptSensitive
()
{
words
,
err
:=
service
.
CheckSensitiveInput
(
imageRequest
.
Prompt
)
if
err
!=
nil
{
...
...
@@ -229,6 +191,10 @@ func ImageHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
requestBody
=
bytes
.
NewBuffer
(
jsonData
)
}
if
common
.
DebugEnabled
{
println
(
fmt
.
Sprintf
(
"image request body: %s"
,
requestBody
))
}
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
relayInfo
,
requestBody
)
...
...
web/src/index.css
View file @
bb8923e7
...
...
@@ -98,17 +98,6 @@ body {
display
:
revert
;
}
.semi-chat
{
padding-top
:
0
!important
;
padding-bottom
:
0
!important
;
height
:
100%
;
}
.semi-chat-chatBox-content
{
min-width
:
auto
;
word-break
:
break-word
;
}
.tableHiddle
{
display
:
none
!important
;
}
...
...
@@ -158,4 +147,114 @@ code {
.semi-tabs-content
{
padding
:
0
!important
;
}
/* 聊天 */
.semi-chat
{
padding-top
:
0
!important
;
padding-bottom
:
0
!important
;
height
:
100%
;
max-width
:
100%
!important
;
width
:
100%
!important
;
overflow
:
hidden
!important
;
}
.semi-chat-chatBox
{
max-width
:
100%
!important
;
overflow
:
hidden
!important
;
}
.semi-chat-chatBox-wrap
{
max-width
:
100%
!important
;
overflow
:
hidden
!important
;
}
.semi-chat-chatBox-content
{
min-width
:
auto
;
word-break
:
break-word
;
max-width
:
100%
!important
;
overflow-wrap
:
break-word
!important
;
}
.semi-chat-content
{
max-width
:
100%
!important
;
overflow
:
hidden
!important
;
}
.semi-chat-list
{
max-width
:
100%
!important
;
overflow-x
:
hidden
!important
;
}
.semi-chat-container
{
overflow-x
:
hidden
!important
;
}
.semi-chat-container
::-webkit-scrollbar
{
width
:
4px
;
}
.semi-chat-container
::-webkit-scrollbar-thumb
{
background
:
rgba
(
0
,
0
,
0
,
0.1
);
border-radius
:
2px
;
}
.semi-chat-container
::-webkit-scrollbar-thumb:hover
{
background
:
rgba
(
0
,
0
,
0
,
0.15
);
}
.semi-chat-container
::-webkit-scrollbar-track
{
background
:
transparent
;
}
/* 隐藏模型设置区域的滚动条 */
.model-settings-scroll
::-webkit-scrollbar
{
display
:
none
;
}
.model-settings-scroll
{
-ms-overflow-style
:
none
;
scrollbar-width
:
none
;
}
/* 调试面板代码样式 */
.debug-code
{
font-family
:
'Monaco'
,
'Menlo'
,
'Ubuntu Mono'
,
monospace
;
font-size
:
11px
;
line-height
:
1.4
;
}
/* 调试面板标签样式 */
.semi-tabs-content
{
height
:
calc
(
100%
-
40px
)
!important
;
flex
:
1
!important
;
}
.semi-tabs-content
.semi-tabs-pane
{
height
:
100%
!important
;
overflow
:
hidden
!important
;
}
.semi-tabs-content
.semi-tabs-pane
>
div
{
height
:
100%
!important
;
}
/* 调试面板特定样式 */
.debug-panel
.semi-tabs
{
height
:
100%
!important
;
display
:
flex
!important
;
flex-direction
:
column
!important
;
}
.debug-panel
.semi-tabs-bar
{
flex-shrink
:
0
!important
;
}
.debug-panel
.semi-tabs-content
{
flex
:
1
!important
;
overflow
:
hidden
!important
;
}
.semi-chat-chatBox-action
{
column-gap
:
0
!important
;
}
\ No newline at end of file
web/src/pages/Playground/Playground.js
View file @
bb8923e7
This diff is collapsed.
Click to expand it.
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