mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 21:48:58 +08:00
feat: datasets openapi list segements support paged resp (#16603)
This commit is contained in:
parent
e2988acc2f
commit
83cd14104d
@ -1,3 +1,4 @@
|
|||||||
|
from flask import request
|
||||||
from flask_login import current_user # type: ignore
|
from flask_login import current_user # type: ignore
|
||||||
from flask_restful import marshal, reqparse # type: ignore
|
from flask_restful import marshal, reqparse # type: ignore
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
@ -74,6 +75,8 @@ class SegmentApi(DatasetApiResource):
|
|||||||
# check dataset
|
# check dataset
|
||||||
dataset_id = str(dataset_id)
|
dataset_id = str(dataset_id)
|
||||||
tenant_id = str(tenant_id)
|
tenant_id = str(tenant_id)
|
||||||
|
page = request.args.get("page", default=1, type=int)
|
||||||
|
limit = request.args.get("limit", default=20, type=int)
|
||||||
dataset = db.session.query(Dataset).filter(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
|
dataset = db.session.query(Dataset).filter(Dataset.tenant_id == tenant_id, Dataset.id == dataset_id).first()
|
||||||
if not dataset:
|
if not dataset:
|
||||||
raise NotFound("Dataset not found.")
|
raise NotFound("Dataset not found.")
|
||||||
@ -118,8 +121,25 @@ class SegmentApi(DatasetApiResource):
|
|||||||
query = query.where(DocumentSegment.content.ilike(f"%{keyword}%"))
|
query = query.where(DocumentSegment.content.ilike(f"%{keyword}%"))
|
||||||
|
|
||||||
total = query.count()
|
total = query.count()
|
||||||
segments = query.order_by(DocumentSegment.position).all()
|
query = query.order_by(DocumentSegment.position)
|
||||||
return {"data": marshal(segments, segment_fields), "doc_form": document.doc_form, "total": total}, 200
|
paginated_segments = query.paginate(
|
||||||
|
page=page,
|
||||||
|
per_page=limit,
|
||||||
|
max_per_page=100,
|
||||||
|
error_out=False,
|
||||||
|
)
|
||||||
|
segments = paginated_segments.items
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"data": marshal(segments, segment_fields),
|
||||||
|
"doc_form": document.doc_form,
|
||||||
|
"total": total,
|
||||||
|
"has_more": len(segments) == limit,
|
||||||
|
"limit": limit,
|
||||||
|
"page": page,
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, 200
|
||||||
|
|
||||||
|
|
||||||
class DatasetSegmentApi(DatasetApiResource):
|
class DatasetSegmentApi(DatasetApiResource):
|
||||||
|
@ -961,6 +961,12 @@ import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstructi
|
|||||||
<Property name='status' type='string' key='status'>
|
<Property name='status' type='string' key='status'>
|
||||||
Search status, completed
|
Search status, completed
|
||||||
</Property>
|
</Property>
|
||||||
|
<Property name='page' type='string' key='page'>
|
||||||
|
Page number (optional)
|
||||||
|
</Property>
|
||||||
|
<Property name='limit' type='string' key='limit'>
|
||||||
|
Number of items returned, default 20, range 1-100 (optional)
|
||||||
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Col>
|
</Col>
|
||||||
<Col sticky>
|
<Col sticky>
|
||||||
@ -1004,7 +1010,11 @@ import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstructi
|
|||||||
"error": null,
|
"error": null,
|
||||||
"stopped_at": null
|
"stopped_at": null
|
||||||
}],
|
}],
|
||||||
"doc_form": "text_model"
|
"doc_form": "text_model",
|
||||||
|
"has_more": false,
|
||||||
|
"limit": 20,
|
||||||
|
"total": 9,
|
||||||
|
"page": 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
@ -961,6 +961,12 @@ import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstructi
|
|||||||
<Property name='status' type='string' key='status'>
|
<Property name='status' type='string' key='status'>
|
||||||
搜索状态,completed
|
搜索状态,completed
|
||||||
</Property>
|
</Property>
|
||||||
|
<Property name='page' type='string' key='page'>
|
||||||
|
页码,可选
|
||||||
|
</Property>
|
||||||
|
<Property name='limit' type='string' key='limit'>
|
||||||
|
返回条数,可选,默认 20,范围 1-100
|
||||||
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Col>
|
</Col>
|
||||||
<Col sticky>
|
<Col sticky>
|
||||||
@ -1004,7 +1010,11 @@ import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstructi
|
|||||||
"error": null,
|
"error": null,
|
||||||
"stopped_at": null
|
"stopped_at": null
|
||||||
}],
|
}],
|
||||||
"doc_form": "text_model"
|
"doc_form": "text_model",
|
||||||
|
"has_more": false,
|
||||||
|
"limit": 20,
|
||||||
|
"total": 9,
|
||||||
|
"page": 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user