application_api.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎虎
  5. @file: application.py
  6. @date:2025/5/26 16:59
  7. @desc:
  8. """
  9. from django.utils.translation import gettext_lazy as _
  10. from drf_spectacular.types import OpenApiTypes
  11. from drf_spectacular.utils import OpenApiParameter
  12. from rest_framework import serializers
  13. from application.serializers.application import ApplicationCreateSerializer, ApplicationListResponse, \
  14. ApplicationImportRequest, ApplicationEditSerializer, TextToSpeechRequest, SpeechToTextRequest, PlayDemoTextRequest
  15. from common.mixins.api_mixin import APIMixin
  16. from common.result import ResultSerializer, ResultPageSerializer, DefaultResultSerializer
  17. from knowledge.serializers.common import BatchSerializer, BatchMoveSerializer
  18. class ApplicationCreateRequest(ApplicationCreateSerializer.SimplateRequest):
  19. work_flow = serializers.DictField(required=True, label=_("Workflow Objects"))
  20. class ApplicationCreateResponse(ResultSerializer):
  21. def get_data(self):
  22. return ApplicationCreateSerializer.ApplicationResponse()
  23. class ApplicationListResult(ResultSerializer):
  24. def get_data(self):
  25. return ApplicationListResponse(many=True)
  26. class ApplicationPageResult(ResultPageSerializer):
  27. def get_data(self):
  28. return ApplicationListResponse(many=True)
  29. class ApplicationQueryAPI(APIMixin):
  30. @staticmethod
  31. def get_parameters():
  32. return [
  33. OpenApiParameter(
  34. name="workspace_id",
  35. description="工作空间id",
  36. type=OpenApiTypes.STR,
  37. location='path',
  38. required=True,
  39. ),
  40. OpenApiParameter(
  41. name="current_page",
  42. description=_("Current page"),
  43. type=OpenApiTypes.INT,
  44. location='path',
  45. required=True,
  46. ),
  47. OpenApiParameter(
  48. name="page_size",
  49. description=_("Page size"),
  50. type=OpenApiTypes.INT,
  51. location='path',
  52. required=True,
  53. ),
  54. OpenApiParameter(
  55. name="folder_id",
  56. description=_("folder id"),
  57. type=OpenApiTypes.STR,
  58. location='query',
  59. required=False,
  60. ),
  61. OpenApiParameter(
  62. name="name",
  63. description=_("Application Name"),
  64. type=OpenApiTypes.STR,
  65. location='query',
  66. required=False,
  67. ),
  68. OpenApiParameter(
  69. name="desc",
  70. description=_("Application Description"),
  71. type=OpenApiTypes.STR,
  72. location='query',
  73. required=False,
  74. ),
  75. OpenApiParameter(
  76. name="user_id",
  77. description=_("User ID"),
  78. type=OpenApiTypes.STR,
  79. location='query',
  80. required=False,
  81. ),
  82. OpenApiParameter(
  83. name="publish_status",
  84. description=_("Publish status") + '(published|unpublished)',
  85. type=OpenApiTypes.STR,
  86. location='query',
  87. required=False,
  88. )
  89. ]
  90. @staticmethod
  91. def get_response():
  92. return ApplicationListResult
  93. @staticmethod
  94. def get_page_response():
  95. return ApplicationPageResult
  96. class ApplicationCreateAPI(APIMixin):
  97. @staticmethod
  98. def get_parameters():
  99. return [
  100. OpenApiParameter(
  101. name="workspace_id",
  102. description="工作空间id",
  103. type=OpenApiTypes.STR,
  104. location='path',
  105. required=True,
  106. )
  107. ]
  108. @staticmethod
  109. def get_request():
  110. return ApplicationCreateRequest
  111. @staticmethod
  112. def get_response():
  113. return ApplicationCreateResponse
  114. class ApplicationImportAPI(APIMixin):
  115. @staticmethod
  116. def get_parameters():
  117. ApplicationCreateAPI.get_parameters()
  118. @staticmethod
  119. def get_request():
  120. return ApplicationImportRequest
  121. class ApplicationOperateAPI(APIMixin):
  122. @staticmethod
  123. def get_parameters():
  124. return [
  125. OpenApiParameter(
  126. name="workspace_id",
  127. description="工作空间id",
  128. type=OpenApiTypes.STR,
  129. location='path',
  130. required=True,
  131. ),
  132. OpenApiParameter(
  133. name="application_id",
  134. description="应用id",
  135. type=OpenApiTypes.STR,
  136. location='path',
  137. required=True,
  138. )
  139. ]
  140. class ApplicationBatchOperateAPI(APIMixin):
  141. @staticmethod
  142. def get_parameters():
  143. return [
  144. OpenApiParameter(
  145. name="workspace_id",
  146. description="工作空间id",
  147. type=OpenApiTypes.STR,
  148. location='path',
  149. required=True,
  150. )
  151. ]
  152. @staticmethod
  153. def get_request():
  154. return BatchSerializer
  155. @staticmethod
  156. def get_move_request():
  157. return BatchMoveSerializer
  158. class ApplicationExportAPI(APIMixin):
  159. @staticmethod
  160. def get_parameters():
  161. return ApplicationOperateAPI.get_parameters()
  162. @staticmethod
  163. def get_response():
  164. return DefaultResultSerializer
  165. class ApplicationEditAPI(APIMixin):
  166. @staticmethod
  167. def get_request():
  168. return ApplicationEditSerializer
  169. class TextToSpeechAPI(APIMixin):
  170. @staticmethod
  171. def get_parameters():
  172. return ApplicationOperateAPI.get_parameters()
  173. @staticmethod
  174. def get_request():
  175. return TextToSpeechRequest
  176. @staticmethod
  177. def get_response():
  178. return DefaultResultSerializer
  179. class SpeechToTextAPI(APIMixin):
  180. @staticmethod
  181. def get_parameters():
  182. return ApplicationOperateAPI.get_parameters()
  183. @staticmethod
  184. def get_request():
  185. return SpeechToTextRequest
  186. @staticmethod
  187. def get_response():
  188. return DefaultResultSerializer
  189. class PlayDemoTextAPI(APIMixin):
  190. @staticmethod
  191. def get_parameters():
  192. return ApplicationOperateAPI.get_parameters()
  193. @staticmethod
  194. def get_request():
  195. return PlayDemoTextRequest
  196. @staticmethod
  197. def get_response():
  198. return DefaultResultSerializer