Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dataset delete endpoint #5048

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions api/controllers/service_api/dataset/dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import request
from flask_restful import marshal, reqparse
from werkzeug.exceptions import NotFound

import services.dataset_service
from controllers.service_api import api
Expand All @@ -19,10 +20,12 @@ def _validate_name(name):
return name


class DatasetApi(DatasetApiResource):
"""Resource for get datasets."""
class DatasetListApi(DatasetApiResource):
"""Resource for datasets."""

def get(self, tenant_id):
"""Resource for getting datasets."""

page = request.args.get('page', default=1, type=int)
limit = request.args.get('limit', default=20, type=int)
provider = request.args.get('provider', default="vendor")
Expand Down Expand Up @@ -65,9 +68,9 @@ def get(self, tenant_id):
}
return response, 200

"""Resource for datasets."""

def post(self, tenant_id):
"""Resource for creating datasets."""
parser = reqparse.RequestParser()
parser.add_argument('name', nullable=False, required=True,
help='type is required. Name must be between 1 to 40 characters.',
Expand All @@ -89,6 +92,31 @@ def post(self, tenant_id):

return marshal(dataset, dataset_detail_fields), 200

class DatasetApi(DatasetApiResource):
"""Resource for dataset."""

def delete(self, _, dataset_id):
"""
Deletes a dataset given its ID.
Args:
dataset_id (UUID): The ID of the dataset to be deleted.
Returns:
dict: A dictionary with a key 'result' and a value 'success'
if the dataset was successfully deleted. Omitted in HTTP response.
int: HTTP status code 204 indicating that the operation was successful.
Raises:
NotFound: If the dataset with the given ID does not exist.
"""

dataset_id_str = str(dataset_id)

api.add_resource(DatasetApi, '/datasets')
if DatasetService.delete_dataset(dataset_id_str, current_user):
return {'result': 'success'}, 204
else:
raise NotFound("Dataset not found.")

api.add_resource(DatasetListApi, '/datasets')
api.add_resource(DatasetApi, '/datasets/<uuid:dataset_id>')
37 changes: 37 additions & 0 deletions web/app/(commonLayout)/datasets/template/template.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from

---

<Heading
url='/datasets/{dataset_id}'
method='DELETE'
title='Delete knowledge'
name='#delete_dataset'
/>
<Row>
<Col>
### Params
<Properties>
<Property name='dataset_id' type='string' key='dataset_id'>
Knowledge ID
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup
title="Request"
tag="DELETE"
label="/datasets/{dataset_id}"
targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
>
```bash {{ title: 'cURL' }}
curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
--header 'Authorization: Bearer {api_key}'
```
</CodeGroup>
<CodeGroup title="Response">
```text {{ title: 'Response' }}
204 No Content
```
</CodeGroup>
</Col>
</Row>

---

<Heading
url='/datasets/{dataset_id}/documents/{document_id}/update_by_text'
method='POST'
Expand Down
37 changes: 37 additions & 0 deletions web/app/(commonLayout)/datasets/template/template.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from

---

<Heading
url='/datasets/{dataset_id}'
method='DELETE'
title='删除知识库'
name='#delete_dataset'
/>
<Row>
<Col>
### Path
<Properties>
<Property name='dataset_id' type='string' key='dataset_id'>
知识库 ID
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup
title="Request"
tag="DELETE"
label="/datasets/{dataset_id}"
targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
>
```bash {{ title: 'cURL' }}
curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
--header 'Authorization: Bearer {api_key}'
```
</CodeGroup>
<CodeGroup title="Response">
```text {{ title: 'Response' }}
204 No Content
```
</CodeGroup>
</Col>
</Row>

---

<Heading
url='/datasets/{dataset_id}/documents/{document_id}/update_by_text'
method='POST'
Expand Down