chore: use ctxkey.RequestModel to eliminate hardcoding

This commit is contained in:
JustSong 2024-09-21 22:39:30 +08:00
parent f9c4384ccc
commit fcd4d2eaaf

View File

@ -3,6 +3,7 @@ package ali
import ( import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"github.com/songquanpeng/one-api/common/ctxkey"
"github.com/songquanpeng/one-api/common/render" "github.com/songquanpeng/one-api/common/render"
"io" "io"
"net/http" "net/http"
@ -102,9 +103,9 @@ func EmbeddingHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStat
StatusCode: resp.StatusCode, StatusCode: resp.StatusCode,
}, nil }, nil
} }
reqeustModel := c.Keys["request_model"] requestModel := c.GetString(ctxkey.RequestModel)
fullTextResponse := embeddingResponseAli2OpenAI(&aliResponse) fullTextResponse := embeddingResponseAli2OpenAI(&aliResponse)
fullTextResponse.Model = reqeustModel.(string) fullTextResponse.Model = requestModel
jsonResponse, err := json.Marshal(fullTextResponse) jsonResponse, err := json.Marshal(fullTextResponse)
if err != nil { if err != nil {
return openai.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError), nil return openai.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError), nil