# 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}")