| 73 | } |
| 74 | |
| 75 | func testChannel(ctx context.Context, channel *model.Channel, testUserID int, testModel string, endpointType string, isStream bool) testResult { |
| 76 | if ctx == nil { |
| 77 | ctx = context.Background() |
| 78 | } |
| 79 | tik := time.Now() |
| 80 | var unsupportedTestChannelTypes = []int{ |
| 81 | constant.ChannelTypeMidjourney, |
| 82 | constant.ChannelTypeMidjourneyPlus, |
| 83 | constant.ChannelTypeSunoAPI, |
| 84 | constant.ChannelTypeKling, |
| 85 | constant.ChannelTypeJimeng, |
| 86 | constant.ChannelTypeDoubaoVideo, |
| 87 | constant.ChannelTypeVidu, |
| 88 | } |
| 89 | if lo.Contains(unsupportedTestChannelTypes, channel.Type) { |
| 90 | channelTypeName := constant.GetChannelTypeName(channel.Type) |
| 91 | return testResult{ |
| 92 | localErr: fmt.Errorf("%s channel test is not supported", channelTypeName), |
| 93 | } |
| 94 | } |
| 95 | w := httptest.NewRecorder() |
| 96 | c, _ := gin.CreateTestContext(w) |
| 97 | |
| 98 | testModel = strings.TrimSpace(testModel) |
| 99 | if testModel == "" { |
| 100 | if channel.TestModel != nil && *channel.TestModel != "" { |
| 101 | testModel = strings.TrimSpace(*channel.TestModel) |
| 102 | } else { |
| 103 | models := channel.GetModels() |
| 104 | if len(models) > 0 { |
| 105 | testModel = strings.TrimSpace(models[0]) |
| 106 | } |
| 107 | if testModel == "" { |
| 108 | testModel = "gpt-4o-mini" |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | endpointType = normalizeChannelTestEndpoint(channel, testModel, endpointType) |
| 114 | |
| 115 | requestPath := "/v1/chat/completions" |
| 116 | |
| 117 | // 如果指定了端点类型,使用指定的端点类型 |
| 118 | if endpointType != "" { |
| 119 | if endpointInfo, ok := common.GetDefaultEndpointInfo(constant.EndpointType(endpointType)); ok { |
| 120 | requestPath = endpointInfo.Path |
| 121 | } |
| 122 | } else { |
| 123 | // 如果没有指定端点类型,使用原有的自动检测逻辑 |
| 124 | |
| 125 | if strings.Contains(strings.ToLower(testModel), "rerank") { |
| 126 | requestPath = "/v1/rerank" |
| 127 | } |
| 128 | |
| 129 | // 先判断是否为 Embedding 模型 |
| 130 | if strings.Contains(strings.ToLower(testModel), "embedding") || |
| 131 | strings.HasPrefix(testModel, "m3e") || // m3e 系列模型 |
| 132 | strings.Contains(testModel, "bge-") || // bge 系列模型 |