2025-04-28 08:31:46 +00:00
|
|
|
from drf_spectacular.types import OpenApiTypes
|
|
|
|
|
from drf_spectacular.utils import OpenApiParameter
|
|
|
|
|
|
|
|
|
|
from common.mixins.api_mixin import APIMixin
|
2025-04-30 09:48:31 +00:00
|
|
|
from common.result import DefaultResultSerializer
|
|
|
|
|
from knowledge.serializers.common import BatchSerializer
|
2025-05-06 07:53:30 +00:00
|
|
|
from knowledge.serializers.document import DocumentInstanceSerializer, DocumentWebInstanceSerializer, \
|
2025-05-08 11:16:45 +00:00
|
|
|
CancelInstanceSerializer, BatchCancelInstanceSerializer, DocumentRefreshSerializer, BatchEditHitHandlingSerializer, \
|
|
|
|
|
DocumentBatchRefreshSerializer, DocumentBatchGenerateRelatedSerializer
|
2025-04-30 06:14:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentSplitAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-05-08 02:42:00 +00:00
|
|
|
|
2025-04-30 06:14:41 +00:00
|
|
|
OpenApiParameter(
|
|
|
|
|
name="limit",
|
|
|
|
|
description="分段长度",
|
|
|
|
|
type=OpenApiTypes.INT,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="patterns",
|
|
|
|
|
description="分段正则列表",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="with_filter",
|
|
|
|
|
description="是否清除特殊字符",
|
|
|
|
|
type=OpenApiTypes.BOOL,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
2025-05-08 02:42:00 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return {
|
|
|
|
|
'multipart/form-data': {
|
|
|
|
|
'type': 'object',
|
|
|
|
|
'properties': {
|
|
|
|
|
'file': {
|
|
|
|
|
'type': 'string',
|
|
|
|
|
'format': 'binary' # Tells Swagger it's a file
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 09:48:31 +00:00
|
|
|
|
|
|
|
|
class DocumentBatchAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return BatchSerializer
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
2025-04-30 10:18:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentBatchCreateAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentInstanceSerializer(many=True)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
2025-05-06 03:05:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentCreateAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentInstanceSerializer
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentReadAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="document_id",
|
|
|
|
|
description="文档id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentEditAPI(DocumentReadAPI):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentInstanceSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentDeleteAPI(DocumentReadAPI):
|
|
|
|
|
pass
|
2025-05-06 06:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TableDocumentCreateAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-05-08 02:42:00 +00:00
|
|
|
|
2025-05-06 06:33:59 +00:00
|
|
|
]
|
|
|
|
|
|
2025-05-08 02:42:00 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return {
|
|
|
|
|
'multipart/form-data': {
|
|
|
|
|
'type': 'object',
|
|
|
|
|
'properties': {
|
|
|
|
|
'file': {
|
|
|
|
|
'type': 'string',
|
|
|
|
|
'format': 'binary' # Tells Swagger it's a file
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 06:33:59 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QaDocumentCreateAPI(TableDocumentCreateAPI):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebDocumentCreateAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentWebInstanceSerializer
|
2025-05-06 07:53:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CancelTaskAPI(DocumentReadAPI):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return CancelInstanceSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BatchCancelTaskAPI(DocumentReadAPI):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return BatchCancelInstanceSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SyncWebAPI(DocumentReadAPI):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RefreshAPI(DocumentReadAPI):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentRefreshSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BatchEditHitHandlingAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return BatchEditHitHandlingSerializer
|
2025-05-06 09:39:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentTreeReadAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="folder_id",
|
|
|
|
|
description="文件夹id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="user_id",
|
|
|
|
|
description="用户id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="name",
|
|
|
|
|
description="名称",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="desc",
|
|
|
|
|
description="描述",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
]
|
2025-05-06 09:56:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentSplitPatternAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
2025-05-08 11:16:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BatchRefreshAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return DocumentBatchRefreshSerializer
|
|
|
|
|
|
2025-06-03 09:44:02 +00:00
|
|
|
|
2025-05-08 11:16:45 +00:00
|
|
|
class BatchGenerateRelatedAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
2025-06-03 09:44:02 +00:00
|
|
|
return DocumentBatchGenerateRelatedSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TemplateExportAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="type",
|
|
|
|
|
description="Export template type csv|excel",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocumentExportAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="knowledge_id",
|
|
|
|
|
description="知识库id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="document_id",
|
|
|
|
|
description="文档id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|