Fix: #5719 Added type check for parser_config (#6243)

### What problem does this PR solve?

Fix #5719 
Add data type validation for parser_config

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
liu an 2025-03-18 18:40:06 +08:00 committed by GitHub
parent 7eb417b24f
commit d16033dd2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 35 deletions

View File

@ -399,9 +399,15 @@ def valid_parser_config(parser_config):
for k in parser_config.keys():
assert k in scopes, f"Abnormal 'parser_config'. Invalid key: {k}"
assert isinstance(parser_config.get("chunk_token_num", 1), int), "chunk_token_num should be int"
assert 1 <= parser_config.get("chunk_token_num", 1) < 100000000, "chunk_token_num should be in range from 1 to 100000000"
assert isinstance(parser_config.get("task_page_size", 1), int), "task_page_size should be int"
assert 1 <= parser_config.get("task_page_size", 1) < 100000000, "task_page_size should be in range from 1 to 100000000"
assert isinstance(parser_config.get("auto_keywords", 1), int), "auto_keywords should be int"
assert 0 <= parser_config.get("auto_keywords", 0) < 32, "auto_keywords should be in range from 0 to 32"
assert isinstance(parser_config.get("auto_questions", 1), int), "auto_questions should be int"
assert 0 <= parser_config.get("auto_questions", 0) < 10, "auto_questions should be in range from 0 to 10"
assert isinstance(parser_config.get("topn_tags", 1), int), "topn_tags should be int"
assert 0 <= parser_config.get("topn_tags", 0) < 10, "topn_tags should be in range from 0 to 10"
assert isinstance(parser_config.get("html4excel", False), bool), "html4excel should be True or False"
assert isinstance(parser_config.get("delimiter", ""), str), "delimiter should be str"

View File

@ -220,21 +220,19 @@ class TestAdvancedConfigurations:
100,
"AssertionError('chunk_token_num should be in range from 1 to 100000000')",
),
pytest.param(
(
"naive_chunk_token_num_float",
"naive",
{"chunk_token_num": 3.14},
102,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
100,
"AssertionError('chunk_token_num should be int')",
),
pytest.param(
(
"naive_chunk_token_num_str",
"naive",
{"chunk_token_num": "1024"},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('chunk_token_num should be int')",
),
(
"naive_layout_recognize_DeepDOC",
@ -261,13 +259,12 @@ class TestAdvancedConfigurations:
),
("naive_delimiter_empty", "naive", {"delimiter": ""}, 0, ""),
("naive_delimiter_backticks", "naive", {"delimiter": "`##`"}, 0, ""),
pytest.param(
(
"naive_delimiter_not_str",
"naive",
{"delimiter": 1},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('delimiter should be str')",
),
(
"naive_task_page_size_negative",
@ -290,21 +287,19 @@ class TestAdvancedConfigurations:
100,
"AssertionError('task_page_size should be in range from 1 to 100000000')",
),
pytest.param(
(
"naive_task_page_size_float",
"naive",
{"task_page_size": 3.14},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('task_page_size should be int')",
),
pytest.param(
(
"naive_task_page_size_str",
"naive",
{"task_page_size": "1024"},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('task_page_size should be int')",
),
("naive_raptor_true", "naive", {"raptor": {"use_raptor": True}}, 0, ""),
("naive_raptor_false", "naive", {"raptor": {"use_raptor": False}}, 0, ""),
@ -329,21 +324,19 @@ class TestAdvancedConfigurations:
100,
"AssertionError('auto_keywords should be in range from 0 to 32')",
),
pytest.param(
(
"naive_auto_keywords_float",
"naive",
{"auto_questions": 3.14},
{"auto_keywords": 3.14},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('auto_keywords should be int')",
),
pytest.param(
(
"naive_auto_keywords_str",
"naive",
{"auto_keywords": "1024"},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('auto_keywords should be int')",
),
(
"naive_auto_questions_negative",
@ -359,21 +352,19 @@ class TestAdvancedConfigurations:
100,
"AssertionError('auto_questions should be in range from 0 to 10')",
),
pytest.param(
(
"naive_auto_questions_float",
"naive",
{"auto_questions": 3.14},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('auto_questions should be int')",
),
pytest.param(
(
"naive_auto_questions_str",
"naive",
{"auto_questions": "1024"},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('auto_questions should be int')",
),
(
"naive_topn_tags_negative",
@ -389,21 +380,19 @@ class TestAdvancedConfigurations:
100,
"AssertionError('topn_tags should be in range from 0 to 10')",
),
pytest.param(
(
"naive_topn_tags_float",
"naive",
{"topn_tags": 3.14},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('topn_tags should be int')",
),
pytest.param(
(
"naive_topn_tags_str",
"naive",
{"topn_tags": "1024"},
100,
"",
marks=pytest.mark.xfail(reason="issue#5719"),
"AssertionError('topn_tags should be int')",
),
],
)