|
|
@@ -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,25 @@ 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特殊字段。若失败重建一个空的。
|
|
|
+ extra, _ := common.Marshal(request.Extra)
|
|
|
+ sfRequest := &SFImageRequest{}
|
|
|
+ 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 +69,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
|
|
|
}
|