-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
create and update dataset #2110
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
13efd5e
create and update dataset
c0d240b
create and update dataset v2.
8fd3b8c
Update api/apps/sdk/dataset.py
KevinHuSh 6f3ce9d
Update sdk/python/ragflow/ragflow.py
KevinHuSh 9035a12
Update sdk/python/ragflow/ragflow.py
KevinHuSh 39db988
Update sdk/python/ragflow/ragflow.py
KevinHuSh cb5482e
Update sdk/python/ragflow/ragflow.py
KevinHuSh ec6535a
Update sdk/python/ragflow/ragflow.py
KevinHuSh f40d7eb
Update sdk/python/ragflow/ragflow.py
KevinHuSh 5cb8ada
Update sdk/python/ragflow/ragflow.py
KevinHuSh ed16e89
Update sdk/python/ragflow/ragflow.py
KevinHuSh 537a1a7
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh 320472e
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh e6d7455
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh 060b26c
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh 8ff9ef9
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh ee57be1
Update sdk/python/ragflow/modules/dataset.py
KevinHuSh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# | ||
# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from flask import request | ||
|
||
from api.db import StatusEnum | ||
from api.db.db_models import APIToken | ||
from api.db.services.knowledgebase_service import KnowledgebaseService | ||
from api.db.services.user_service import TenantService | ||
from api.settings import RetCode | ||
from api.utils import get_uuid | ||
from api.utils.api_utils import get_data_error_result | ||
from api.utils.api_utils import get_json_result | ||
|
||
|
||
@manager.route('/save', methods=['POST']) | ||
def save(): | ||
req = request.json | ||
token = request.headers.get('Authorization').split()[1] | ||
objs = APIToken.query(token=token) | ||
if not objs: | ||
return get_json_result( | ||
data=False, retmsg='Token is not valid!"', retcode=RetCode.AUTHENTICATION_ERROR) | ||
tenant_id = objs[0].tenant_id | ||
e, t = TenantService.get_by_id(tenant_id) | ||
if not e: | ||
return get_data_error_result(retmsg="Tenant not found.") | ||
if "id" not in req: | ||
req['id'] = get_uuid() | ||
req["name"] = req["name"].strip() | ||
if req["name"] == "": | ||
return get_data_error_result( | ||
retmsg="Name is not empty") | ||
if KnowledgebaseService.query(name=req["name"]): | ||
return get_data_error_result( | ||
retmsg="Duplicated knowledgebase name") | ||
req["tenant_id"] = tenant_id | ||
req['created_by'] = tenant_id | ||
req['embd_id'] = t.embd_id | ||
if not KnowledgebaseService.save(**req): | ||
return get_data_error_result(retmsg="Data saving error") | ||
req.pop('created_by') | ||
keys_to_rename = {'embd_id': "embedding_model", 'parser_id': 'parser_method', | ||
'chunk_num': 'chunk_count', 'doc_num': 'document_count'} | ||
for old_key,new_key in keys_to_rename.items(): | ||
if old_key in req: | ||
req[new_key]=req.pop(old_key) | ||
return get_json_result(data=req) | ||
else: | ||
if req["tenant_id"] != tenant_id or req["embd_id"] != t.embd_id: | ||
return get_data_error_result( | ||
retmsg="Can't change tenant_id or embedding_model") | ||
|
||
e, kb = KnowledgebaseService.get_by_id(req["id"]) | ||
if not e: | ||
return get_data_error_result( | ||
retmsg="Can't find this knowledgebase!") | ||
|
||
if not KnowledgebaseService.query( | ||
created_by=tenant_id, id=req["id"]): | ||
return get_json_result( | ||
data=False, retmsg=f'Only owner of knowledgebase authorized for this operation.', | ||
retcode=RetCode.OPERATING_ERROR) | ||
|
||
if req["chunk_num"] != kb.chunk_num or req['doc_num'] != kb.doc_num: | ||
return get_data_error_result( | ||
retmsg="Can't change document_count or chunk_count ") | ||
|
||
if kb.chunk_num > 0 and req['parser_id'] != kb.parser_id: | ||
return get_data_error_result( | ||
retmsg="if chunk count is not 0, parser method is not changable. ") | ||
|
||
|
||
if req["name"].lower() != kb.name.lower() \ | ||
and len(KnowledgebaseService.query(name=req["name"], tenant_id=req['tenant_id'], | ||
status=StatusEnum.VALID.value)) > 0: | ||
return get_data_error_result( | ||
retmsg="Duplicated knowledgebase name.") | ||
|
||
del req["id"] | ||
req['created_by'] = tenant_id | ||
if not KnowledgebaseService.update_by_id(kb.id, req): | ||
return get_data_error_result(retmsg="Data update error ") | ||
return get_json_result(data=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
|
||
API_KEY = 'IjUxNGM0MmM4NWY5MzExZWY5MDhhMDI0MmFjMTIwMDA2Ig.ZsWebA.mV1NKdSPPllgowiH-7vz36tMWyI' | ||
API_KEY = 'ragflow-k0N2I1MzQwNjNhMzExZWY5ODg1MDI0Mm' | ||
HOST_ADDRESS = 'http://127.0.0.1:9380' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
from ragflow import RAGFlow | ||
from ragflow import RAGFlow, DataSet | ||
|
||
from common import API_KEY, HOST_ADDRESS | ||
from test_sdkbase import TestSdk | ||
|
||
|
||
class TestDataset(TestSdk): | ||
def test_create_dataset_with_success(self): | ||
""" | ||
Test creating dataset with success | ||
""" | ||
rag = RAGFlow(API_KEY, HOST_ADDRESS) | ||
ds = rag.create_dataset("God") | ||
assert ds is not None, "The dataset creation failed, returned None." | ||
assert ds.name == "God", "Dataset name does not match." | ||
if isinstance(ds, DataSet): | ||
assert ds.name == "God", "Name does not match." | ||
else: | ||
assert False, f"Failed to create dataset, error: {ds}" | ||
|
||
def test_delete_one_file(self): | ||
def test_update_dataset_with_success(self): | ||
""" | ||
Test deleting one file with success. | ||
Test updating dataset with success. | ||
""" | ||
rag = RAGFlow(API_KEY, HOST_ADDRESS) | ||
ds = rag.create_dataset("ABC") | ||
assert ds is not None, "Failed to create dataset" | ||
assert ds.name == "ABC", "Dataset name mismatch" | ||
delete_result = ds.delete() | ||
assert delete_result is True, "Failed to delete dataset" | ||
if isinstance(ds, DataSet): | ||
assert ds.name == "ABC", "Name does not match." | ||
ds.name = 'DEF' | ||
res = ds.save() | ||
assert res is True, f"Failed to update dataset, error: {res}" | ||
|
||
else: | ||
assert False, f"Failed to create dataset, error: {ds}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.