mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 21:26:39 +00:00
fix(community): reject bool and fractional web-search max_results like image search does (#5852)
This commit is contained in:
parent
5242fcfb63
commit
63401d79fd
@ -33,10 +33,14 @@ WIKIPEDIA_LANGUAGE_ALIASES = {
|
||||
|
||||
def _coerce_max_results(value: object) -> int:
|
||||
"""Normalize config/parameter values before passing them to DDGS."""
|
||||
try:
|
||||
count = int(value) # type: ignore[call-overload]
|
||||
except (TypeError, ValueError, OverflowError):
|
||||
if isinstance(value, bool) or (isinstance(value, float) and not value.is_integer()):
|
||||
# int() accepts booleans and silently truncates a YAML value such as 3.5.
|
||||
count = 0
|
||||
else:
|
||||
try:
|
||||
count = int(value) # type: ignore[call-overload]
|
||||
except (TypeError, ValueError, OverflowError):
|
||||
count = 0
|
||||
if count <= 0:
|
||||
logger.warning("Invalid DDG Search max_results=%r; using default %s", value, DEFAULT_MAX_RESULTS)
|
||||
return DEFAULT_MAX_RESULTS
|
||||
|
||||
@ -22,6 +22,8 @@ from deerflow.community.ddg_search import tools
|
||||
pytest.param("$DDG_TEST_MAX_RESULTS", "abc", {"max_results": 2}, 5, True, id="invalid-env"),
|
||||
pytest.param("$DDG_TEST_MAX_RESULTS", "", {"max_results": 2}, 5, True, id="empty-env"),
|
||||
pytest.param("$DDG_TEST_MAX_RESULTS", "3.5", {"max_results": 2}, 5, True, id="fractional-env"),
|
||||
pytest.param(3.5, "3", {"max_results": 2}, 5, True, id="fractional-config"),
|
||||
pytest.param(True, "3", {"max_results": 2}, 5, True, id="boolean-config"),
|
||||
pytest.param("$DDG_TEST_MAX_RESULTS", "0", {"max_results": 2}, 5, True, id="zero-env"),
|
||||
pytest.param("$DDG_TEST_MAX_RESULTS", "-2", {"max_results": 2}, 5, True, id="negative-env"),
|
||||
pytest.param(0, "3", {}, 5, True, id="zero-config"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user