Skip to content

Commit

Permalink
fix: fix ali embedding model always use v1 (#1747)
Browse files Browse the repository at this point in the history
* fix:ali embedding model: v2 and v3

* chore: use ctxkey.RequestModel to eliminate hardcoding

---------

Co-authored-by: xuejia <[email protected]>
Co-authored-by: JustSong <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2024
1 parent 89b63ca commit 15f815c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions relay/adaptor/ali/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
}{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 15f815c

Please sign in to comment.