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 {
case relaymode.Embeddings:
baiduEmbeddingRequest := ConvertEmbeddingRequest(*request)
return baiduEmbeddingRequest, nil
baiduEmbeddingRequest, err := ConvertEmbeddingRequest(*request)
return baiduEmbeddingRequest, err
default:
// TopP (0.0, 1.0)
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
}
func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) *EmbeddingRequest {
return &EmbeddingRequest{
Model: "embedding-2",
Input: request.Input.(string),
func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) (*EmbeddingRequest, error) {
inputs := request.ParseInput()
if len(inputs) != 1 {
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 {