channel.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. package controller
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "one-api/common"
  7. "one-api/model"
  8. "strconv"
  9. "strings"
  10. "github.com/gin-gonic/gin"
  11. )
  12. type OpenAIModel struct {
  13. ID string `json:"id"`
  14. Object string `json:"object"`
  15. Created int64 `json:"created"`
  16. OwnedBy string `json:"owned_by"`
  17. Permission []struct {
  18. ID string `json:"id"`
  19. Object string `json:"object"`
  20. Created int64 `json:"created"`
  21. AllowCreateEngine bool `json:"allow_create_engine"`
  22. AllowSampling bool `json:"allow_sampling"`
  23. AllowLogprobs bool `json:"allow_logprobs"`
  24. AllowSearchIndices bool `json:"allow_search_indices"`
  25. AllowView bool `json:"allow_view"`
  26. AllowFineTuning bool `json:"allow_fine_tuning"`
  27. Organization string `json:"organization"`
  28. Group string `json:"group"`
  29. IsBlocking bool `json:"is_blocking"`
  30. } `json:"permission"`
  31. Root string `json:"root"`
  32. Parent string `json:"parent"`
  33. }
  34. type OpenAIModelsResponse struct {
  35. Data []OpenAIModel `json:"data"`
  36. Success bool `json:"success"`
  37. }
  38. func GetAllChannels(c *gin.Context) {
  39. p, _ := strconv.Atoi(c.Query("p"))
  40. pageSize, _ := strconv.Atoi(c.Query("page_size"))
  41. if p < 1 {
  42. p = 1
  43. }
  44. if pageSize < 1 {
  45. pageSize = common.ItemsPerPage
  46. }
  47. channelData := make([]*model.Channel, 0)
  48. idSort, _ := strconv.ParseBool(c.Query("id_sort"))
  49. enableTagMode, _ := strconv.ParseBool(c.Query("tag_mode"))
  50. var total int64
  51. if enableTagMode {
  52. // tag 分页:先分页 tag,再取各 tag 下 channels
  53. tags, err := model.GetPaginatedTags((p-1)*pageSize, pageSize)
  54. if err != nil {
  55. c.JSON(http.StatusOK, gin.H{"success": false, "message": err.Error()})
  56. return
  57. }
  58. for _, tag := range tags {
  59. if tag != nil && *tag != "" {
  60. tagChannel, err := model.GetChannelsByTag(*tag, idSort)
  61. if err == nil {
  62. channelData = append(channelData, tagChannel...)
  63. }
  64. }
  65. }
  66. // 计算 tag 总数用于分页
  67. total, _ = model.CountAllTags()
  68. } else {
  69. channels, err := model.GetAllChannels((p-1)*pageSize, pageSize, false, idSort)
  70. if err != nil {
  71. c.JSON(http.StatusOK, gin.H{"success": false, "message": err.Error()})
  72. return
  73. }
  74. channelData = channels
  75. total, _ = model.CountAllChannels()
  76. }
  77. c.JSON(http.StatusOK, gin.H{
  78. "success": true,
  79. "message": "",
  80. "data": gin.H{
  81. "items": channelData,
  82. "total": total,
  83. "page": p,
  84. "page_size": pageSize,
  85. },
  86. })
  87. return
  88. }
  89. func FetchUpstreamModels(c *gin.Context) {
  90. id, err := strconv.Atoi(c.Param("id"))
  91. if err != nil {
  92. c.JSON(http.StatusOK, gin.H{
  93. "success": false,
  94. "message": err.Error(),
  95. })
  96. return
  97. }
  98. channel, err := model.GetChannelById(id, true)
  99. if err != nil {
  100. c.JSON(http.StatusOK, gin.H{
  101. "success": false,
  102. "message": err.Error(),
  103. })
  104. return
  105. }
  106. //if channel.Type != common.ChannelTypeOpenAI {
  107. // c.JSON(http.StatusOK, gin.H{
  108. // "success": false,
  109. // "message": "仅支持 OpenAI 类型渠道",
  110. // })
  111. // return
  112. //}
  113. baseURL := common.ChannelBaseURLs[channel.Type]
  114. if channel.GetBaseURL() != "" {
  115. baseURL = channel.GetBaseURL()
  116. }
  117. url := fmt.Sprintf("%s/v1/models", baseURL)
  118. switch channel.Type {
  119. case common.ChannelTypeGemini:
  120. url = fmt.Sprintf("%s/v1beta/openai/models", baseURL)
  121. case common.ChannelTypeAli:
  122. url = fmt.Sprintf("%s/compatible-mode/v1/models", baseURL)
  123. }
  124. body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
  125. if err != nil {
  126. c.JSON(http.StatusOK, gin.H{
  127. "success": false,
  128. "message": err.Error(),
  129. })
  130. return
  131. }
  132. var result OpenAIModelsResponse
  133. if err = json.Unmarshal(body, &result); err != nil {
  134. c.JSON(http.StatusOK, gin.H{
  135. "success": false,
  136. "message": fmt.Sprintf("解析响应失败: %s", err.Error()),
  137. })
  138. return
  139. }
  140. var ids []string
  141. for _, model := range result.Data {
  142. id := model.ID
  143. if channel.Type == common.ChannelTypeGemini {
  144. id = strings.TrimPrefix(id, "models/")
  145. }
  146. ids = append(ids, id)
  147. }
  148. c.JSON(http.StatusOK, gin.H{
  149. "success": true,
  150. "message": "",
  151. "data": ids,
  152. })
  153. }
  154. func FixChannelsAbilities(c *gin.Context) {
  155. count, err := model.FixAbility()
  156. if err != nil {
  157. c.JSON(http.StatusOK, gin.H{
  158. "success": false,
  159. "message": err.Error(),
  160. })
  161. return
  162. }
  163. c.JSON(http.StatusOK, gin.H{
  164. "success": true,
  165. "message": "",
  166. "data": count,
  167. })
  168. }
  169. func SearchChannels(c *gin.Context) {
  170. keyword := c.Query("keyword")
  171. group := c.Query("group")
  172. modelKeyword := c.Query("model")
  173. idSort, _ := strconv.ParseBool(c.Query("id_sort"))
  174. enableTagMode, _ := strconv.ParseBool(c.Query("tag_mode"))
  175. channelData := make([]*model.Channel, 0)
  176. if enableTagMode {
  177. tags, err := model.SearchTags(keyword, group, modelKeyword, idSort)
  178. if err != nil {
  179. c.JSON(http.StatusOK, gin.H{
  180. "success": false,
  181. "message": err.Error(),
  182. })
  183. return
  184. }
  185. for _, tag := range tags {
  186. if tag != nil && *tag != "" {
  187. tagChannel, err := model.GetChannelsByTag(*tag, idSort)
  188. if err == nil {
  189. channelData = append(channelData, tagChannel...)
  190. }
  191. }
  192. }
  193. } else {
  194. channels, err := model.SearchChannels(keyword, group, modelKeyword, idSort)
  195. if err != nil {
  196. c.JSON(http.StatusOK, gin.H{
  197. "success": false,
  198. "message": err.Error(),
  199. })
  200. return
  201. }
  202. channelData = channels
  203. }
  204. c.JSON(http.StatusOK, gin.H{
  205. "success": true,
  206. "message": "",
  207. "data": channelData,
  208. })
  209. return
  210. }
  211. func GetChannel(c *gin.Context) {
  212. id, err := strconv.Atoi(c.Param("id"))
  213. if err != nil {
  214. c.JSON(http.StatusOK, gin.H{
  215. "success": false,
  216. "message": err.Error(),
  217. })
  218. return
  219. }
  220. channel, err := model.GetChannelById(id, false)
  221. if err != nil {
  222. c.JSON(http.StatusOK, gin.H{
  223. "success": false,
  224. "message": err.Error(),
  225. })
  226. return
  227. }
  228. c.JSON(http.StatusOK, gin.H{
  229. "success": true,
  230. "message": "",
  231. "data": channel,
  232. })
  233. return
  234. }
  235. type AddChannelRequest struct {
  236. Mode string `json:"mode"`
  237. Channel *model.Channel `json:"channel"`
  238. }
  239. func AddChannel(c *gin.Context) {
  240. addChannelRequest := AddChannelRequest{}
  241. err := c.ShouldBindJSON(&addChannelRequest)
  242. if err != nil {
  243. c.JSON(http.StatusOK, gin.H{
  244. "success": false,
  245. "message": err.Error(),
  246. })
  247. return
  248. }
  249. if addChannelRequest.Channel == nil || addChannelRequest.Channel.Key == "" {
  250. c.JSON(http.StatusOK, gin.H{
  251. "success": false,
  252. "message": "channel cannot be empty",
  253. })
  254. return
  255. }
  256. // Validate the length of the model name
  257. for _, m := range addChannelRequest.Channel.GetModels() {
  258. if len(m) > 255 {
  259. c.JSON(http.StatusOK, gin.H{
  260. "success": false,
  261. "message": fmt.Sprintf("模型名称过长: %s", m),
  262. })
  263. return
  264. }
  265. }
  266. if addChannelRequest.Channel.Type == common.ChannelTypeVertexAi {
  267. if addChannelRequest.Channel.Other == "" {
  268. c.JSON(http.StatusOK, gin.H{
  269. "success": false,
  270. "message": "部署地区不能为空",
  271. })
  272. return
  273. } else {
  274. if common.IsJsonStr(addChannelRequest.Channel.Other) {
  275. // must have default
  276. regionMap := common.StrToMap(addChannelRequest.Channel.Other)
  277. if regionMap["default"] == nil {
  278. c.JSON(http.StatusOK, gin.H{
  279. "success": false,
  280. "message": "部署地区必须包含default字段",
  281. })
  282. return
  283. }
  284. }
  285. }
  286. }
  287. addChannelRequest.Channel.CreatedTime = common.GetTimestamp()
  288. keys := make([]string, 0)
  289. switch addChannelRequest.Mode {
  290. case "multi_to_single":
  291. addChannelRequest.Channel.ChannelInfo.MultiKeyMode = true
  292. if addChannelRequest.Channel.Type == common.ChannelTypeVertexAi {
  293. if !common.IsJsonStr(addChannelRequest.Channel.Key) {
  294. c.JSON(http.StatusOK, gin.H{
  295. "success": false,
  296. "message": "Vertex AI 批量添加模式必须使用标准的JsonArray格式,例如[{key1}, {key2}...],请检查输入",
  297. })
  298. return
  299. }
  300. toMap := common.StrToMap(addChannelRequest.Channel.Key)
  301. if toMap != nil {
  302. addChannelRequest.Channel.ChannelInfo.MultiKeySize = len(toMap)
  303. } else {
  304. addChannelRequest.Channel.ChannelInfo.MultiKeySize = 0
  305. }
  306. } else {
  307. cleanKeys := make([]string, 0)
  308. for _, key := range strings.Split(addChannelRequest.Channel.Key, "\n") {
  309. if key == "" {
  310. continue
  311. }
  312. cleanKeys = append(cleanKeys, key)
  313. }
  314. addChannelRequest.Channel.ChannelInfo.MultiKeySize = len(cleanKeys)
  315. addChannelRequest.Channel.Key = strings.Join(cleanKeys, "\n")
  316. }
  317. keys = []string{addChannelRequest.Channel.Key}
  318. case "batch":
  319. if addChannelRequest.Channel.Type == common.ChannelTypeVertexAi {
  320. // multi json
  321. if !common.IsJsonStr(addChannelRequest.Channel.Key) {
  322. c.JSON(http.StatusOK, gin.H{
  323. "success": false,
  324. "message": "Vertex AI 批量添加模式必须使用标准的JsonArray格式,例如[{key1}, {key2}...],请检查输入",
  325. })
  326. return
  327. }
  328. toMap := common.StrToMap(addChannelRequest.Channel.Key)
  329. if toMap == nil {
  330. c.JSON(http.StatusOK, gin.H{
  331. "success": false,
  332. "message": "Vertex AI 批量添加模式必须使用标准的JsonArray格式,例如[{key1}, {key2}...],请检查输入",
  333. })
  334. return
  335. }
  336. keys = make([]string, 0, len(toMap))
  337. for k := range toMap {
  338. if k == "" {
  339. continue
  340. }
  341. keys = append(keys, k)
  342. }
  343. } else {
  344. keys = strings.Split(addChannelRequest.Channel.Key, "\n")
  345. }
  346. case "single":
  347. keys = []string{addChannelRequest.Channel.Key}
  348. default:
  349. c.JSON(http.StatusOK, gin.H{
  350. "success": false,
  351. "message": "不支持的添加模式",
  352. })
  353. return
  354. }
  355. channels := make([]model.Channel, 0, len(keys))
  356. for _, key := range keys {
  357. if key == "" {
  358. continue
  359. }
  360. localChannel := addChannelRequest.Channel
  361. localChannel.Key = key
  362. channels = append(channels, *localChannel)
  363. }
  364. err = model.BatchInsertChannels(channels)
  365. if err != nil {
  366. c.JSON(http.StatusOK, gin.H{
  367. "success": false,
  368. "message": err.Error(),
  369. })
  370. return
  371. }
  372. c.JSON(http.StatusOK, gin.H{
  373. "success": true,
  374. "message": "",
  375. })
  376. return
  377. }
  378. func DeleteChannel(c *gin.Context) {
  379. id, _ := strconv.Atoi(c.Param("id"))
  380. channel := model.Channel{Id: id}
  381. err := channel.Delete()
  382. if err != nil {
  383. c.JSON(http.StatusOK, gin.H{
  384. "success": false,
  385. "message": err.Error(),
  386. })
  387. return
  388. }
  389. c.JSON(http.StatusOK, gin.H{
  390. "success": true,
  391. "message": "",
  392. })
  393. return
  394. }
  395. func DeleteDisabledChannel(c *gin.Context) {
  396. rows, err := model.DeleteDisabledChannel()
  397. if err != nil {
  398. c.JSON(http.StatusOK, gin.H{
  399. "success": false,
  400. "message": err.Error(),
  401. })
  402. return
  403. }
  404. c.JSON(http.StatusOK, gin.H{
  405. "success": true,
  406. "message": "",
  407. "data": rows,
  408. })
  409. return
  410. }
  411. type ChannelTag struct {
  412. Tag string `json:"tag"`
  413. NewTag *string `json:"new_tag"`
  414. Priority *int64 `json:"priority"`
  415. Weight *uint `json:"weight"`
  416. ModelMapping *string `json:"model_mapping"`
  417. Models *string `json:"models"`
  418. Groups *string `json:"groups"`
  419. }
  420. func DisableTagChannels(c *gin.Context) {
  421. channelTag := ChannelTag{}
  422. err := c.ShouldBindJSON(&channelTag)
  423. if err != nil || channelTag.Tag == "" {
  424. c.JSON(http.StatusOK, gin.H{
  425. "success": false,
  426. "message": "参数错误",
  427. })
  428. return
  429. }
  430. err = model.DisableChannelByTag(channelTag.Tag)
  431. if err != nil {
  432. c.JSON(http.StatusOK, gin.H{
  433. "success": false,
  434. "message": err.Error(),
  435. })
  436. return
  437. }
  438. c.JSON(http.StatusOK, gin.H{
  439. "success": true,
  440. "message": "",
  441. })
  442. return
  443. }
  444. func EnableTagChannels(c *gin.Context) {
  445. channelTag := ChannelTag{}
  446. err := c.ShouldBindJSON(&channelTag)
  447. if err != nil || channelTag.Tag == "" {
  448. c.JSON(http.StatusOK, gin.H{
  449. "success": false,
  450. "message": "参数错误",
  451. })
  452. return
  453. }
  454. err = model.EnableChannelByTag(channelTag.Tag)
  455. if err != nil {
  456. c.JSON(http.StatusOK, gin.H{
  457. "success": false,
  458. "message": err.Error(),
  459. })
  460. return
  461. }
  462. c.JSON(http.StatusOK, gin.H{
  463. "success": true,
  464. "message": "",
  465. })
  466. return
  467. }
  468. func EditTagChannels(c *gin.Context) {
  469. channelTag := ChannelTag{}
  470. err := c.ShouldBindJSON(&channelTag)
  471. if err != nil {
  472. c.JSON(http.StatusOK, gin.H{
  473. "success": false,
  474. "message": "参数错误",
  475. })
  476. return
  477. }
  478. if channelTag.Tag == "" {
  479. c.JSON(http.StatusOK, gin.H{
  480. "success": false,
  481. "message": "tag不能为空",
  482. })
  483. return
  484. }
  485. err = model.EditChannelByTag(channelTag.Tag, channelTag.NewTag, channelTag.ModelMapping, channelTag.Models, channelTag.Groups, channelTag.Priority, channelTag.Weight)
  486. if err != nil {
  487. c.JSON(http.StatusOK, gin.H{
  488. "success": false,
  489. "message": err.Error(),
  490. })
  491. return
  492. }
  493. c.JSON(http.StatusOK, gin.H{
  494. "success": true,
  495. "message": "",
  496. })
  497. return
  498. }
  499. type ChannelBatch struct {
  500. Ids []int `json:"ids"`
  501. Tag *string `json:"tag"`
  502. }
  503. func DeleteChannelBatch(c *gin.Context) {
  504. channelBatch := ChannelBatch{}
  505. err := c.ShouldBindJSON(&channelBatch)
  506. if err != nil || len(channelBatch.Ids) == 0 {
  507. c.JSON(http.StatusOK, gin.H{
  508. "success": false,
  509. "message": "参数错误",
  510. })
  511. return
  512. }
  513. err = model.BatchDeleteChannels(channelBatch.Ids)
  514. if err != nil {
  515. c.JSON(http.StatusOK, gin.H{
  516. "success": false,
  517. "message": err.Error(),
  518. })
  519. return
  520. }
  521. c.JSON(http.StatusOK, gin.H{
  522. "success": true,
  523. "message": "",
  524. "data": len(channelBatch.Ids),
  525. })
  526. return
  527. }
  528. func UpdateChannel(c *gin.Context) {
  529. channel := model.Channel{}
  530. err := c.ShouldBindJSON(&channel)
  531. if err != nil {
  532. c.JSON(http.StatusOK, gin.H{
  533. "success": false,
  534. "message": err.Error(),
  535. })
  536. return
  537. }
  538. if channel.Type == common.ChannelTypeVertexAi {
  539. if channel.Other == "" {
  540. c.JSON(http.StatusOK, gin.H{
  541. "success": false,
  542. "message": "部署地区不能为空",
  543. })
  544. return
  545. } else {
  546. if common.IsJsonStr(channel.Other) {
  547. // must have default
  548. regionMap := common.StrToMap(channel.Other)
  549. if regionMap["default"] == nil {
  550. c.JSON(http.StatusOK, gin.H{
  551. "success": false,
  552. "message": "部署地区必须包含default字段",
  553. })
  554. return
  555. }
  556. }
  557. }
  558. }
  559. err = channel.Update()
  560. if err != nil {
  561. c.JSON(http.StatusOK, gin.H{
  562. "success": false,
  563. "message": err.Error(),
  564. })
  565. return
  566. }
  567. c.JSON(http.StatusOK, gin.H{
  568. "success": true,
  569. "message": "",
  570. "data": channel,
  571. })
  572. return
  573. }
  574. func FetchModels(c *gin.Context) {
  575. var req struct {
  576. BaseURL string `json:"base_url"`
  577. Type int `json:"type"`
  578. Key string `json:"key"`
  579. }
  580. if err := c.ShouldBindJSON(&req); err != nil {
  581. c.JSON(http.StatusBadRequest, gin.H{
  582. "success": false,
  583. "message": "Invalid request",
  584. })
  585. return
  586. }
  587. baseURL := req.BaseURL
  588. if baseURL == "" {
  589. baseURL = common.ChannelBaseURLs[req.Type]
  590. }
  591. client := &http.Client{}
  592. url := fmt.Sprintf("%s/v1/models", baseURL)
  593. request, err := http.NewRequest("GET", url, nil)
  594. if err != nil {
  595. c.JSON(http.StatusInternalServerError, gin.H{
  596. "success": false,
  597. "message": err.Error(),
  598. })
  599. return
  600. }
  601. // remove line breaks and extra spaces.
  602. key := strings.TrimSpace(req.Key)
  603. // If the key contains a line break, only take the first part.
  604. key = strings.Split(key, "\n")[0]
  605. request.Header.Set("Authorization", "Bearer "+key)
  606. response, err := client.Do(request)
  607. if err != nil {
  608. c.JSON(http.StatusInternalServerError, gin.H{
  609. "success": false,
  610. "message": err.Error(),
  611. })
  612. return
  613. }
  614. //check status code
  615. if response.StatusCode != http.StatusOK {
  616. c.JSON(http.StatusInternalServerError, gin.H{
  617. "success": false,
  618. "message": "Failed to fetch models",
  619. })
  620. return
  621. }
  622. defer response.Body.Close()
  623. var result struct {
  624. Data []struct {
  625. ID string `json:"id"`
  626. } `json:"data"`
  627. }
  628. if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
  629. c.JSON(http.StatusInternalServerError, gin.H{
  630. "success": false,
  631. "message": err.Error(),
  632. })
  633. return
  634. }
  635. var models []string
  636. for _, model := range result.Data {
  637. models = append(models, model.ID)
  638. }
  639. c.JSON(http.StatusOK, gin.H{
  640. "success": true,
  641. "data": models,
  642. })
  643. }
  644. func BatchSetChannelTag(c *gin.Context) {
  645. channelBatch := ChannelBatch{}
  646. err := c.ShouldBindJSON(&channelBatch)
  647. if err != nil || len(channelBatch.Ids) == 0 {
  648. c.JSON(http.StatusOK, gin.H{
  649. "success": false,
  650. "message": "参数错误",
  651. })
  652. return
  653. }
  654. err = model.BatchSetChannelTag(channelBatch.Ids, channelBatch.Tag)
  655. if err != nil {
  656. c.JSON(http.StatusOK, gin.H{
  657. "success": false,
  658. "message": err.Error(),
  659. })
  660. return
  661. }
  662. c.JSON(http.StatusOK, gin.H{
  663. "success": true,
  664. "message": "",
  665. "data": len(channelBatch.Ids),
  666. })
  667. return
  668. }
  669. func GetTagModels(c *gin.Context) {
  670. tag := c.Query("tag")
  671. if tag == "" {
  672. c.JSON(http.StatusBadRequest, gin.H{
  673. "success": false,
  674. "message": "tag不能为空",
  675. })
  676. return
  677. }
  678. channels, err := model.GetChannelsByTag(tag, false) // Assuming false for idSort is fine here
  679. if err != nil {
  680. c.JSON(http.StatusInternalServerError, gin.H{
  681. "success": false,
  682. "message": err.Error(),
  683. })
  684. return
  685. }
  686. var longestModels string
  687. maxLength := 0
  688. // Find the longest models string among all channels with the given tag
  689. for _, channel := range channels {
  690. if channel.Models != "" {
  691. currentModels := strings.Split(channel.Models, ",")
  692. if len(currentModels) > maxLength {
  693. maxLength = len(currentModels)
  694. longestModels = channel.Models
  695. }
  696. }
  697. }
  698. c.JSON(http.StatusOK, gin.H{
  699. "success": true,
  700. "message": "",
  701. "data": longestModels,
  702. })
  703. return
  704. }