chat_api.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎虎
  5. @file: chat_api.py
  6. @date:2025/6/9 15:23
  7. @desc:
  8. """
  9. from drf_spectacular.types import OpenApiTypes
  10. from drf_spectacular.utils import OpenApiParameter
  11. from application.serializers.application_chat_record import ChatRecordSerializerModel
  12. from chat.serializers.chat import ChatMessageSerializers, GeneratePromptSerializers
  13. from chat.serializers.chat_record import HistoryChatModel, EditAbstractSerializer
  14. from common.mixins.api_mixin import APIMixin
  15. from common.result import ResultSerializer, ResultPageSerializer, DefaultResultSerializer
  16. class PromptGenerateAPI(APIMixin):
  17. @staticmethod
  18. def get_parameters():
  19. return [OpenApiParameter(
  20. name="workspace_id",
  21. description="工作空间id",
  22. type=OpenApiTypes.STR,
  23. location='path',
  24. required=True,
  25. ),
  26. OpenApiParameter(
  27. name="model_id",
  28. description="模型id",
  29. type=OpenApiTypes.STR,
  30. location='path',
  31. required=True,
  32. ),
  33. OpenApiParameter(
  34. name="application_id",
  35. description="应用id",
  36. type=OpenApiTypes.STR,
  37. location='path',
  38. required=True,
  39. ),
  40. ]
  41. @staticmethod
  42. def get_request():
  43. return GeneratePromptSerializers
  44. class ChatAPI(APIMixin):
  45. @staticmethod
  46. def get_parameters():
  47. return [OpenApiParameter(
  48. name="chat_id",
  49. description="对话id",
  50. type=OpenApiTypes.STR,
  51. location='path',
  52. required=True,
  53. )]
  54. @staticmethod
  55. def get_request():
  56. return ChatMessageSerializers
  57. class ApplicationCreateResponse(ResultSerializer):
  58. def get_data(self):
  59. return HistoryChatModel(many=True)
  60. class PageApplicationCreateResponse(ResultPageSerializer):
  61. def get_data(self):
  62. return HistoryChatModel(many=True)
  63. class ApplicationRecordResponse(ResultSerializer):
  64. def get_data(self):
  65. return ChatRecordSerializerModel(many=True)
  66. class PageApplicationRecordResponse(ResultPageSerializer):
  67. def get_data(self):
  68. return ChatRecordSerializerModel(many=True)
  69. class HistoricalConversationAPI(APIMixin):
  70. @staticmethod
  71. def get_parameters():
  72. return []
  73. @staticmethod
  74. def get_response():
  75. return ApplicationCreateResponse
  76. class PageHistoricalConversationAPI(APIMixin):
  77. @staticmethod
  78. def get_parameters():
  79. return []
  80. @staticmethod
  81. def get_response():
  82. return PageApplicationCreateResponse
  83. class HistoricalConversationOperateAPI(APIMixin):
  84. @staticmethod
  85. def get_parameters():
  86. return [OpenApiParameter(
  87. name="chat_id",
  88. description="对话id",
  89. type=OpenApiTypes.STR,
  90. location='path',
  91. required=True
  92. )]
  93. @staticmethod
  94. def get_request():
  95. return EditAbstractSerializer
  96. @staticmethod
  97. def get_response():
  98. return DefaultResultSerializer
  99. class HistoricalConversationRecordAPI(APIMixin):
  100. @staticmethod
  101. def get_parameters():
  102. return [OpenApiParameter(
  103. name="chat_id",
  104. description="对话id",
  105. type=OpenApiTypes.STR,
  106. location='path',
  107. required=True,
  108. )]
  109. @staticmethod
  110. def get_response():
  111. return ApplicationRecordResponse
  112. class PageHistoricalConversationRecordAPI(APIMixin):
  113. @staticmethod
  114. def get_parameters():
  115. return [OpenApiParameter(
  116. name="chat_id",
  117. description="对话id",
  118. type=OpenApiTypes.STR,
  119. location='path',
  120. required=True,
  121. )]
  122. @staticmethod
  123. def get_response():
  124. return PageApplicationRecordResponse