跳到主要内容
Perigon 是一个综合性的新闻 API,提供对全球数千个来源的新闻文章、故事、元数据和维基百科页面中实时上下文信息的访问。

安装和设置

Perigon 集成存在于其独立的合作伙伴包中。您可以使用以下命令安装它:
pip install -qU langchain-perigon
为了使用该包,您还需要将 PERIGON_API_KEY 环境变量设置为您的 Perigon API 密钥。

检索器

Perigon 提供两种检索器:

文章检索器 (ArticlesRetriever)

此检索器根据给定查询和可选过滤器检索文章。 请参阅完整用法示例
# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key
from langchain_perigon import ArticlesRetriever, ArticlesFilter

# Create retriever with specific number of results
retriever = ArticlesRetriever(k=12)

# Configure filter options to exclude reprints and focus on US articles
options: ArticlesFilter = {
    "showReprints": False,  # Exclude duplicate/reprint articles
    "filter": {"country": "us"},  # Only US-based news
}

try:
    documents = retriever.invoke("Recent big tech layoffs", options=options)

    # Check if we got results before accessing
    if documents:
        print(f"First document: {documents[0].page_content[:200]}...")
    else:
        print("No articles found for the given query.")
except Exception as e:
    print(f"Error retrieving articles: {e}")
您可以在标准检索管道中使用 ArticlesRetriever

维基百科检索器 (WikipediaRetriever)

此检索器根据给定查询和可选过滤器检索维基百科页面。 请参阅完整用法示例
# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key
from langchain_perigon import WikipediaRetriever

# Create retriever with specific number of results
retriever = WikipediaRetriever(k=12)

try:
    documents = retriever.invoke("machine learning")

    # Safely access results with error handling
    if documents:
        print(f"First document: {documents[0].page_content[:200]}...")
    else:
        print("No Wikipedia articles found for the given query.")
except Exception as e:
    print(f"Error retrieving Wikipedia articles: {e}")
您可以在标准检索管道中使用 WikipediaRetriever
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.