feat: add DocumentTreeReadAPI for document pagination and file size limit to knowledge model
This commit is contained in:
parent
c3b979decc
commit
6f5645e16c
@ -266,3 +266,52 @@ class BatchEditHitHandlingAPI(APIMixin):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_request():
|
def get_request():
|
||||||
return BatchEditHitHandlingSerializer
|
return BatchEditHitHandlingSerializer
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 5.2 on 2025-05-06 09:05
|
||||||
|
|
||||||
|
import knowledge.models.knowledge
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('knowledge', '0003_alter_document_status_alter_paragraph_status_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='knowledge',
|
||||||
|
name='file_size_limit',
|
||||||
|
field=models.IntegerField(default=100, verbose_name='文件大小限制'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='document',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(default=knowledge.models.knowledge.Status.__str__, max_length=20, verbose_name='状态'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='paragraph',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(default=knowledge.models.knowledge.Status.__str__, max_length=20, verbose_name='状态'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -127,6 +127,7 @@ class Knowledge(AppModelMixin):
|
|||||||
folder = models.ForeignKey(KnowledgeFolder, on_delete=models.DO_NOTHING, verbose_name="文件夹id", default='root')
|
folder = models.ForeignKey(KnowledgeFolder, on_delete=models.DO_NOTHING, verbose_name="文件夹id", default='root')
|
||||||
embedding_model = models.ForeignKey(Model, on_delete=models.DO_NOTHING, verbose_name="向量模型",
|
embedding_model = models.ForeignKey(Model, on_delete=models.DO_NOTHING, verbose_name="向量模型",
|
||||||
default=default_model)
|
default=default_model)
|
||||||
|
file_size_limit = models.IntegerField(verbose_name="文件大小限制", default=100)
|
||||||
meta = models.JSONField(verbose_name="元数据", default=dict)
|
meta = models.JSONField(verbose_name="元数据", default=dict)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -197,6 +198,7 @@ class ProblemParagraphMapping(AppModelMixin):
|
|||||||
class Meta:
|
class Meta:
|
||||||
db_table = "problem_paragraph_mapping"
|
db_table = "problem_paragraph_mapping"
|
||||||
|
|
||||||
|
|
||||||
class ApplicationKnowledgeMapping(AppModelMixin):
|
class ApplicationKnowledgeMapping(AppModelMixin):
|
||||||
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")
|
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id")
|
||||||
# application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
# application = models.ForeignKey(Application, on_delete=models.CASCADE)
|
||||||
@ -206,7 +208,6 @@ class ApplicationKnowledgeMapping(AppModelMixin):
|
|||||||
db_table = "application_knowledge_mapping"
|
db_table = "application_knowledge_mapping"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SourceType(models.IntegerChoices):
|
class SourceType(models.IntegerChoices):
|
||||||
"""订单类型"""
|
"""订单类型"""
|
||||||
PROBLEM = 0, '问题'
|
PROBLEM = 0, '问题'
|
||||||
|
|||||||
@ -20,5 +20,6 @@ urlpatterns = [
|
|||||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/refresh', views.DocumentView.Refresh.as_view()),
|
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/refresh', views.DocumentView.Refresh.as_view()),
|
||||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/cancel_task', views.DocumentView.CancelTask.as_view()),
|
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/cancel_task', views.DocumentView.CancelTask.as_view()),
|
||||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/cancel_task/batch', views.DocumentView.BatchCancelTask.as_view()),
|
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/cancel_task/batch', views.DocumentView.BatchCancelTask.as_view()),
|
||||||
|
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<int:current_page>/<int:page_sige>', views.DocumentView.Page.as_view()),
|
||||||
path('workspace/<str:workspace_id>/knowledge/<int:current_page>/<int:page_size>', views.KnowledgeView.Page.as_view()),
|
path('workspace/<str:workspace_id>/knowledge/<int:current_page>/<int:page_size>', views.KnowledgeView.Page.as_view()),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -10,8 +10,8 @@ from common.constants.permission_constants import PermissionConstants
|
|||||||
from common.result import result
|
from common.result import result
|
||||||
from knowledge.api.document import DocumentSplitAPI, DocumentBatchAPI, DocumentBatchCreateAPI, DocumentCreateAPI, \
|
from knowledge.api.document import DocumentSplitAPI, DocumentBatchAPI, DocumentBatchCreateAPI, DocumentCreateAPI, \
|
||||||
DocumentReadAPI, DocumentEditAPI, DocumentDeleteAPI, TableDocumentCreateAPI, QaDocumentCreateAPI, \
|
DocumentReadAPI, DocumentEditAPI, DocumentDeleteAPI, TableDocumentCreateAPI, QaDocumentCreateAPI, \
|
||||||
WebDocumentCreateAPI, CancelTaskAPI, BatchCancelTaskAPI, SyncWebAPI, RefreshAPI, BatchEditHitHandlingAPI
|
WebDocumentCreateAPI, CancelTaskAPI, BatchCancelTaskAPI, SyncWebAPI, RefreshAPI, BatchEditHitHandlingAPI, \
|
||||||
from knowledge.api.knowledge import KnowledgeTreeReadAPI
|
DocumentTreeReadAPI
|
||||||
from knowledge.serializers.document import DocumentSerializers
|
from knowledge.serializers.document import DocumentSerializers
|
||||||
|
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ class DocumentView(APIView):
|
|||||||
description=_('Get document'),
|
description=_('Get document'),
|
||||||
summary=_('Get document'),
|
summary=_('Get document'),
|
||||||
operation_id=_('Get document'),
|
operation_id=_('Get document'),
|
||||||
parameters=KnowledgeTreeReadAPI.get_parameters(),
|
parameters=DocumentTreeReadAPI.get_parameters(),
|
||||||
responses=KnowledgeTreeReadAPI.get_response(),
|
responses=DocumentTreeReadAPI.get_response(),
|
||||||
tags=[_('Knowledge Base/Documentation')]
|
tags=[_('Knowledge Base/Documentation')]
|
||||||
)
|
)
|
||||||
@has_permissions(PermissionConstants.DOCUMENT_READ.get_workspace_permission())
|
@has_permissions(PermissionConstants.DOCUMENT_READ.get_workspace_permission())
|
||||||
@ -163,16 +163,17 @@ class DocumentView(APIView):
|
|||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
methods=['PUT'],
|
methods=['GET'],
|
||||||
description=_('Synchronize web site types'),
|
description=_('Synchronize web site types'),
|
||||||
summary=_('Synchronize web site types'),
|
summary=_('Synchronize web site types'),
|
||||||
operation_id=_('Synchronize web site types'),
|
operation_id=_('Synchronize web site types'),
|
||||||
parameters=SyncWebAPI.get_parameters(),
|
parameters=SyncWebAPI.get_parameters(),
|
||||||
|
request=SyncWebAPI.get_request(),
|
||||||
responses=SyncWebAPI.get_response(),
|
responses=SyncWebAPI.get_response(),
|
||||||
tags=[_('Knowledge Base/Documentation')]
|
tags=[_('Knowledge Base/Documentation')]
|
||||||
)
|
)
|
||||||
@has_permissions(PermissionConstants.DOCUMENT_EDIT.get_workspace_permission())
|
@has_permissions(PermissionConstants.DOCUMENT_EDIT.get_workspace_permission())
|
||||||
def put(self, request: Request, workspace_id: str, knowledge_id: str, document_id: str):
|
def get(self, request: Request, workspace_id: str, knowledge_id: str, document_id: str):
|
||||||
return result.success(DocumentSerializers.Sync(
|
return result.success(DocumentSerializers.Sync(
|
||||||
data={'document_id': document_id, 'knowledge_id': knowledge_id, 'workspace_id': workspace_id}
|
data={'document_id': document_id, 'knowledge_id': knowledge_id, 'workspace_id': workspace_id}
|
||||||
).sync())
|
).sync())
|
||||||
@ -291,6 +292,31 @@ class DocumentView(APIView):
|
|||||||
data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}
|
data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}
|
||||||
).batch_delete(request.data))
|
).batch_delete(request.data))
|
||||||
|
|
||||||
|
class Page(APIView):
|
||||||
|
authentication_classes = [TokenAuth]
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
methods=['GET'],
|
||||||
|
description=_('Get document by pagination'),
|
||||||
|
summary=_('Get document by pagination'),
|
||||||
|
operation_id=_('Get document by pagination'),
|
||||||
|
parameters=DocumentTreeReadAPI.get_parameters(),
|
||||||
|
responses=DocumentTreeReadAPI.get_response(),
|
||||||
|
tags=[_('Knowledge Base/Documentation')]
|
||||||
|
)
|
||||||
|
@has_permissions(PermissionConstants.DOCUMENT_READ.get_workspace_permission())
|
||||||
|
def get(self, request: Request, workspace_id: str, knowledge_id: str, current_page: int, page_size: int):
|
||||||
|
return result.success(DocumentSerializers.Query(
|
||||||
|
data={
|
||||||
|
'workspace_id': workspace_id,
|
||||||
|
'knowledge_id': knowledge_id,
|
||||||
|
'folder_id': request.query_params.get('folder_id'),
|
||||||
|
'name': request.query_params.get('name'),
|
||||||
|
'desc': request.query_params.get("desc"),
|
||||||
|
'user_id': request.query_params.get('user_id')
|
||||||
|
}
|
||||||
|
).page(current_page, page_size))
|
||||||
|
|
||||||
|
|
||||||
class WebDocumentView(APIView):
|
class WebDocumentView(APIView):
|
||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user