google.py

Overview

google.py is a utility component designed to perform Google searches via the SerpApi service. It provides a structured interface for querying Google's search engine, retrieving organic search results, and formatting these results for further use within the InfiniFlow system. The component encapsulates parameter validation, request execution with retry and timeout logic, and result extraction.

The file defines two main classes:

This component enables the InfiniFlow agents or tools to integrate Google search capabilities seamlessly, supporting configurable search queries, result pagination, and localization options such as country and language.


Classes and Methods

Class: GoogleParam

Defines the configurable parameters for the Google search tool and validates them.

Attributes

Methods

Usage Example

param = GoogleParam()
param.api_key = "your_serpapi_key"
param.country = "us"
param.language = "en"
param.start = 0
param.num = 10
param.check()  # Raises error if invalid

input_form = param.get_input_form()
print(input_form)

Class: Google (inherits ToolBase, ABC)

Implements the Google search tool's core functionality, including request invocation, result retrieval, and error handling.

Class Attributes

Methods

Implementation Details

Usage Example

google_tool = Google()
google_tool._param.api_key = "your_serpapi_key"
google_tool._param.country = "us"
google_tool._param.language = "en"
google_tool._param.max_retries = 2
google_tool._param.delay_after_error = 1

result = google_tool._invoke(q="OpenAI GPT-4 capabilities")
print(result)

Important Implementation Details and Algorithms


Interaction with Other System Components


Mermaid Diagram

The following class diagram illustrates the structure and main methods of the classes defined in google.py:

classDiagram
    class GoogleParam {
        +meta: ToolMeta
        +start: int
        +num: int
        +api_key: str
        +country: str
        +language: str
        +__init__()
        +check()
        +get_input_form() dict
    }

    class Google {
        +component_name: str = "Google"
        +_invoke(**kwargs) str
        +thoughts() str
    }

    GoogleParam <|-- GoogleParamBase
    Google --> ToolBase
    Google --> ABC

Summary

The google.py file implements a specialized tool within the InfiniFlow system to perform Google web searches using the SerpApi service. It provides parameter encapsulation and validation (GoogleParam), search execution with retry and timeout handling (Google), and result extraction for integration with downstream components. This modular design supports flexible and localized Google search queries within larger AI agent workflows.