fix: Error in SerpAPI search: cannot access local variable 'wrapper' where it is not associated with a value (#4758)

Update serp_api.py

fixes:  Error: Error in SerpAPI search: cannot access local variable 'wrapper' where it is not associated with a value
This commit is contained in:
Edwin Jose 2024-11-21 19:44:14 -05:00 committed by GitHub
commit 8fb19add81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,17 +56,17 @@ class SerpAPIComponent(LCToolComponent):
return SerpAPIWrapper(serpapi_api_key=self.serpapi_api_key)
def build_tool(self) -> Tool:
wrapper = self._build_wrapper(self.search_params) # noqa: F841
wrapper = self._build_wrapper(self.search_params)
def search_func(
query: str, params: dict[str, Any] | None = None, max_results: int = 5, max_snippet_length: int = 100
) -> list[dict[str, Any]]:
try:
# rebuild the wrapper if params are provided
local_wrapper = wrapper
if params:
wrapper = self._build_wrapper(params)
local_wrapper = self._build_wrapper(params)
full_results = wrapper.results(query)
full_results = local_wrapper.results(query)
organic_results = full_results.get("organic_results", [])[:max_results]
limited_results = []