fix: fix zhipu embedding error when input is array but not string (#1306)

* fix zhipu embedding error when input is array but not string

* fix: only use the first one

---------

Co-authored-by: 蔡新疆 <cxj@icc.link>
Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
caixinjiang 2024-04-27 16:05:14 +08:00 committed by GitHub
parent a84c7b38b7
commit 6cffb116b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,8 +62,8 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G
} }
switch relayMode { switch relayMode {
case relaymode.Embeddings: case relaymode.Embeddings:
baiduEmbeddingRequest := ConvertEmbeddingRequest(*request) baiduEmbeddingRequest, err := ConvertEmbeddingRequest(*request)
return baiduEmbeddingRequest, nil return baiduEmbeddingRequest, err
default: default:
// TopP (0.0, 1.0) // TopP (0.0, 1.0)
request.TopP = math.Min(0.99, request.TopP) request.TopP = math.Min(0.99, request.TopP)
@ -129,11 +129,15 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Met
return return
} }
func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) *EmbeddingRequest { func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) (*EmbeddingRequest, error) {
return &EmbeddingRequest{ inputs := request.ParseInput()
Model: "embedding-2", if len(inputs) != 1 {
Input: request.Input.(string), return nil, errors.New("invalid input length, zhipu only support one input")
} }
return &EmbeddingRequest{
Model: request.Model,
Input: inputs[0],
}, nil
} }
func (a *Adaptor) GetModelList() []string { func (a *Adaptor) GetModelList() []string {