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
c62daee6
authored
Oct 14, 2025
by
Seefs
Committed by
GitHub
Oct 14, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2036 from etnAtker/siliconflow-images-generations
feat: 添加SiliconFlow图像生成接口自动转换支持
parents
7391b15b
fc2486d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
relay/channel/siliconflow/adaptor.go
+26
-2
relay/channel/siliconflow/dto.go
+15
-0
No files found.
relay/channel/siliconflow/adaptor.go
View file @
c62daee6
...
...
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/relay/channel"
"github.com/QuantumNous/new-api/relay/channel/openai"
...
...
@@ -35,8 +36,27 @@ func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInf
}
func
(
a
*
Adaptor
)
ConvertImageRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
ImageRequest
)
(
any
,
error
)
{
adaptor
:=
openai
.
Adaptor
{}
return
adaptor
.
ConvertImageRequest
(
c
,
info
,
request
)
// 解析extra到SFImageRequest里,以填入SiliconFlow特殊字段。若失败重建一个空的。
sfRequest
:=
&
SFImageRequest
{}
extra
,
err
:=
common
.
Marshal
(
request
.
Extra
)
if
err
==
nil
{
err
=
common
.
Unmarshal
(
extra
,
sfRequest
)
if
err
!=
nil
{
sfRequest
=
&
SFImageRequest
{}
}
}
sfRequest
.
Model
=
request
.
Model
sfRequest
.
Prompt
=
request
.
Prompt
// 优先使用image_size/batch_size,否则使用OpenAI标准的size/n
if
sfRequest
.
ImageSize
==
""
{
sfRequest
.
ImageSize
=
request
.
Size
}
if
sfRequest
.
BatchSize
==
0
{
sfRequest
.
BatchSize
=
request
.
N
}
return
sfRequest
,
nil
}
func
(
a
*
Adaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
...
...
@@ -51,6 +71,8 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
return
fmt
.
Sprintf
(
"%s/v1/chat/completions"
,
info
.
ChannelBaseUrl
),
nil
}
else
if
info
.
RelayMode
==
constant
.
RelayModeCompletions
{
return
fmt
.
Sprintf
(
"%s/v1/completions"
,
info
.
ChannelBaseUrl
),
nil
}
else
if
info
.
RelayMode
==
constant
.
RelayModeImagesGenerations
{
return
fmt
.
Sprintf
(
"%s/v1/images/generations"
,
info
.
ChannelBaseUrl
),
nil
}
return
fmt
.
Sprintf
(
"%s/v1/chat/completions"
,
info
.
ChannelBaseUrl
),
nil
}
...
...
@@ -102,6 +124,8 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycom
fallthrough
case
constant
.
RelayModeChatCompletions
:
fallthrough
case
constant
.
RelayModeImagesGenerations
:
fallthrough
default
:
if
info
.
IsStream
{
usage
,
err
=
openai
.
OaiStreamHandler
(
c
,
info
,
resp
)
...
...
relay/channel/siliconflow/dto.go
View file @
c62daee6
...
...
@@ -15,3 +15,18 @@ type SFRerankResponse struct {
Results
[]
dto
.
RerankResponseResult
`json:"results"`
Meta
SFMeta
`json:"meta"`
}
type
SFImageRequest
struct
{
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
NegativePrompt
string
`json:"negative_prompt,omitempty"`
ImageSize
string
`json:"image_size,omitempty"`
BatchSize
uint
`json:"batch_size,omitempty"`
Seed
uint64
`json:"seed,omitempty"`
NumInferenceSteps
uint
`json:"num_inference_steps,omitempty"`
GuidanceScale
float64
`json:"guidance_scale,omitempty"`
Cfg
float64
`json:"cfg,omitempty"`
Image
string
`json:"image,omitempty"`
Image2
string
`json:"image2,omitempty"`
Image3
string
`json:"image3,omitempty"`
}
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