### What problem does this PR solve? 1. Split SDK class to optimize code structure `ragflow.get_all_datasets()` ===> `ragflow.dataset.list()` 2. Fixed the parameter validation to allow for empty values. 3. Change the way of checking parameter nullness, Because even if the parameter is empty, the key still exists, this is a feature from [APIFlask](https://apiflask.com/schema/). `if "parser_config" in json_data` ===> `if json_data["parser_config"]`  4. Some common parameter error messages, all from [Marshmallow](https://marshmallow.readthedocs.io/en/stable/marshmallow.fields.html) Parameter validation configuration ``` kb_id = fields.String(required=True) parser_id = fields.String(validate=validators.OneOf([parser_type.value for parser_type in ParserType]), allow_none=True) ``` When my parameter is ``` kb_id=None, parser_id='A4' ``` Error messages ``` { "detail": { "json": { "kb_id": [ "Field may not be null." ], "parser_id": [ "Must be one of: presentation, laws, manual, paper, resume, book, qa, table, naive, picture, one, audio, email, knowledge_graph." ] } }, "message": "Validation error" } ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
18 lines
615 B
Python
18 lines
615 B
Python
from ragflow import RAGFlow
|
|
|
|
from sdk.python.test.common import API_KEY, HOST_ADDRESS
|
|
from sdk.python.test.test_sdkbase import TestSdk
|
|
|
|
|
|
class TestDocuments(TestSdk):
|
|
|
|
def test_upload_two_files(self):
|
|
"""
|
|
Test uploading two files with success.
|
|
"""
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
|
|
created_res = ragflow.dataset.create("test_upload_two_files")
|
|
dataset_id = created_res["data"]["kb_id"]
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"]
|
|
res = ragflow.document.upload(dataset_id, file_paths)
|
|
assert res["retmsg"] == "success" |