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:
parent
725a256285
commit
8fb19add81
1 changed files with 4 additions and 4 deletions
|
|
@ -56,17 +56,17 @@ class SerpAPIComponent(LCToolComponent):
|
||||||
return SerpAPIWrapper(serpapi_api_key=self.serpapi_api_key)
|
return SerpAPIWrapper(serpapi_api_key=self.serpapi_api_key)
|
||||||
|
|
||||||
def build_tool(self) -> Tool:
|
def build_tool(self) -> Tool:
|
||||||
wrapper = self._build_wrapper(self.search_params) # noqa: F841
|
wrapper = self._build_wrapper(self.search_params)
|
||||||
|
|
||||||
def search_func(
|
def search_func(
|
||||||
query: str, params: dict[str, Any] | None = None, max_results: int = 5, max_snippet_length: int = 100
|
query: str, params: dict[str, Any] | None = None, max_results: int = 5, max_snippet_length: int = 100
|
||||||
) -> list[dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
try:
|
try:
|
||||||
# rebuild the wrapper if params are provided
|
local_wrapper = wrapper
|
||||||
if params:
|
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]
|
organic_results = full_results.get("organic_results", [])[:max_results]
|
||||||
|
|
||||||
limited_results = []
|
limited_results = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue