feat: add deployment_mapping for Azure OpenAI

This commit is contained in:
WqyJh
2023-11-20 16:00:21 +08:00
parent 495fc628e4
commit 9042b7c4e4
5 changed files with 68 additions and 12 deletions

View File

@@ -33,18 +33,19 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
case common.ChannelTypeXunfei:
return errors.New("该渠道类型当前版本不支持测试,请手动测试"), nil
case common.ChannelTypeAzure:
request.Model = "gpt-35-turbo"
defer func() {
if err != nil {
err = errors.New("请确保已在 Azure 上创建了 gpt-35-turbo 模型,并且 apiVersion 已正确填写!")
err = errors.New("请确保已在 Azure 上创建了 gpt-35-turbo 模型,或正确配置部署映射,并且 apiVersion 已正确填写!")
}
}()
fallthrough
default:
request.Model = "gpt-3.5-turbo"
}
requestURL := common.ChannelBaseURLs[channel.Type]
if channel.Type == common.ChannelTypeAzure {
requestURL = getFullRequestURL(channel.GetBaseURL(), fmt.Sprintf("/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview", request.Model), channel.Type)
deployment := channel.GetDeployment(request.Model)
requestURL = fmt.Sprintf("%s/openai/deployments/%s/chat/completions?api-version=%s", channel.GetBaseURL(), deployment, channel.Other)
} else {
if baseURL := channel.GetBaseURL(); len(baseURL) > 0 {
requestURL = baseURL

View File

@@ -141,15 +141,13 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, apiVersion)
baseURL = c.GetString("base_url")
task := strings.TrimPrefix(requestURL, "/v1/")
model_ := textRequest.Model
model_ = strings.Replace(model_, ".", "", -1)
// https://github.com/songquanpeng/one-api/issues/67
model_ = strings.TrimSuffix(model_, "-0301")
model_ = strings.TrimSuffix(model_, "-0314")
model_ = strings.TrimSuffix(model_, "-0613")
requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
fullRequestURL = getFullRequestURL(baseURL, requestURL, channelType)
deploymentMapping := c.GetStringMapString("deployment_mapping")
deployment := deploymentMapping[textRequest.Model]
if deployment == "" {
deployment = model.ModelToDeployment(textRequest.Model)
}
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/%s", baseURL, deployment, task)
}
case APITypeClaude:
fullRequestURL = "https://api.anthropic.com/v1/complete"