From 35ca91fc5e9f72aec0a2a66f98fcdce1fbcd808d Mon Sep 17 00:00:00 2001 From: linzhaoming Date: Tue, 18 Jun 2024 16:38:36 +0800 Subject: [PATCH] fix: model redirect --- controller/channel-test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 469e3c8..c7067d0 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -55,6 +55,8 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr meta := relaycommon.GenRelayInfo(c) apiType, _ := constant.ChannelType2APIType(channel.Type) adaptor := relay.GetAdaptor(apiType) + // OpenAI 适配器需要 channelType + adaptor.Init(meta, dto.GeneralOpenAIRequest{}) if adaptor == 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 { testModel = adaptor.GetModelList()[0] } - } else { - modelMapping := *channel.ModelMapping - if modelMapping != "" && modelMapping != "{}" { - modelMap := make(map[string]string) - err := json.Unmarshal([]byte(modelMapping), &modelMap) - if err != nil { - openaiErr := service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError).Error - return err, &openaiErr - } - if modelMap[testModel] != "" { - testModel = modelMap[testModel] - } + } + modelMapping := *channel.ModelMapping + if modelMapping != "" && modelMapping != "{}" { + modelMap := make(map[string]string) + err := json.Unmarshal([]byte(modelMapping), &modelMap) + if err != nil { + openaiErr := service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError).Error + return err, &openaiErr + } + if modelMap[testModel] != "" { + testModel = modelMap[testModel] } } - request := buildTestRequest() request.Model = testModel meta.UpstreamModelName = testModel