mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refa: validation utils to use Pydantic v2 style models (#9037)
### What problem does this PR solve? - Update BaseModel to use model_config instead of Config class - Replace StrEnum with Literal types for method fields - Convert Field declarations to Annotated style ### Type of change - [x] Refactoring
This commit is contained in:
@ -254,11 +254,8 @@ class TestDatasetCreate:
|
||||
[
|
||||
("me", "me"),
|
||||
("team", "team"),
|
||||
("me_upercase", "ME"),
|
||||
("team_upercase", "TEAM"),
|
||||
("whitespace", " ME "),
|
||||
],
|
||||
ids=["me", "team", "me_upercase", "team_upercase", "whitespace"],
|
||||
ids=["me", "team"],
|
||||
)
|
||||
def test_permission(self, client, name, permission):
|
||||
payload = {"name": name, "permission": permission}
|
||||
@ -271,8 +268,11 @@ class TestDatasetCreate:
|
||||
[
|
||||
("empty", ""),
|
||||
("unknown", "unknown"),
|
||||
("me_upercase", "ME"),
|
||||
("team_upercase", "TEAM"),
|
||||
("whitespace", " ME "),
|
||||
],
|
||||
ids=["empty", "unknown"],
|
||||
ids=["empty", "unknown", "me_upercase", "team_upercase", "whitespace"],
|
||||
)
|
||||
def test_permission_invalid(self, client, name, permission):
|
||||
payload = {"name": name, "permission": permission}
|
||||
@ -466,57 +466,57 @@ class TestDatasetCreate:
|
||||
[
|
||||
("auto_keywords_min_limit", {"auto_keywords": -1}, "Input should be greater than or equal to 0"),
|
||||
("auto_keywords_max_limit", {"auto_keywords": 33}, "Input should be less than or equal to 32"),
|
||||
("auto_keywords_float_not_allowed", {"auto_keywords": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("auto_keywords_type_invalid", {"auto_keywords": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("auto_keywords_float_not_allowed", {"auto_keywords": 3.14}, "Input should be a valid integer"),
|
||||
("auto_keywords_type_invalid", {"auto_keywords": "string"}, "Input should be a valid integer"),
|
||||
("auto_questions_min_limit", {"auto_questions": -1}, "Input should be greater than or equal to 0"),
|
||||
("auto_questions_max_limit", {"auto_questions": 11}, "Input should be less than or equal to 10"),
|
||||
("auto_questions_float_not_allowed", {"auto_questions": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("auto_questions_type_invalid", {"auto_questions": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("auto_questions_float_not_allowed", {"auto_questions": 3.14}, "Input should be a valid integer"),
|
||||
("auto_questions_type_invalid", {"auto_questions": "string"}, "Input should be a valid integer"),
|
||||
("chunk_token_num_min_limit", {"chunk_token_num": 0}, "Input should be greater than or equal to 1"),
|
||||
("chunk_token_num_max_limit", {"chunk_token_num": 2049}, "Input should be less than or equal to 2048"),
|
||||
("chunk_token_num_float_not_allowed", {"chunk_token_num": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("chunk_token_num_type_invalid", {"chunk_token_num": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("chunk_token_num_float_not_allowed", {"chunk_token_num": 3.14}, "Input should be a valid integer"),
|
||||
("chunk_token_num_type_invalid", {"chunk_token_num": "string"}, "Input should be a valid integer"),
|
||||
("delimiter_empty", {"delimiter": ""}, "String should have at least 1 character"),
|
||||
("html4excel_type_invalid", {"html4excel": "string"}, "Input should be a valid boolean, unable to interpret input"),
|
||||
("html4excel_type_invalid", {"html4excel": "string"}, "Input should be a valid boolean"),
|
||||
("tag_kb_ids_not_list", {"tag_kb_ids": "1,2"}, "Input should be a valid list"),
|
||||
("tag_kb_ids_int_in_list", {"tag_kb_ids": [1, 2]}, "Input should be a valid string"),
|
||||
("topn_tags_min_limit", {"topn_tags": 0}, "Input should be greater than or equal to 1"),
|
||||
("topn_tags_max_limit", {"topn_tags": 11}, "Input should be less than or equal to 10"),
|
||||
("topn_tags_float_not_allowed", {"topn_tags": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("topn_tags_type_invalid", {"topn_tags": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("topn_tags_float_not_allowed", {"topn_tags": 3.14}, "Input should be a valid integer"),
|
||||
("topn_tags_type_invalid", {"topn_tags": "string"}, "Input should be a valid integer"),
|
||||
("filename_embd_weight_min_limit", {"filename_embd_weight": -1}, "Input should be greater than or equal to 0"),
|
||||
("filename_embd_weight_max_limit", {"filename_embd_weight": 1.1}, "Input should be less than or equal to 1"),
|
||||
("filename_embd_weight_type_invalid", {"filename_embd_weight": "string"}, "Input should be a valid number, unable to parse string as a number"),
|
||||
("filename_embd_weight_type_invalid", {"filename_embd_weight": "string"}, "Input should be a valid number"),
|
||||
("task_page_size_min_limit", {"task_page_size": 0}, "Input should be greater than or equal to 1"),
|
||||
("task_page_size_float_not_allowed", {"task_page_size": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("task_page_size_type_invalid", {"task_page_size": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("task_page_size_float_not_allowed", {"task_page_size": 3.14}, "Input should be a valid integer"),
|
||||
("task_page_size_type_invalid", {"task_page_size": "string"}, "Input should be a valid integer"),
|
||||
("pages_not_list", {"pages": "1,2"}, "Input should be a valid list"),
|
||||
("pages_not_list_in_list", {"pages": ["1,2"]}, "Input should be a valid list"),
|
||||
("pages_not_int_list", {"pages": [["string1", "string2"]]}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("graphrag_type_invalid", {"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
("pages_not_int_list", {"pages": [["string1", "string2"]]}, "Input should be a valid integer"),
|
||||
("graphrag_type_invalid", {"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean"),
|
||||
("graphrag_entity_types_not_list", {"graphrag": {"entity_types": "1,2"}}, "Input should be a valid list"),
|
||||
("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"),
|
||||
("graphrag_method_unknown", {"graphrag": {"method": "unknown"}}, "Input should be 'light' or 'general'"),
|
||||
("graphrag_method_none", {"graphrag": {"method": None}}, "Input should be 'light' or 'general'"),
|
||||
("graphrag_community_type_invalid", {"graphrag": {"community": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
("graphrag_resolution_type_invalid", {"graphrag": {"resolution": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
("raptor_type_invalid", {"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
("graphrag_community_type_invalid", {"graphrag": {"community": "string"}}, "Input should be a valid boolean"),
|
||||
("graphrag_resolution_type_invalid", {"graphrag": {"resolution": "string"}}, "Input should be a valid boolean"),
|
||||
("raptor_type_invalid", {"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean"),
|
||||
("raptor_prompt_empty", {"raptor": {"prompt": ""}}, "String should have at least 1 character"),
|
||||
("raptor_prompt_space", {"raptor": {"prompt": " "}}, "String should have at least 1 character"),
|
||||
("raptor_max_token_min_limit", {"raptor": {"max_token": 0}}, "Input should be greater than or equal to 1"),
|
||||
("raptor_max_token_max_limit", {"raptor": {"max_token": 2049}}, "Input should be less than or equal to 2048"),
|
||||
("raptor_max_token_float_not_allowed", {"raptor": {"max_token": 3.14}}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("raptor_max_token_type_invalid", {"raptor": {"max_token": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("raptor_max_token_float_not_allowed", {"raptor": {"max_token": 3.14}}, "Input should be a valid integer"),
|
||||
("raptor_max_token_type_invalid", {"raptor": {"max_token": "string"}}, "Input should be a valid integer"),
|
||||
("raptor_threshold_min_limit", {"raptor": {"threshold": -0.1}}, "Input should be greater than or equal to 0"),
|
||||
("raptor_threshold_max_limit", {"raptor": {"threshold": 1.1}}, "Input should be less than or equal to 1"),
|
||||
("raptor_threshold_type_invalid", {"raptor": {"threshold": "string"}}, "Input should be a valid number, unable to parse string as a number"),
|
||||
("raptor_threshold_type_invalid", {"raptor": {"threshold": "string"}}, "Input should be a valid number"),
|
||||
("raptor_max_cluster_min_limit", {"raptor": {"max_cluster": 0}}, "Input should be greater than or equal to 1"),
|
||||
("raptor_max_cluster_max_limit", {"raptor": {"max_cluster": 1025}}, "Input should be less than or equal to 1024"),
|
||||
("raptor_max_cluster_float_not_allowed", {"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer, got a number with a fractional par"),
|
||||
("raptor_max_cluster_type_invalid", {"raptor": {"max_cluster": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("raptor_max_cluster_float_not_allowed", {"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer"),
|
||||
("raptor_max_cluster_type_invalid", {"raptor": {"max_cluster": "string"}}, "Input should be a valid integer"),
|
||||
("raptor_random_seed_min_limit", {"raptor": {"random_seed": -1}}, "Input should be greater than or equal to 0"),
|
||||
("raptor_random_seed_float_not_allowed", {"raptor": {"random_seed": 3.14}}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
("raptor_random_seed_type_invalid", {"raptor": {"random_seed": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
("raptor_random_seed_float_not_allowed", {"raptor": {"random_seed": 3.14}}, "Input should be a valid integer"),
|
||||
("raptor_random_seed_type_invalid", {"raptor": {"random_seed": "string"}}, "Input should be a valid integer"),
|
||||
("parser_config_type_invalid", {"delimiter": "a" * 65536}, "Parser config exceeds size limit (max 65,535 characters)"),
|
||||
],
|
||||
ids=[
|
||||
|
||||
@ -141,11 +141,8 @@ class TestDatasetsList:
|
||||
[
|
||||
{"orderby": "create_time"},
|
||||
{"orderby": "update_time"},
|
||||
{"orderby": "CREATE_TIME"},
|
||||
{"orderby": "UPDATE_TIME"},
|
||||
{"orderby": " create_time "},
|
||||
],
|
||||
ids=["orderby_create_time", "orderby_update_time", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
|
||||
ids=["orderby_create_time", "orderby_update_time"],
|
||||
)
|
||||
def test_orderby(self, client, params):
|
||||
client.list_datasets(**params)
|
||||
@ -156,8 +153,11 @@ class TestDatasetsList:
|
||||
[
|
||||
{"orderby": ""},
|
||||
{"orderby": "unknown"},
|
||||
{"orderby": "CREATE_TIME"},
|
||||
{"orderby": "UPDATE_TIME"},
|
||||
{"orderby": " create_time "},
|
||||
],
|
||||
ids=["empty", "unknown"],
|
||||
ids=["empty", "unknown", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
|
||||
)
|
||||
def test_orderby_invalid(self, client, params):
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
|
||||
@ -242,11 +242,8 @@ class TestDatasetUpdate:
|
||||
[
|
||||
"me",
|
||||
"team",
|
||||
"ME",
|
||||
"TEAM",
|
||||
" ME ",
|
||||
],
|
||||
ids=["me", "team", "me_upercase", "team_upercase", "whitespace"],
|
||||
ids=["me", "team"],
|
||||
)
|
||||
def test_permission(self, client, add_dataset_func, permission):
|
||||
dataset = add_dataset_func
|
||||
@ -263,8 +260,11 @@ class TestDatasetUpdate:
|
||||
"",
|
||||
"unknown",
|
||||
list(),
|
||||
"ME",
|
||||
"TEAM",
|
||||
" ME ",
|
||||
],
|
||||
ids=["empty", "unknown", "type_error"],
|
||||
ids=["empty", "unknown", "type_error", "me_upercase", "team_upercase", "whitespace"],
|
||||
)
|
||||
def test_permission_invalid(self, add_dataset_func, permission):
|
||||
dataset = add_dataset_func
|
||||
@ -514,57 +514,57 @@ class TestDatasetUpdate:
|
||||
[
|
||||
({"auto_keywords": -1}, "Input should be greater than or equal to 0"),
|
||||
({"auto_keywords": 33}, "Input should be less than or equal to 32"),
|
||||
({"auto_keywords": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"auto_keywords": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"auto_keywords": 3.14}, "Input should be a valid integer"),
|
||||
({"auto_keywords": "string"}, "Input should be a valid integer"),
|
||||
({"auto_questions": -1}, "Input should be greater than or equal to 0"),
|
||||
({"auto_questions": 11}, "Input should be less than or equal to 10"),
|
||||
({"auto_questions": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"auto_questions": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"auto_questions": 3.14}, "Input should be a valid integer"),
|
||||
({"auto_questions": "string"}, "Input should be a valid integer"),
|
||||
({"chunk_token_num": 0}, "Input should be greater than or equal to 1"),
|
||||
({"chunk_token_num": 2049}, "Input should be less than or equal to 2048"),
|
||||
({"chunk_token_num": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"chunk_token_num": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"chunk_token_num": 3.14}, "Input should be a valid integer"),
|
||||
({"chunk_token_num": "string"}, "Input should be a valid integer"),
|
||||
({"delimiter": ""}, "String should have at least 1 character"),
|
||||
({"html4excel": "string"}, "Input should be a valid boolean, unable to interpret input"),
|
||||
({"html4excel": "string"}, "Input should be a valid boolean"),
|
||||
({"tag_kb_ids": "1,2"}, "Input should be a valid list"),
|
||||
({"tag_kb_ids": [1, 2]}, "Input should be a valid string"),
|
||||
({"topn_tags": 0}, "Input should be greater than or equal to 1"),
|
||||
({"topn_tags": 11}, "Input should be less than or equal to 10"),
|
||||
({"topn_tags": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"topn_tags": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"topn_tags": 3.14}, "Input should be a valid integer"),
|
||||
({"topn_tags": "string"}, "Input should be a valid integer"),
|
||||
({"filename_embd_weight": -1}, "Input should be greater than or equal to 0"),
|
||||
({"filename_embd_weight": 1.1}, "Input should be less than or equal to 1"),
|
||||
({"filename_embd_weight": "string"}, "Input should be a valid number, unable to parse string as a number"),
|
||||
({"filename_embd_weight": "string"}, "Input should be a valid number"),
|
||||
({"task_page_size": 0}, "Input should be greater than or equal to 1"),
|
||||
({"task_page_size": 3.14}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"task_page_size": "string"}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"task_page_size": 3.14}, "Input should be a valid integer"),
|
||||
({"task_page_size": "string"}, "Input should be a valid integer"),
|
||||
({"pages": "1,2"}, "Input should be a valid list"),
|
||||
({"pages": ["1,2"]}, "Input should be a valid list"),
|
||||
({"pages": [["string1", "string2"]]}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
({"pages": [["string1", "string2"]]}, "Input should be a valid integer"),
|
||||
({"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean"),
|
||||
({"graphrag": {"entity_types": "1,2"}}, "Input should be a valid list"),
|
||||
({"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"),
|
||||
({"graphrag": {"method": "unknown"}}, "Input should be 'light' or 'general'"),
|
||||
({"graphrag": {"method": None}}, "Input should be 'light' or 'general'"),
|
||||
({"graphrag": {"community": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
({"graphrag": {"resolution": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
({"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean, unable to interpret input"),
|
||||
({"graphrag": {"community": "string"}}, "Input should be a valid boolean"),
|
||||
({"graphrag": {"resolution": "string"}}, "Input should be a valid boolean"),
|
||||
({"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean"),
|
||||
({"raptor": {"prompt": ""}}, "String should have at least 1 character"),
|
||||
({"raptor": {"prompt": " "}}, "String should have at least 1 character"),
|
||||
({"raptor": {"max_token": 0}}, "Input should be greater than or equal to 1"),
|
||||
({"raptor": {"max_token": 2049}}, "Input should be less than or equal to 2048"),
|
||||
({"raptor": {"max_token": 3.14}}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"raptor": {"max_token": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"raptor": {"max_token": 3.14}}, "Input should be a valid integer"),
|
||||
({"raptor": {"max_token": "string"}}, "Input should be a valid integer"),
|
||||
({"raptor": {"threshold": -0.1}}, "Input should be greater than or equal to 0"),
|
||||
({"raptor": {"threshold": 1.1}}, "Input should be less than or equal to 1"),
|
||||
({"raptor": {"threshold": "string"}}, "Input should be a valid number, unable to parse string as a number"),
|
||||
({"raptor": {"threshold": "string"}}, "Input should be a valid number"),
|
||||
({"raptor": {"max_cluster": 0}}, "Input should be greater than or equal to 1"),
|
||||
({"raptor": {"max_cluster": 1025}}, "Input should be less than or equal to 1024"),
|
||||
({"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer, got a number with a fractional par"),
|
||||
({"raptor": {"max_cluster": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer"),
|
||||
({"raptor": {"max_cluster": "string"}}, "Input should be a valid integer"),
|
||||
({"raptor": {"random_seed": -1}}, "Input should be greater than or equal to 0"),
|
||||
({"raptor": {"random_seed": 3.14}}, "Input should be a valid integer, got a number with a fractional part"),
|
||||
({"raptor": {"random_seed": "string"}}, "Input should be a valid integer, unable to parse string as an integer"),
|
||||
({"raptor": {"random_seed": 3.14}}, "Input should be a valid integer"),
|
||||
({"raptor": {"random_seed": "string"}}, "Input should be a valid integer"),
|
||||
({"delimiter": "a" * 65536}, "Parser config exceeds size limit (max 65,535 characters)"),
|
||||
],
|
||||
ids=[
|
||||
|
||||
Reference in New Issue
Block a user