fix: model redirect

This commit is contained in:
linzhaoming 2024-06-18 16:38:36 +08:00
parent 62e9a628a6
commit 35ca91fc5e

View File

@ -55,6 +55,8 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
meta := relaycommon.GenRelayInfo(c) meta := relaycommon.GenRelayInfo(c)
apiType, _ := constant.ChannelType2APIType(channel.Type) apiType, _ := constant.ChannelType2APIType(channel.Type)
adaptor := relay.GetAdaptor(apiType) adaptor := relay.GetAdaptor(apiType)
// OpenAI 适配器需要 channelType
adaptor.Init(meta, dto.GeneralOpenAIRequest{})
if adaptor == nil { if adaptor == nil {
return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil
} }
@ -64,21 +66,19 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
} else { } else {
testModel = adaptor.GetModelList()[0] testModel = adaptor.GetModelList()[0]
} }
} else { }
modelMapping := *channel.ModelMapping modelMapping := *channel.ModelMapping
if modelMapping != "" && modelMapping != "{}" { if modelMapping != "" && modelMapping != "{}" {
modelMap := make(map[string]string) modelMap := make(map[string]string)
err := json.Unmarshal([]byte(modelMapping), &modelMap) err := json.Unmarshal([]byte(modelMapping), &modelMap)
if err != nil { if err != nil {
openaiErr := service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError).Error openaiErr := service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError).Error
return err, &openaiErr return err, &openaiErr
} }
if modelMap[testModel] != "" { if modelMap[testModel] != "" {
testModel = modelMap[testModel] testModel = modelMap[testModel]
}
} }
} }
request := buildTestRequest() request := buildTestRequest()
request.Model = testModel request.Model = testModel
meta.UpstreamModelName = testModel meta.UpstreamModelName = testModel