mirror of
https://github.com/LearningCircuit/local-deep-research.git
synced 2026-06-16 20:10:39 +03:00
- Add required settings_snapshot with all necessary LLM and search settings - Pass settings_snapshot to all API function calls - Example now runs without crashing (though returns empty results in programmatic mode) - Preserves original example structure and API usage patterns
84 lines
2.8 KiB
Python
Executable File
84 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Simple Programmatic API Example for Local Deep Research
|
|
|
|
Quick example showing how to use the LDR Python API directly.
|
|
"""
|
|
|
|
from local_deep_research.api import detailed_research, quick_summary
|
|
|
|
# Create a minimal settings snapshot for programmatic mode
|
|
# You need to specify at least the LLM settings for programmatic mode
|
|
settings_snapshot = {
|
|
"programmatic_mode": True,
|
|
# LLM settings
|
|
"llm.provider": "ollama", # or "openai_endpoint", "openai", etc.
|
|
"llm.model": "gemma3:12b", # or your preferred model
|
|
"llm.temperature": 0.7,
|
|
"llm.local_context_window_size": 8192,
|
|
"llm.max_tokens": 4096,
|
|
"llm.supports_max_tokens": True,
|
|
# Search settings
|
|
"search.tool": "wikipedia", # default search tool
|
|
"search.max_results": 10,
|
|
"search.region": "wt-wt",
|
|
"search.time_period": "all",
|
|
"search.safe_search": True,
|
|
"search.snippets_only": True,
|
|
"search.search_language": "English",
|
|
"search.max_filtered_results": 5,
|
|
}
|
|
|
|
# Example 1: Quick Summary
|
|
print("=== Quick Summary ===")
|
|
result = quick_summary(
|
|
"What is machine learning?", settings_snapshot=settings_snapshot
|
|
)
|
|
print(f"Summary: {result['summary'][:300]}...")
|
|
print(f"Found {len(result.get('findings', []))} findings")
|
|
|
|
# Example 2: Detailed Research with Custom Parameters
|
|
print("\n=== Detailed Research ===")
|
|
result = detailed_research(
|
|
query="Impact of climate change on agriculture",
|
|
iterations=2,
|
|
search_tool="wikipedia",
|
|
search_strategy="source_based",
|
|
settings_snapshot=settings_snapshot,
|
|
)
|
|
print(f"Research ID: {result['research_id']}")
|
|
print(f"Summary length: {len(result['summary'])} characters")
|
|
print(f"Sources: {len(result.get('sources', []))}")
|
|
|
|
# Example 3: Using Custom Search Parameters
|
|
print("\n=== Custom Search Parameters ===")
|
|
result = quick_summary(
|
|
query="renewable energy trends 2024",
|
|
search_tool="auto", # Auto-select best search engine
|
|
iterations=1,
|
|
questions_per_iteration=3,
|
|
temperature=0.5, # Lower temperature for focused results
|
|
provider="openai_endpoint", # Specify LLM provider
|
|
model_name="llama-3.3-70b-instruct", # Specify model
|
|
settings_snapshot=settings_snapshot,
|
|
)
|
|
print(f"Completed {result['iterations']} iterations")
|
|
print(
|
|
f"Generated {sum(len(qs) for qs in result.get('questions', {}).values())} questions"
|
|
)
|
|
|
|
# Example 4: Generate and Save a Report
|
|
print("\n=== Generate Report (Optional - Uncomment to run) ===")
|
|
print("Note: Report generation can take several minutes")
|
|
# Uncomment the following to generate a full report:
|
|
"""
|
|
report = generate_report(
|
|
query="Future of artificial intelligence",
|
|
output_file="ai_future_report.md", # Save directly to file
|
|
searches_per_section=2,
|
|
iterations=1
|
|
)
|
|
print(f"Report saved to: {report.get('file_path', 'ai_future_report.md')}")
|
|
print(f"Report length: {len(report['content'])} characters")
|
|
"""
|