mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix: handle empty web_search_options dict edge case
Use key presence check instead of truthiness so that
kwargs={"web_search_options": {}} produces WebSearchOptions
with defaults rather than None.
This commit is contained in:
parent
1e18b33413
commit
bdc348f369
2 changed files with 10 additions and 4 deletions
|
|
@ -727,10 +727,8 @@ class StandardBuiltInToolCostTracking:
|
|||
web_search_options: Optional[WebSearchOptions] = None
|
||||
file_search: Optional[FileSearchTool] = None
|
||||
|
||||
# Check direct web_search_options first
|
||||
web_search_options_dict = kwargs.get("web_search_options")
|
||||
if web_search_options_dict:
|
||||
web_search_options = WebSearchOptions(**web_search_options_dict)
|
||||
if "web_search_options" in kwargs:
|
||||
web_search_options = WebSearchOptions(**kwargs["web_search_options"])
|
||||
|
||||
# Get tools once
|
||||
tools = kwargs.get("tools")
|
||||
|
|
|
|||
|
|
@ -376,3 +376,11 @@ class TestGetBuiltInToolsFromKwargs:
|
|||
# Direct web_search_options should take precedence
|
||||
assert web_search is not None
|
||||
assert web_search.get("search_context_size") == "high"
|
||||
|
||||
def test_empty_web_search_options_dict_returns_web_search_options(self):
|
||||
"""An empty web_search_options dict should still produce WebSearchOptions (use defaults)."""
|
||||
kwargs = {"web_search_options": {}}
|
||||
web_search, file_search = StandardBuiltInToolCostTracking.get_built_in_tools_from_kwargs(kwargs)
|
||||
|
||||
assert web_search is not None
|
||||
assert file_search is None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue