| 38 | } |
| 39 | |
| 40 | func testChannel(channel *model.Channel, testModel string) testResult { |
| 41 | tik := time.Now() |
| 42 | if channel.Type == constant.ChannelTypeMidjourney { |
| 43 | return testResult{ |
| 44 | localErr: errors.New("midjourney channel test is not supported"), |
| 45 | newAPIError: nil, |
| 46 | } |
| 47 | } |
| 48 | if channel.Type == constant.ChannelTypeMidjourneyPlus { |
| 49 | return testResult{ |
| 50 | localErr: errors.New("midjourney plus channel test is not supported"), |
| 51 | newAPIError: nil, |
| 52 | } |
| 53 | } |
| 54 | if channel.Type == constant.ChannelTypeSunoAPI { |
| 55 | return testResult{ |
| 56 | localErr: errors.New("suno channel test is not supported"), |
| 57 | newAPIError: nil, |
| 58 | } |
| 59 | } |
| 60 | if channel.Type == constant.ChannelTypeKling { |
| 61 | return testResult{ |
| 62 | localErr: errors.New("kling channel test is not supported"), |
| 63 | newAPIError: nil, |
| 64 | } |
| 65 | } |
| 66 | if channel.Type == constant.ChannelTypeJimeng { |
| 67 | return testResult{ |
| 68 | localErr: errors.New("jimeng channel test is not supported"), |
| 69 | newAPIError: nil, |
| 70 | } |
| 71 | } |
| 72 | w := httptest.NewRecorder() |
| 73 | c, _ := gin.CreateTestContext(w) |
| 74 | |
| 75 | requestPath := "/v1/chat/completions" |
| 76 | |
| 77 | // 先判断是否为 Embedding 模型 |
| 78 | if strings.Contains(strings.ToLower(testModel), "embedding") || |
| 79 | strings.HasPrefix(testModel, "m3e") || // m3e 系列模型 |
| 80 | strings.Contains(testModel, "bge-") || // bge 系列模型 |
| 81 | strings.Contains(testModel, "embed") || |
| 82 | channel.Type == constant.ChannelTypeMokaAI { // 其他 embedding 模型 |
| 83 | requestPath = "/v1/embeddings" // 修改请求路径 |
| 84 | } |
| 85 | |
| 86 | c.Request = &http.Request{ |
| 87 | Method: "POST", |
| 88 | URL: &url.URL{Path: requestPath}, // 使用动态路径 |
| 89 | Body: nil, |
| 90 | Header: make(http.Header), |
| 91 | } |
| 92 | |
| 93 | if testModel == "" { |
| 94 | if channel.TestModel != nil && *channel.TestModel != "" { |
| 95 | testModel = *channel.TestModel |
| 96 | } else { |
| 97 | if len(channel.GetModels()) > 0 { |