mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-21 07:26:47 +08:00
refactor: use model_mapping instead of deployment_mapping
This commit is contained in:
@@ -35,7 +35,7 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
|
||||
case common.ChannelTypeAzure:
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err = errors.New("请确保已在 Azure 上创建了 gpt-35-turbo 模型,或正确配置部署映射,并且 apiVersion 已正确填写!")
|
||||
err = errors.New("请确保已在 Azure 上创建了 gpt-35-turbo 模型,或正确配置模型映射,并且 apiVersion 已正确填写!")
|
||||
}
|
||||
}()
|
||||
fallthrough
|
||||
@@ -44,8 +44,11 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
|
||||
}
|
||||
requestURL := common.ChannelBaseURLs[channel.Type]
|
||||
if channel.Type == common.ChannelTypeAzure {
|
||||
deployment := channel.GetDeployment(request.Model)
|
||||
requestURL = fmt.Sprintf("%s/openai/deployments/%s/chat/completions?api-version=%s", channel.GetBaseURL(), deployment, channel.Other)
|
||||
modelMap := channel.GetModelMapping()
|
||||
if modelMap[request.Model] != "" {
|
||||
request.Model = modelMap[request.Model]
|
||||
}
|
||||
requestURL = getFullRequestURL(channel.GetBaseURL(), fmt.Sprintf("/openai/deployments/%s/chat/completions?api-version=%s", request.Model, channel.Other), channel.Type)
|
||||
} else {
|
||||
if baseURL := channel.GetBaseURL(); len(baseURL) > 0 {
|
||||
requestURL = baseURL
|
||||
|
||||
@@ -90,18 +90,12 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
}
|
||||
}
|
||||
// map model name
|
||||
modelMapping := c.GetString("model_mapping")
|
||||
modelMapping := c.GetStringMapString("model_mapping")
|
||||
isModelMapped := false
|
||||
if modelMapping != "" && modelMapping != "{}" {
|
||||
modelMap := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(modelMapping), &modelMap)
|
||||
if err != nil {
|
||||
return errorWrapper(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError)
|
||||
}
|
||||
if modelMap[textRequest.Model] != "" {
|
||||
textRequest.Model = modelMap[textRequest.Model]
|
||||
isModelMapped = true
|
||||
}
|
||||
originalModel := textRequest.Model
|
||||
if modelMapping[textRequest.Model] != "" {
|
||||
textRequest.Model = modelMapping[textRequest.Model]
|
||||
isModelMapped = true
|
||||
}
|
||||
apiType := APITypeOpenAI
|
||||
switch channelType {
|
||||
@@ -142,9 +136,11 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
baseURL = c.GetString("base_url")
|
||||
task := strings.TrimPrefix(requestURL, "/v1/")
|
||||
|
||||
deploymentMapping := c.GetStringMapString("deployment_mapping")
|
||||
deployment := deploymentMapping[textRequest.Model]
|
||||
if deployment == "" {
|
||||
var deployment string
|
||||
if isModelMapped {
|
||||
deployment = textRequest.Model
|
||||
textRequest.Model = originalModel
|
||||
} else {
|
||||
deployment = model.ModelToDeployment(textRequest.Model)
|
||||
}
|
||||
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/%s", baseURL, deployment, task)
|
||||
|
||||
Reference in New Issue
Block a user