mirror of
https://github.com/LearningCircuit/local-deep-research.git
synced 2026-06-16 12:02:34 +03:00
- Fix Ollama API key NoSettingsContextError by using empty string default - Add ui_element fallback in thread_settings to handle custom overrides - Pass settings_snapshot to file_write_verifier for programmatic mode - Auto-detect ui_element type in settings_utils (checkbox/number/json) - Add api.allow_file_output to programmatic examples - Add programmatic API tests to api-tests.yml workflow These fixes enable the programmatic API to work correctly without database access, as intended for programmatic usage scenarios.
87 lines
2.8 KiB
Python
Executable File
87 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,
|
|
generate_report,
|
|
)
|
|
from local_deep_research.api.settings_utils import (
|
|
create_settings_snapshot,
|
|
)
|
|
|
|
# Use default settings with minimal overrides
|
|
# This provides all necessary settings with sensible defaults
|
|
settings_snapshot = create_settings_snapshot(
|
|
overrides={
|
|
"search.tool": "wikipedia", # Use Wikipedia for this example
|
|
"api.allow_file_output": True, # Allow generate_report to save files
|
|
}
|
|
)
|
|
|
|
# Alternative: Use completely default settings
|
|
# settings_snapshot = get_default_settings_snapshot()
|
|
|
|
# Example 1: Quick Summary
|
|
print("=== Quick Summary ===")
|
|
result = quick_summary(
|
|
"What is machine learning?",
|
|
settings_snapshot=settings_snapshot,
|
|
programmatic_mode=True,
|
|
)
|
|
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,
|
|
programmatic_mode=True,
|
|
)
|
|
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,
|
|
programmatic_mode=True,
|
|
)
|
|
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 ===")
|
|
print("Note: Report generation can take several minutes")
|
|
|
|
# Generate a comprehensive 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,
|
|
settings_snapshot=settings_snapshot, # Now works with programmatic mode!
|
|
)
|
|
print(f"Report saved to: {report.get('file_path', 'ai_future_report.md')}")
|
|
print(f"Report length: {len(report['content'])} characters")
|
|
print("Report preview (first 300 chars):")
|
|
print(report["content"][:300] + "...")
|