mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
delete_dataset method and tests created (#1186)
### What problem does this PR solve? This PR have completed both HTTP API and Python SDK for 'delete_dataset". In addition, there are tests for it. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -39,8 +39,23 @@ class RAGFlow:
|
||||
result_dict = json.loads(res.text)
|
||||
return result_dict
|
||||
|
||||
def delete_dataset(self, dataset_name=None, dataset_id=None):
|
||||
return dataset_name
|
||||
def delete_dataset(self, dataset_name):
|
||||
dataset_id = self.find_dataset_id_by_name(dataset_name)
|
||||
if not dataset_id:
|
||||
return {"success": False, "message": "Dataset not found."}
|
||||
|
||||
res = requests.delete(f"{self.dataset_url}/{dataset_id}", headers=self.authorization_header)
|
||||
if res.status_code == 200:
|
||||
return {"success": True, "message": "Dataset deleted successfully!"}
|
||||
else:
|
||||
return {"success": False, "message": f"Other status code: {res.status_code}"}
|
||||
|
||||
def find_dataset_id_by_name(self, dataset_name):
|
||||
res = requests.get(self.dataset_url, headers=self.authorization_header)
|
||||
for dataset in res.json()['data']:
|
||||
if dataset['name'] == dataset_name:
|
||||
return dataset['id']
|
||||
return None
|
||||
|
||||
def list_dataset(self, offset=0, count=-1, orderby="create_time", desc=True):
|
||||
params = {
|
||||
|
||||
@ -101,6 +101,21 @@ class TestDataset(TestSdk):
|
||||
_, res = response
|
||||
assert "IndexError" in res['message']
|
||||
|
||||
def test_delete_one_dataset_with_success(self):
|
||||
# get the real name of the created dataset
|
||||
ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
res = ragflow.create_dataset("kb0")
|
||||
real_dataset_name = res['data']['dataset_name']
|
||||
print("name", real_dataset_name)
|
||||
# delete this dataset
|
||||
result = ragflow.delete_dataset(real_dataset_name)
|
||||
print(result)
|
||||
assert result["success"] is True
|
||||
|
||||
def test_delete_dataset_with_not_existing_dataset(self):
|
||||
ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
res = ragflow.delete_dataset("weird_dataset")
|
||||
assert res["success"] is False
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user