Skip to main content

langchain-cloro

This package contains the LangChain integration for cloro.dev - a unified API for monitoring multiple AI providers including Google Search, ChatGPT, Gemini, Perplexity, and Microsoft Copilot.

Installation

pip install langchain-cloro

Setup

You'll need a cloro API key. Get one at https://cloro.dev.

Set the API key as an environment variable:

export CLORO_API_KEY="your-api-key-here"

Or pass it directly when initializing:

from langchain_cloro import CloroGoogleSearch

tool = CloroGoogleSearch(cloro_api_key="your-api-key-here")

Available Tools

CloroGoogleSearch

Extract structured data from Google Search results, including organic results, People Also Ask questions, related searches, and optional AI Overview data.

from langchain_cloro import CloroGoogleSearch

tool = CloroGoogleSearch()

# Basic search
results = tool.invoke({"query": "best laptops for programming"})

# With AI Overview
results = tool.invoke({
    "query": "best laptops for programming",
    "include_aioverview": True,
    "aioverview_markdown": True
})

# Multiple pages
results = tool.invoke({
    "query": "python tutorials",
    "pages": 3,
    "country": "US",
    "device": "desktop"
})

Parameters:

  • query (str, required): The search query
  • country (str): ISO 3166-1 alpha-2 country code. Default: "US"
  • device (str): "desktop" or "mobile". Default: "desktop"
  • pages (int): Number of pages to scrape (1-20). Default: 1
  • include_aioverview (bool): Include Google AI Overview. Default: False
  • aioverview_markdown (bool): Format AI Overview as markdown. Default: False
  • include_html (bool): Include raw HTML response. Default: False

CloroChatGPT

Extract structured data from ChatGPT with shopping cards, entity extraction, and advanced features for monitoring products, prices, and brand mentions.

from langchain_cloro import CloroChatGPT

tool = CloroChatGPT()

# Basic query
results = tool.invoke({"prompt": "What are the best sneakers under $100?"})

# With shopping card data
results = tool.invoke({
    "prompt": "best running shoes",
    "include_raw_response": True,
    "include_search_queries": True
})

Parameters:

  • prompt (str, required): The prompt/query
  • country (str): ISO 3166-1 alpha-2 country code. Default: "US"
  • include_raw_response (bool): Include raw streaming response events. Default: False
  • include_search_queries (bool): Include search fan-out queries. Default: False
  • include_html (bool): Include HTML response. Default: False
  • include_markdown (bool): Include markdown response. Default: False

CloroGemini

Extract structured data from Google's Gemini AI with source citations, confidence levels, and multiple output formats.

from langchain_cloro import CloroGemini

tool = CloroGemini()

results = tool.invoke({"prompt": "Explain quantum entanglement"})

Parameters:

  • prompt (str, required): The prompt/query
  • country (str): ISO 3166-1 alpha-2 country code. Default: "US"
  • include_html (bool): Include HTML response. Default: False
  • include_markdown (bool): Include markdown response. Default: False

CloroPerplexity

Extract comprehensive structured data from Perplexity AI with real-time web sources, shopping products, media content, and travel information.

from langchain_cloro import CloroPerplexity

tool = CloroPerplexity()

# Travel query
results = tool.invoke({"prompt": "Best hotels in San Francisco"})

# Shopping query
results = tool.invoke({"prompt": "best noise-cancelling headphones"})

Parameters:

  • prompt (str, required): The prompt/query
  • country (str): ISO 3166-1 alpha-2 country code. Default: "US"
  • include_html (bool): Include HTML response. Default: False
  • include_markdown (bool): Include markdown response. Default: False

CloroCopilot

Extract structured data from Microsoft Copilot with source citations.

from langchain_cloro import CloroCopilot

tool = CloroCopilot()

results = tool.invoke({"prompt": "What is the capital of France?"})

Parameters:

  • prompt (str, required): The prompt/query
  • country (str): ISO 3166-1 alpha-2 country code. Default: "US"
  • include_html (bool): Include HTML response. Default: False
  • include_markdown (bool): Include markdown response. Default: False

get_countries Utility

Get list of supported country codes for specific AI providers.

from langchain_cloro import get_countries

# Get all countries
all_countries = get_countries()

# Get countries for specific model
chatgpt_countries = get_countries(model="chatgpt")
google_countries = get_countries(model="google")

Usage with LangChain Agents

With an Agent

from langchain.agents import initialize_agent, AgentType
from langchain_openai import OpenAI
from langchain_cloro import CloroGoogleSearch, CloroChatGPT

llm = OpenAI(temperature=0)
tools = [CloroGoogleSearch(), CloroChatGPT()]

agent = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

agent.run("What are the latest developments in AI?")

With LCEL

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI
from langchain_cloro import CloroChatGPT

chatgpt = CloroChatGPT()

prompt = ChatPromptTemplate.from_messages([
    ("system", "Answer based on the AI's response:\n\n{response}"),
    ("user", "{question}")
])

chain = {
    "response": lambda x: chatgpt.invoke({"prompt": x["question"]}),
    "question": lambda x: x["question"]
} | prompt | ChatOpenAI() | StrOutputParser()

response = chain.invoke({"question": "What is LangChain?"})
print(response)

Multiple Tools Example

from langchain_cloro import (
    CloroGoogleSearch,
    CloroChatGPT,
    CloroGemini,
    CloroPerplexity,
    CloroCopilot
)

tools = [
    CloroGoogleSearch(),  # For search queries
    CloroChatGPT(),      # For shopping/product queries
    CloroGemini(),       # For general AI queries
    CloroPerplexity(),   # For research with citations
    CloroCopilot(),      # For general queries
]

Supported Country Codes

Use the get_countries() utility to fetch supported countries:

from langchain_cloro import get_countries

# Check which countries are available for each model
models = ["google", "chatgpt", "gemini", "perplexity", "copilot"]

for model in models:
    countries = get_countries(model=model)
    print(f"{model}: {len(countries)} countries")

Development

Running Tests

# Unit tests
pytest tests/unit_tests -v

# Linting
ruff check .
ruff format .

# Type checking
mypy langchain_cloro

API Reference

For detailed API documentation, see https://cloro.dev/docs.

License

MIT

Metadata

Release files for langchain-cloro 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-cloro 0.3.0
File Size Uploaded
langchain_cloro-0.3.0.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-cloro 0.3.0
File Interpreter ABI Platform
langchain_cloro-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / langchain_cloro-0.3.0.tar.gz

Download URL langchain_cloro-0.3.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b4b6d2615cdb2769188b7e64dab447125f1901e043d5b10dd1f1ec444a63bac3
BLAKE2b-256 checksum
How to use checksums
efed8c4c981214504861ca1845d46b46bd7abf7a4b8a0a31d26c3029a2d64362
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / langchain_cloro-0.3.0-py3-none-any.whl

Download URL langchain_cloro-0.3.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66b509aa884312643fb3620b8eadefccdd6d8a2d9d92dd6d816c3839d6e9962f
BLAKE2b-256 checksum
How to use checksums
3272e725a36bd49ee8e55aa6d1ff829325b2ed1c21904a175a0fd65116d18cb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page