Skip to main content

An integration package connecting Cloro.dev and LangChain

Project description

langchain-cloro

This package contains the LangChain integration for Cloro.dev.

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 CloroSearchRun

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

Usage

With an Agent

from langchain.agents import initialize_agent, AgentType
from langchain_openai import OpenAI
from langchain_cloro import CloroSearchRun

llm = OpenAI(temperature=0)
search = CloroSearchRun()

agent = initialize_agent(
    [search],
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

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

Direct Tool Usage

from langchain_cloro import CloroSearchRun

tool = CloroSearchRun()

# Simple search
results = tool.invoke({"query": "Python programming tips"})

# Search with custom parameters
results = tool.invoke({
    "query": "machine learning tutorials",
    "num_results": 5,
})

With LCEL

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

search = CloroSearchRun()

prompt = ChatPromptTemplate.from_messages([
    ("system", "Answer the question based on the search results:\n\n{results}"),
    ("user", "{question}")
])

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

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

API Reference

CloroSearchRun

Main search tool for Cloro.dev API.

Parameters:

  • cloro_api_key (str, optional): Cloro API key. Defaults to CLORO_API_KEY environment variable.
  • timeout (float, optional): Request timeout in seconds. Defaults to 10.0.

Methods:

_run

Execute a search query.

_run(
    query: str,
    num_results: int = 10,
    **kwargs: dict
) -> str

Parameters:

  • query (str): The search query string.
  • num_results (int): Number of results to return. Default: 10.
  • **kwargs: Additional search parameters to pass to the Cloro API.

Returns:

  • str: JSON string of search results.

Development

Running Tests

# Unit tests
pytest tests/unit_tests

# Linting
ruff check .
ruff format .

Contributing

This package follows LangChain's contribution guidelines. See:

License

MIT

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_cloro-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_cloro-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_cloro-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_cloro-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for langchain_cloro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 109f220ab57e599417068c02d1dd4ed7b8b4665ed25ae9f3262d6cfc84d74724
MD5 99e2f6fdc6b41b03e5d0cfbccd64b404
BLAKE2b-256 d7d9fdbe7cff93ea44a20f1994eb5e5471f536ff4badcebf551fe7faf66c466f

See more details on using hashes here.

File details

Details for the file langchain_cloro-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_cloro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 374c3988cc96511921cc6825d212e5adb69afdbd1dd5b7c485dca5aaccf87f0c
MD5 c1612916921352783afd40f9695e30a1
BLAKE2b-256 5529766737aaa8117d78c534da6a77927efa5d68d2bab68e572d8c36fa9318ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page