以编程方式使用文档

>Parallel 是一个为 LLM 和 AI 应用构建的实时网络搜索和内容提取平台。

ParallelFindAllTool 调用 Parallel 的 FindAll API 进行实体发现。给定一个自然语言目标和一组布尔匹配条件,它返回满足所有条件的排名候选。

概述

集成详情

可序列化JS 支持包最新版本
ParallelFindAllToollangchain-parallel<a href="https://pypi.org/project/langchain-parallel/" target="_blank"><img src="https://img.shields.io/pypi/v/langchain-parallel?style=flat-square&label=%20&color=orange" alt="PyPI - Latest version" noZoom height="100" class="rounded" /></a>

设置

集成位于 langchain-parallel package.

    pip install -U langchain-parallel
    
    uv add langchain-parallel
    

凭证

前往 Parallel 注册并生成 API 密钥。设置 PARALLEL_API_KEY 在您的环境中:

if not os.environ.get("PARALLEL_API_KEY"):
    os.environ["PARALLEL_API_KEY"] = getpass.getpass("Parallel API key:\n")

实例化

generator 是一个工具级设置。使用 "preview" (免费,最多 10 个候选)用于快速迭代;切换到 "base" (默认), "core", or "pro" 以获得更高质量的运行。

from langchain_parallel import ParallelFindAllTool

tool = ParallelFindAllTool(generator="preview")

调用

快速发现(预览生成器)

这个 preview 生成器在几秒内返回,最多限制为 10 个候选。 match_limit 是必需的;对于 preview 它必须在 [5, 10].

from langchain_parallel import FindAllMatchCondition

result = await tool.ainvoke({
    "objective": "Pure-play public LLM API providers",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="public_us",
            description="Company is publicly traded on a US exchange",
        ),
        FindAllMatchCondition(
            name="llm_api_revenue",
            description="Primary revenue is selling LLM inference via API",
        ),
    ],
    "match_limit": 5,
})

for c in result["candidates"]:
    print(c["name"], "—", c["url"])
Anthropic — https://www.anthropic.com
OpenAI — https://www.openai.com
...

更高质量的运行

切换到 "base", "core", or "pro" 以获取 match_limit 最多 1000 个。这需要几分钟;该工具会持续轮询直到运行达到终止状态(completed, cancelled, or failed).

deep = ParallelFindAllTool(generator="core")

result = await deep.ainvoke({
    "objective": "Independent solar-installer companies based in the EU",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="eu_hq",
            description="Headquartered in an EU country",
        ),
        FindAllMatchCondition(
            name="residential_solar_pv",
            description="Primarily installs residential solar PV",
        ),
    ],
    "match_limit": 50,
})

排除已见过的候选

传入 exclude_list=[FindAllExcludeEntry(name=..., url=...)] 以丢弃您已处理的候选。 nameurl 都是必需的。

from langchain_parallel import FindAllExcludeEntry

result = await tool.ainvoke({
    "objective": "Pure-play public LLM API providers",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="llm_api_revenue",
            description="Primary revenue is selling LLM inference via API",
        ),
    ],
    "match_limit": 5,
    "exclude_list": [
        FindAllExcludeEntry(name="OpenAI", url="https://www.openai.com"),
        FindAllExcludeEntry(name="Anthropic", url="https://www.anthropic.com"),
    ],
})

取消

cancel() 通过 id 中止正在运行的任务。该 id 会返回给启动运行的主叫方;如果您使用 tool.ainvoke(...) 在长时间运行的任务中,请在等待完成前捕获 findall_id 从该运行中。

# from another task / handler:
tool.cancel(findall_id)        # sync
await tool.acancel(findall_id) # async

参数

必需

  • - objective:要查找内容的自然语言描述。
  • - entity_type:描述候选类的简短名词("company", "researcher", "product"等)。
  • - match_conditions:列表 FindAllMatchCondition(name=..., description=...)。每个都需要这两个字段。
  • - match_limit:整数,范围为 [5, 1000]preview 生成器进一步限制为 10。

可选

  • - exclude_list:要跳过的 FindAllExcludeEntry(name=..., url=...) 列表。
  • - webhook: FindAllWebhook(url=..., event_types=[...]) to receive run/candidate events.
  • - metadata:持久化在运行上的自由格式元数据。
  • - timeout:轮询超时时间(默认 600 秒)。

链式调用

将工具绑定到任何支持工具调用的聊天模型,并驱动一个代理 create_agent:

from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

llm = init_chat_model(model="claude-haiku-4-5", model_provider="anthropic")
agent = create_agent(model=llm, tools=[tool])

agent.invoke({"messages": [("human", "Find me a few independent EU solar installers.")]})

响应格式

{
    "candidates": [
        {
            "candidate_id": "cand_abc",
            "name": "Acme Solar",
            "url": "https://acmesolar.example",
            "description": "...",
            "match_status": "matched",  # or "generated" / "unmatched"
            "output": {
                "<condition_name>": {
                    "type": "match_condition",
                    "value": True,
                    "is_matched": True,
                },
            },
            "basis": [...],  # citations + reasoning per output field
        },
    ],
    "run": {...},          # status info
    "last_event_id": "...",
}

API 参考文档

要获取详细文档,请访问 ParallelFindAllTool API 参考文档或 并行 FindAll API 指南.