Skip to content

Commit 1cf02d0

Browse files
Wenxi OnyxWenxi Onyx
authored andcommitted
more mypy
1 parent 6d6add9 commit 1cf02d0

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

backend/onyx/tools/tool_implementations/internet_search/internet_search_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ def __init__(
111111
else CONTEXT_CHUNKS_BELOW
112112
)
113113

114+
# mypy complains about the assignment to self.provider, but it's fine
114115
self.provider = (
115116
get_provider_by_name(provider) if provider else get_default_provider()
116-
)
117+
) # type: ignore[assignment]
117118

118119
if not self.provider:
119120
raise ValueError("No internet search providers are configured")

backend/onyx/tools/tool_implementations/internet_search/providers.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,12 @@ def _search_post(self, query: str, token_budget: int) -> requests.Response:
109109

110110
def _extract_global_field(self, data: dict[str, Any], field_path: list[str]) -> Any:
111111
"""Extract a global field from the API response using a path"""
112-
current_data = data
113-
for path_key in field_path:
114-
try:
115-
if isinstance(current_data, dict):
116-
current_data = current_data.get(path_key)
117-
else:
118-
return None
119-
except Exception as e:
120-
logger.error(f"Error extracting global field: {e}")
112+
current = data
113+
for key in field_path:
114+
if not isinstance(current, dict) or key not in current:
121115
return None
122-
return current_data
116+
current = current[key]
117+
return current
123118

124119
def _extract_field_value(self, source: dict[str, Any], field_key: str) -> str:
125120
"""Safely extract a field value from a source dictionary"""
@@ -130,16 +125,13 @@ def _extract_field_value(self, source: dict[str, Any], field_key: str) -> str:
130125

131126
def _navigate_to_results(self, data: dict[str, Any]) -> list[dict[str, Any]]:
132127
"""Navigate to results list using the configured path"""
133-
current_data = data
134-
135-
for path_key in self.config.results_path:
136-
if not current_data:
137-
logger.error(f"Path '{path_key}' not found in data")
128+
current = data
129+
for key in self.config.results_path:
130+
if not isinstance(current, dict) or key not in current:
138131
return []
139-
current_data = current_data.get(path_key)
132+
current = current[key]
140133

141-
# API responses should return a list of results
142-
return current_data or []
134+
return current if isinstance(current, list) else []
143135

144136
def _extract_results(self, data: dict[str, Any]) -> list[InternetSearchResult]:
145137
"""Extract results from API response based on provider configuration"""

0 commit comments

Comments
 (0)