channel.go 17 KB

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