TestChannel Test channel availability @Summary Test channel connectivity @Description Verify channel configuration by invoking actual API endpoints @Tags Channel @Accept json @Produce json @Security BearerAuth @Param channel_id path int true "Channel ID" @Param model query string false "Model name"
(c *gin.Context)
| 50 | // @Success 200 {object} model.CommonResponse{data=ChannelTestResponse} |
| 51 | // @Router /api/channels/test/{channel_id} [get] |
| 52 | func TestChannel(c *gin.Context) { |
| 53 | ctx := c.Request.Context() |
| 54 | channel_id, err := strconv.Atoi(c.Param("channel_id")) |
| 55 | if err != nil { |
| 56 | c.JSON(http.StatusOK, model.ParamError.ToResponse(err)) |
| 57 | return |
| 58 | } |
| 59 | channel, err := model.GetChannelByID(int64(channel_id)) |
| 60 | if err != nil { |
| 61 | c.JSON(http.StatusOK, model.ParamError.ToResponse(err)) |
| 62 | return |
| 63 | } |
| 64 | modelName := c.Query("model") |
| 65 | modelType := c.Query("model_type") // 获取model_type参数 |
| 66 | testRequest := buildTestRequest(modelName) |
| 67 | tik := time.Now() |
| 68 | |
| 69 | // 如果提供了model_type,则优先使用它来判断模型类型 |
| 70 | if modelType != "" { |
| 71 | switch modelType { |
| 72 | case "3", "rerank": |
| 73 | responseMessage, err := testRerankChannel(ctx, channel, modelName) |
| 74 | returnResponse(c, channel, tik, modelName, responseMessage, err) |
| 75 | return |
| 76 | case "2", "embedding": |
| 77 | responseMessage, err := testEmbeddingChannel(ctx, channel, modelName) |
| 78 | returnResponse(c, channel, tik, modelName, responseMessage, err) |
| 79 | return |
| 80 | case "1", "chat": |
| 81 | // 跳过下面的自动检测,直接进入聊天模型测试 |
| 82 | default: |
| 83 | // 对于未知类型,仍然使用原有检测逻辑 |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // 如果没有提供model_type或model_type为未知类型,使用原有检测逻辑 |
| 88 | // 检查是否为 rerank 模型 |
| 89 | if isRerankModel(modelName) { |
| 90 | responseMessage, err := testRerankChannel(ctx, channel, modelName) |
| 91 | returnResponse(c, channel, tik, modelName, responseMessage, err) |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | // 检查是否为 embedding 模型 |
| 96 | if isEmbeddingModel(modelName) { |
| 97 | responseMessage, err := testEmbeddingChannel(ctx, channel, modelName) |
| 98 | returnResponse(c, channel, tik, modelName, responseMessage, err) |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | // 检查是否为图像生成模型 |
| 103 | if isImageGenerationModel(modelName) { |
| 104 | responseMessage, err := testImageGenerationChannel(ctx, channel, modelName) |
| 105 | returnResponse(c, channel, tik, modelName, responseMessage, err) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | // 原有的聊天模型测试逻辑 |
nothing calls this directly
no test coverage detected