refactor(google_search): migrate to new tool mode implementation (#5444)

* ## refactor(google_search): migrate to new tool mode implementation

- Replace legacy tool mode using LCToolComponent with new Component class and tool_mode flag.

- Update input/output definitions to use new DataFrame type and explicit Output configuration.

Key changes:
- Migrate from LCToolComponent to Component base class
- Add explicit output configuration with DataFrame type
- Update error handling to return structured DataFrame responses
- Implement tool_mode using new flag syntax

* test(google-search): add unit tests for GoogleSearchAPIComponent

* fix(google-search): adjust DataFrame format to match expected type

- Update error responses to use list[dict] format instead of dict[list]

* [autofix.ci] apply automated fixes

* revert(tools): restore GoogleSearchAPI component to its original implementation

Due to potential breaking changes in the repository, reverting the GoogleSearchAPI
component to its initial state to maintain compatibility and stability.

* refactor(tools): mark GoogleSearchAPI component as deprecated

Mark GoogleSearchAPI component as legacy and add [DEPRECATED] to its display name
to better communicate its status to users while maintaining backward compatibility.

* feat: add Google Search API core component

Implements Google Search API wrapper with error handling and DataFrame output

* test: update Google Search API tests for core component

Adjusts test file to use GoogleSearchAPICore instead of GoogleSearchAPIComponent

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
This commit is contained in:
VICTOR CORREA GOMES 2025-01-17 21:14:38 -03:00 • committed by GitHub
commit 7c04245ea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 185 additions and 1 deletions

View file

@ -9,6 +9,7 @@ from .duck_duck_go_search_run import DuckDuckGoSearchComponent
from .exa_search import ExaSearchToolkit
from .glean_search_api import GleanSearchAPIComponent
from .google_search_api import GoogleSearchAPIComponent
from .google_search_api_core import GoogleSearchAPICore
from .google_serper_api import GoogleSerperAPIComponent
from .mcp_stdio import MCPStdio
from .python_code_structured_tool import PythonCodeStructuredTool
@ -39,6 +40,7 @@ __all__ = [
"ExaSearchToolkit",
"GleanSearchAPIComponent",
"GoogleSearchAPIComponent",
"GoogleSearchAPICore",
"GoogleSerperAPIComponent",
"MCPStdio",
"PythonCodeStructuredTool",

View file

@ -6,10 +6,11 @@ from langflow.schema import Data
class GoogleSearchAPIComponent(LCToolComponent):
display_name = "Google Search API"
display_name = "Google Search API [DEPRECATED]"
description = "Call Google Search API."
name = "GoogleSearchAPI"
icon = "Google"
legacy = True
inputs = [
SecretStrInput(name="google_api_key", display_name="Google API Key", required=True),
SecretStrInput(name="google_cse_id", display_name="Google CSE ID", required=True),

View file

@ -0,0 +1,68 @@
from langchain_google_community import GoogleSearchAPIWrapper
from langflow.custom import Component
from langflow.io import IntInput, MultilineInput, Output, SecretStrInput
from langflow.schema import DataFrame
class GoogleSearchAPICore(Component):
display_name = "Google Search API"
description = "Call Google Search API and return results as a DataFrame."
icon = "Google"
inputs = [
SecretStrInput(
name="google_api_key",
display_name="Google API Key",
required=True,
),
SecretStrInput(
name="google_cse_id",
display_name="Google CSE ID",
required=True,
),
MultilineInput(
name="input_value",
display_name="Input",
tool_mode=True,
),
IntInput(
name="k",
display_name="Number of results",
value=4,
required=True,
),
]
outputs = [
Output(
display_name="Results",
name="results",
type_=DataFrame,
method="search_google",
),
]
def search_google(self) -> DataFrame:
"""Search Google using the provided query."""
if not self.google_api_key:
return DataFrame([{"error": "Invalid Google API Key"}])
if not self.google_cse_id:
return DataFrame([{"error": "Invalid Google CSE ID"}])
try:
wrapper = GoogleSearchAPIWrapper(
google_api_key=self.google_api_key, google_cse_id=self.google_cse_id, k=self.k
)
results = wrapper.results(query=self.input_value, num_results=self.k)
return DataFrame(results)
except (ValueError, KeyError) as e:
return DataFrame([{"error": f"Invalid configuration: {e!s}"}])
except ConnectionError as e:
return DataFrame([{"error": f"Connection error: {e!s}"}])
except RuntimeError as e:
return DataFrame([{"error": f"Error occurred while searching: {e!s}"}])
def build(self):
return self.search_google