forked from infiniflow/ragflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What problem does this PR solve? You can use sdk to create a dataset ### Type of change - [x] New Feature --------- Co-authored-by: root <root@xwg>
- Loading branch information
Showing
7 changed files
with
126 additions
and
27 deletions.
There are no files selected for viewing
Empty file.
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,30 @@ | ||
class Base(object): | ||
def __init__(self, rag, res_dict): | ||
self.rag = rag | ||
for k, v in res_dict.items(): | ||
if isinstance(v, dict): | ||
self.__dict__[k] = Base(rag, v) | ||
else: | ||
self.__dict__[k] = v | ||
|
||
def to_json(self): | ||
pr = {} | ||
for name in dir(self): | ||
value = getattr(self, name) | ||
if not name.startswith('__') and not callable(value) and name != "rag": | ||
if isinstance(value, Base): | ||
pr[name] = value.to_json() | ||
else: | ||
pr[name] = value | ||
return pr | ||
|
||
|
||
def post(self, path, param): | ||
res = self.rag.post(path,param) | ||
return res | ||
|
||
def get(self, path, params=''): | ||
res = self.rag.get(path,params) | ||
return res | ||
|
||
|
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,33 @@ | ||
from .base import Base | ||
|
||
|
||
class DataSet(Base): | ||
class ParseConfig(Base): | ||
def __init__(self, rag, res_dict): | ||
self.chunk_token_count = 128 | ||
self.layout_recognize = True | ||
self.delimiter = '\n!?。;!?' | ||
self.task_page_size = 12 | ||
super().__init__(rag, res_dict) | ||
|
||
def __init__(self, rag, res_dict): | ||
self.id = "" | ||
self.name = "" | ||
self.avatar = "" | ||
self.tenant_id = None | ||
self.description = "" | ||
self.language = "English" | ||
self.embedding_model = "" | ||
self.permission = "me" | ||
self.document_count = 0 | ||
self.chunk_count = 0 | ||
self.parse_method = 0 | ||
self.parser_config = None | ||
super().__init__(rag, res_dict) | ||
|
||
def delete(self): | ||
try: | ||
self.post("/rm", {"kb_id": self.id}) | ||
return True | ||
except Exception: | ||
return False |
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 = 'IjJkOGQ4ZDE2MzkyMjExZWZhYTk0MzA0M2Q3ZWU1MzdlIg.ZoUfug.RmqcYyCrlAnLtkzk6bYXiXN3eEY' | ||
API_KEY = 'IjUxNGM0MmM4NWY5MzExZWY5MDhhMDI0MmFjMTIwMDA2Ig.ZsWebA.mV1NKdSPPllgowiH-7vz36tMWyI' | ||
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 |
---|---|---|
@@ -0,0 1,23 @@ | ||
from ragflow import RAGFlow | ||
|
||
from common import API_KEY, HOST_ADDRESS | ||
from test_sdkbase import TestSdk | ||
|
||
|
||
class TestDataset(TestSdk): | ||
def test_create_dataset_with_success(self): | ||
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." | ||
|
||
def test_delete_one_file(self): | ||
""" | ||
Test deleting one file 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" |