@@ -25,7 +25,7 @@ import (
2525 "github.com/labring/aiproxy/monitor"
2626 "github.com/labring/aiproxy/relay/channeltype"
2727 "github.com/labring/aiproxy/relay/meta"
28- "github.com/labring/aiproxy/relay/relaymode "
28+ "github.com/labring/aiproxy/relay/mode "
2929 "github.com/labring/aiproxy/relay/utils"
3030 log "github.com/sirupsen/logrus"
3131)
@@ -60,7 +60,7 @@ func testSingleModel(mc *model.ModelCaches, channel *model.Channel, modelName st
6060 if ! ok {
6161 return nil , errors .New (modelName + " model config not found" )
6262 }
63- if modelConfig .Type == relaymode .Unknown {
63+ if modelConfig .Type == mode .Unknown {
6464 newModelConfig := guessModelConfig (modelName )
6565 if newModelConfig != nil {
6666 modelConfig = newModelConfig
@@ -81,7 +81,7 @@ func testSingleModel(mc *model.ModelCaches, channel *model.Channel, modelName st
8181 }, nil
8282 }
8383
84- body , mode , err := utils .BuildRequest (modelConfig )
84+ body , m , err := utils .BuildRequest (modelConfig )
8585 if err != nil {
8686 return nil , err
8787 }
@@ -97,23 +97,23 @@ func testSingleModel(mc *model.ModelCaches, channel *model.Channel, modelName st
9797
9898 meta := meta .NewMeta (
9999 channel ,
100- mode ,
100+ m ,
101101 modelName ,
102102 modelConfig ,
103103 meta .WithRequestID (channelTestRequestID ),
104104 )
105- relayController , ok := relayController (mode )
105+ relayController , ok := relayController (m )
106106 if ! ok {
107- return nil , fmt .Errorf ("relay mode %d not implemented" , mode )
107+ return nil , fmt .Errorf ("relay mode %d not implemented" , m )
108108 }
109109 result := relayController (meta , newc )
110110 success := result .Error == nil
111111 var respStr string
112112 var code int
113113 if success {
114114 switch meta .Mode {
115- case relaymode .AudioSpeech ,
116- relaymode .ImagesGenerations :
115+ case mode .AudioSpeech ,
116+ mode .ImagesGenerations :
117117 respStr = ""
118118 default :
119119 respStr = w .Body .String ()
@@ -136,6 +136,18 @@ func testSingleModel(mc *model.ModelCaches, channel *model.Channel, modelName st
136136 )
137137}
138138
139+ // TestChannel godoc
140+ //
141+ // @Summary Test channel model
142+ // @Description Tests a single model in the channel
143+ // @Tags channel
144+ // @Produce json
145+ // @Security ApiKeyAuth
146+ // @Param id path int true "Channel ID"
147+ // @Param model path string true "Model name"
148+ // @Success 200 {object} middleware.APIResponse{data=model.ChannelTest}
149+ // @Router /api/channel/{id}/{model} [get]
150+ //
139151//nolint:goconst
140152func TestChannel (c * gin.Context ) {
141153 id , err := strconv .Atoi (c .Param ("id" ))
@@ -193,13 +205,13 @@ func TestChannel(c *gin.Context) {
193205 })
194206}
195207
196- type testResult struct {
208+ type TestResult struct {
197209 Data * model.ChannelTest `json:"data,omitempty"`
198210 Message string `json:"message,omitempty"`
199211 Success bool `json:"success"`
200212}
201213
202- func processTestResult (mc * model.ModelCaches , channel * model.Channel , modelName string , returnSuccess bool , successResponseBody bool ) * testResult {
214+ func processTestResult (mc * model.ModelCaches , channel * model.Channel , modelName string , returnSuccess bool , successResponseBody bool ) * TestResult {
203215 ct , err := testSingleModel (mc , channel , modelName )
204216
205217 e := & utils.UnsupportedModelTypeError {}
@@ -208,7 +220,7 @@ func processTestResult(mc *model.ModelCaches, channel *model.Channel, modelName
208220 return nil
209221 }
210222
211- result := & testResult {
223+ result := & TestResult {
212224 Success : err == nil ,
213225 }
214226 if err != nil {
@@ -232,6 +244,16 @@ func processTestResult(mc *model.ModelCaches, channel *model.Channel, modelName
232244 return result
233245}
234246
247+ // TestChannelModels godoc
248+ //
249+ // @Summary Test channel models
250+ // @Description Tests all models in the channel
251+ // @Tags channel
252+ // @Produce json
253+ // @Security ApiKeyAuth
254+ // @Param id path int true "Channel ID"
255+ // @Success 200 {object} middleware.APIResponse{data=[]TestResult}
256+ // @Router /api/channel/{id}/models [get]
235257func TestChannelModels (c * gin.Context ) {
236258 id , err := strconv .Atoi (c .Param ("id" ))
237259 if err != nil {
@@ -259,7 +281,7 @@ func TestChannelModels(c *gin.Context) {
259281 common .SetEventStreamHeaders (c )
260282 }
261283
262- results := make ([]* testResult , 0 )
284+ results := make ([]* TestResult , 0 )
263285 resultsMutex := sync.Mutex {}
264286 hasError := atomic.Bool {}
265287
@@ -318,6 +340,16 @@ func TestChannelModels(c *gin.Context) {
318340 }
319341}
320342
343+ // TestAllChannels godoc
344+ //
345+ // @Summary Test all channels
346+ // @Description Tests all channels
347+ // @Tags channel
348+ // @Produce json
349+ // @Security ApiKeyAuth
350+ // @Success 200 {object} middleware.APIResponse{data=[]TestResult}
351+ //
352+ // @Router /api/channels/test [get]
321353func TestAllChannels (c * gin.Context ) {
322354 testDisabled := c .Query ("test_disabled" ) == "true"
323355 var channels []* model.Channel
@@ -342,7 +374,7 @@ func TestAllChannels(c *gin.Context) {
342374 common .SetEventStreamHeaders (c )
343375 }
344376
345- results := make ([]* testResult , 0 )
377+ results := make ([]* TestResult , 0 )
346378 resultsMutex := sync.Mutex {}
347379 hasErrorMap := make (map [int ]* atomic.Bool )
348380
0 commit comments