Home / Class/ PerplexitySearchResults Class — langchain Architecture

PerplexitySearchResults Class — langchain Architecture

Architecture documentation for the PerplexitySearchResults class in tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6c2656e8_9201_6f51_c168_6eba5bcbee8c["PerplexitySearchResults"]
  5ebe56ae_0ac8_cb13_b5a9_ee567b924009["BaseTool"]
  6c2656e8_9201_6f51_c168_6eba5bcbee8c -->|extends| 5ebe56ae_0ac8_cb13_b5a9_ee567b924009
  1a67c21d_2ec3_4b16_a500_a33a7c94b43e["tools.py"]
  6c2656e8_9201_6f51_c168_6eba5bcbee8c -->|defined in| 1a67c21d_2ec3_4b16_a500_a33a7c94b43e
  f6f2d283_eb05_3dda_54b2_27fd70a970dc["validate_environment()"]
  6c2656e8_9201_6f51_c168_6eba5bcbee8c -->|method| f6f2d283_eb05_3dda_54b2_27fd70a970dc
  d0b5e159_6e0c_c039_08ab_2a5f29c4d74e["_run()"]
  6c2656e8_9201_6f51_c168_6eba5bcbee8c -->|method| d0b5e159_6e0c_c039_08ab_2a5f29c4d74e

Relationship Graph

Source Code

libs/partners/perplexity/langchain_perplexity/tools.py lines 12–66

class PerplexitySearchResults(BaseTool):
    """Perplexity Search tool."""

    name: str = "perplexity_search_results_json"
    description: str = (
        "A wrapper around Perplexity Search. "
        "Input should be a search query. "
        "Output is a JSON array of the query results"
    )
    client: Any = Field(default=None, exclude=True)
    pplx_api_key: SecretStr = Field(default=SecretStr(""))

    @model_validator(mode="before")
    @classmethod
    def validate_environment(cls, values: dict) -> Any:
        """Validate the environment."""
        return initialize_client(values)

    def _run(
        self,
        query: str | list[str],
        max_results: int = 10,
        country: str | None = None,
        search_domain_filter: list[str] | None = None,
        search_recency_filter: Literal["day", "week", "month", "year"] | None = None,
        search_after_date: str | None = None,
        search_before_date: str | None = None,
        run_manager: CallbackManagerForToolRun | None = None,
    ) -> list[dict] | str:
        """Use the tool."""
        try:
            params = {
                "query": query,
                "max_results": max_results,
                "country": country,
                "search_domain_filter": search_domain_filter,
                "search_recency_filter": search_recency_filter,
                "search_after_date": search_after_date,
                "search_before_date": search_before_date,
            }
            params = {k: v for k, v in params.items() if v is not None}
            response = self.client.search.create(**params)
            return [
                {
                    "title": result.title,
                    "url": result.url,
                    "snippet": result.snippet,
                    "date": result.date,
                    "last_updated": result.last_updated,
                }
                for result in response.results
            ]
        except Exception as e:
            msg = f"Perplexity search failed: {type(e).__name__}"
            return msg

Extends

Frequently Asked Questions

What is the PerplexitySearchResults class?
PerplexitySearchResults is a class in the langchain codebase, defined in libs/partners/perplexity/langchain_perplexity/tools.py.
Where is PerplexitySearchResults defined?
PerplexitySearchResults is defined in libs/partners/perplexity/langchain_perplexity/tools.py at line 12.
What does PerplexitySearchResults extend?
PerplexitySearchResults extends BaseTool.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free