MCPcopy Index your code
hub / github.com/53AI/53AIHub / TestChannel

Function TestChannel

api/controller/channel-test.go:52–128  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

50// @Success 200 {object} model.CommonResponse{data=ChannelTestResponse}
51// @Router /api/channels/test/{channel_id} [get]
52func 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 // 原有的聊天模型测试逻辑

Callers

nothing calls this directly

Calls 12

buildTestRequestFunction · 0.85
testRerankChannelFunction · 0.85
returnResponseFunction · 0.85
testEmbeddingChannelFunction · 0.85
isRerankModelFunction · 0.85
isEmbeddingModelFunction · 0.85
isImageGenerationModelFunction · 0.85
testChannelFunction · 0.85
ToResponseMethod · 0.80
UpdateResponseTimeMethod · 0.80
QueryMethod · 0.65

Tested by

no test coverage detected