You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

123 lines
6.4 KiB

  1. package aiping
  2. import "net/http"
  3. const (
  4. ActionText2Video = "kling-text2video"
  5. ActionImage2Video = "kling-image2video"
  6. ActionMotionControl = "kling-motion-control"
  7. ActionOmniVideo = "kling-omni-video"
  8. ActionMultiImage2Video = "kling-multi-image2video"
  9. ActionVideoExtend = "kling-video-extend"
  10. ActionAdvancedElements = "kling-advanced-elements-create"
  11. ActionVoicesCreate = "kling-voices-create"
  12. ActionDeleteElements = "kling-delete-elements"
  13. ActionDeleteVoices = "kling-voices-delete"
  14. )
  15. const (
  16. RouteKindSubmit = "submit"
  17. RouteKindFetch = "fetch"
  18. RouteKindList = "list"
  19. RouteKindProxy = "proxy"
  20. )
  21. const (
  22. ModelKlingAdvancedElements = "kling-advanced-elements"
  23. ModelCustomVoices = "custom-voices"
  24. )
  25. type Route struct {
  26. Method string
  27. PathPattern string
  28. Action string
  29. UpstreamPath string
  30. Kind string
  31. BillingModel string
  32. }
  33. var Routes = []Route{
  34. // 视频能力:文生视频
  35. {http.MethodPost, "/v1/videos/text2video", ActionText2Video, "/api/v1/multimodal/kling/videos/text2video", RouteKindSubmit, ""},
  36. {http.MethodGet, "/v1/videos/text2video/:task_id", ActionText2Video, "/api/v1/multimodal/kling/videos/text2video/:task_id", RouteKindFetch, ""},
  37. {http.MethodGet, "/v1/videos/text2video", ActionText2Video, "/api/v1/multimodal/kling/videos/text2video", RouteKindList, ""},
  38. // 视频能力:图生视频
  39. {http.MethodPost, "/v1/videos/image2video", ActionImage2Video, "/api/v1/multimodal/kling/videos/image2video", RouteKindSubmit, ""},
  40. {http.MethodGet, "/v1/videos/image2video/:task_id", ActionImage2Video, "/api/v1/multimodal/kling/videos/image2video/:task_id", RouteKindFetch, ""},
  41. {http.MethodGet, "/v1/videos/image2video", ActionImage2Video, "/api/v1/multimodal/kling/videos/image2video", RouteKindList, ""},
  42. // 视频能力:动作控制(model_name 可指定 Kling-V3 / Kling-V2.6)
  43. {http.MethodPost, "/v1/videos/motion-control", ActionMotionControl, "/api/v1/multimodal/kling/videos/motion-control", RouteKindSubmit, ""},
  44. {http.MethodGet, "/v1/videos/motion-control/:task_id", ActionMotionControl, "/api/v1/multimodal/kling/videos/motion-control/:task_id", RouteKindFetch, ""},
  45. {http.MethodGet, "/v1/videos/motion-control", ActionMotionControl, "/api/v1/multimodal/kling/videos/motion-control", RouteKindList, ""},
  46. // 视频能力:Omni / 多镜头
  47. {http.MethodPost, "/v1/videos/omni-video", ActionOmniVideo, "/api/v1/multimodal/kling/videos/omni-video", RouteKindSubmit, ""},
  48. {http.MethodGet, "/v1/videos/omni-video/:task_id", ActionOmniVideo, "/api/v1/multimodal/kling/videos/omni-video/:task_id", RouteKindFetch, ""},
  49. {http.MethodGet, "/v1/videos/omni-video", ActionOmniVideo, "/api/v1/multimodal/kling/videos/omni-video", RouteKindList, ""},
  50. // 视频能力:多图参考生视频
  51. {http.MethodPost, "/v1/videos/multi-image2video", ActionMultiImage2Video, "/api/v1/multimodal/kling/videos/multi-image2video", RouteKindSubmit, ""},
  52. {http.MethodGet, "/v1/videos/multi-image2video/:task_id", ActionMultiImage2Video, "/api/v1/multimodal/kling/videos/multi-image2video/:task_id", RouteKindFetch, ""},
  53. {http.MethodGet, "/v1/videos/multi-image2video", ActionMultiImage2Video, "/api/v1/multimodal/kling/videos/multi-image2video", RouteKindList, ""},
  54. // 视频能力:视频延长
  55. {http.MethodPost, "/v1/videos/video-extend", ActionVideoExtend, "/api/v1/multimodal/kling/videos/video-extend", RouteKindSubmit, ""},
  56. {http.MethodGet, "/v1/videos/video-extend/:task_id", ActionVideoExtend, "/api/v1/multimodal/kling/videos/video-extend/:task_id", RouteKindFetch, ""},
  57. {http.MethodGet, "/v1/videos/video-extend", ActionVideoExtend, "/api/v1/multimodal/kling/videos/video-extend", RouteKindList, ""},
  58. // 主体能力:自定义主体
  59. {http.MethodPost, "/v1/general/advanced-custom-elements", ActionAdvancedElements, "/api/v1/multimodal/kling/general/advanced-custom-elements", RouteKindSubmit, ModelKlingAdvancedElements},
  60. {http.MethodGet, "/v1/general/advanced-custom-elements/:task_id", ActionAdvancedElements, "/api/v1/multimodal/kling/general/advanced-custom-elements/:task_id", RouteKindFetch, ModelKlingAdvancedElements},
  61. {http.MethodGet, "/v1/general/advanced-custom-elements", "kling-advanced-elements-list", "/api/v1/multimodal/kling/general/advanced-custom-elements", RouteKindProxy, ModelKlingAdvancedElements},
  62. // 主体能力:官方主体列表
  63. {http.MethodGet, "/v1/general/advanced-presets-elements", "kling-advanced-elements-presets", "/api/v1/multimodal/kling/general/advanced-presets-elements", RouteKindProxy, ModelKlingAdvancedElements},
  64. // 主体能力:删除自定义主体
  65. {http.MethodPost, "/v1/general/delete-advanced-elements", ActionDeleteElements, "/api/v1/multimodal/kling/general/delete-advanced-elements", RouteKindProxy, ModelKlingAdvancedElements},
  66. // 音色能力:自定义音色
  67. {http.MethodPost, "/v1/general/custom-voices", ActionVoicesCreate, "/api/v1/multimodal/kling/general/custom-voices", RouteKindSubmit, ModelCustomVoices},
  68. {http.MethodGet, "/v1/general/custom-voices/:task_id", ActionVoicesCreate, "/api/v1/multimodal/kling/general/custom-voices/:task_id", RouteKindFetch, ModelCustomVoices},
  69. {http.MethodGet, "/v1/general/custom-voices", "kling-voices-list", "/api/v1/multimodal/kling/general/custom-voices", RouteKindProxy, ModelCustomVoices},
  70. // 音色能力:官方音色列表
  71. {http.MethodGet, "/v1/general/presets-voices", "kling-voices-presets", "/api/v1/multimodal/kling/general/presets-voices", RouteKindProxy, ModelCustomVoices},
  72. // 音色能力:删除自定义音色
  73. {http.MethodPost, "/v1/general/delete-voices", ActionDeleteVoices, "/api/v1/multimodal/kling/general/delete-voices", RouteKindProxy, ModelCustomVoices},
  74. }
  75. func FindRoute(method, pathPattern, kind string) (Route, bool) {
  76. for _, route := range Routes {
  77. if route.Method == method && route.PathPattern == pathPattern && route.Kind == kind {
  78. return route, true
  79. }
  80. }
  81. return Route{}, false
  82. }
  83. func FindRouteByAction(action string) (Route, bool) {
  84. for _, route := range Routes {
  85. if route.Action == action && route.Kind == RouteKindSubmit {
  86. return route, true
  87. }
  88. }
  89. return Route{}, false
  90. }
  91. func FindFetchRouteByAction(action string) (Route, bool) {
  92. for _, route := range Routes {
  93. if route.Action == action && route.Kind == RouteKindFetch {
  94. return route, true
  95. }
  96. }
  97. return Route{}, false
  98. }
  99. func Models() []string {
  100. return []string{
  101. "kling-v1",
  102. "kling-v1-6",
  103. "kling-v2-6",
  104. "kling-v3",
  105. "kling-video-o1",
  106. "kling-v3-omni",
  107. ModelKlingAdvancedElements,
  108. ModelCustomVoices,
  109. }
  110. }