From 15f815c23cf5365dc19cdba718ad7337fd335963 Mon Sep 17 00:00:00 2001 From: leavegee <474451886@qq.com> Date: Sat, 21 Sep 2024 22:40:06 +0800 Subject: [PATCH] fix: fix ali embedding model always use v1 (#1747) * fix:ali embedding model: v2 and v3 * chore: use ctxkey.RequestModel to eliminate hardcoding --------- Co-authored-by: xuejia Co-authored-by: JustSong --- relay/adaptor/ali/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/relay/adaptor/ali/main.go b/relay/adaptor/ali/main.go index f9039dbe..ec5848ce 100644 --- a/relay/adaptor/ali/main.go +++ b/relay/adaptor/ali/main.go @@ -3,6 +3,7 @@ package ali import ( "bufio" "encoding/json" + "github.com/songquanpeng/one-api/common/ctxkey" "github.com/songquanpeng/one-api/common/render" "io" "net/http" @@ -59,7 +60,7 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest { func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) *EmbeddingRequest { return &EmbeddingRequest{ - Model: "text-embedding-v1", + Model: request.Model, Input: struct { Texts []string `json:"texts"` }{ @@ -102,8 +103,9 @@ func EmbeddingHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStat StatusCode: resp.StatusCode, }, nil } - + requestModel := c.GetString(ctxkey.RequestModel) fullTextResponse := embeddingResponseAli2OpenAI(&aliResponse) + fullTextResponse.Model = requestModel jsonResponse, err := json.Marshal(fullTextResponse) if err != nil { return openai.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError), nil