7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
132 lines
4.0 KiB
Python
132 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple API Client Example - No more CSRF complexity!
|
|
|
|
This shows how easy it is to use the LDR API with the new client.
|
|
All the CSRF token handling is done automatically.
|
|
"""
|
|
|
|
from local_deep_research.api import LDRClient, quick_query
|
|
|
|
# Configuration
|
|
USERNAME = "your_username" # Change this!
|
|
PASSWORD = "your_password" # Change this!
|
|
|
|
|
|
def example_1_simple():
|
|
"""Simplest possible usage - one line research."""
|
|
print("=== Example 1: One-liner ===")
|
|
|
|
# Just one line to get a research summary!
|
|
summary = quick_query(USERNAME, PASSWORD, "What is machine learning?")
|
|
print(f"Summary: {summary[:200]}...")
|
|
|
|
|
|
def example_2_client():
|
|
"""Using the client for multiple operations."""
|
|
print("\n=== Example 2: Client Usage ===")
|
|
|
|
# Create client
|
|
client = LDRClient()
|
|
|
|
# Login once
|
|
if not client.login(USERNAME, PASSWORD):
|
|
print("Login failed!")
|
|
return
|
|
|
|
# Now just use it - no more CSRF hassles!
|
|
try:
|
|
# Do research
|
|
result = client.quick_research("What are neural networks?")
|
|
print("Research complete!")
|
|
print(f"Summary: {result['summary'][:200]}...")
|
|
print(f"Sources found: {len(result.get('sources', []))}")
|
|
|
|
# Check settings
|
|
settings = client.get_settings()
|
|
print(
|
|
f"\nYou have {len(settings.get('settings', {}))} settings configured"
|
|
)
|
|
|
|
# Get history
|
|
history = client.get_history()
|
|
print(f"You have {len(history)} items in history")
|
|
|
|
finally:
|
|
client.logout()
|
|
|
|
|
|
def example_3_context_manager():
|
|
"""Using context manager for automatic cleanup."""
|
|
print("\n=== Example 3: Context Manager ===")
|
|
|
|
# Automatic login/logout with context manager
|
|
with LDRClient() as client:
|
|
if client.login(USERNAME, PASSWORD):
|
|
# Start research without waiting
|
|
result = client.quick_research(
|
|
"What is quantum computing?", wait_for_result=False
|
|
)
|
|
print(f"Research started with ID: {result['research_id']}")
|
|
|
|
# Do other things...
|
|
print("Doing other work while research runs...")
|
|
|
|
# Later, get the results
|
|
final_result = client.wait_for_research(result["research_id"])
|
|
print(f"Research complete: {final_result['summary'][:100]}...")
|
|
|
|
|
|
def example_4_batch_research():
|
|
"""Running multiple research queries efficiently."""
|
|
print("\n=== Example 4: Batch Research ===")
|
|
|
|
questions = [
|
|
"What is DNA?",
|
|
"How do vaccines work?",
|
|
"What causes earthquakes?",
|
|
]
|
|
|
|
with LDRClient() as client:
|
|
if not client.login(USERNAME, PASSWORD):
|
|
print("Login failed!")
|
|
return
|
|
|
|
# Start all research tasks
|
|
research_ids = []
|
|
for question in questions:
|
|
result = client.quick_research(question, wait_for_result=False)
|
|
research_ids.append((question, result["research_id"]))
|
|
print(f"Started: {question}")
|
|
|
|
print("\nWaiting for all results...")
|
|
|
|
# Collect all results
|
|
for question, research_id in research_ids:
|
|
try:
|
|
result = client.wait_for_research(research_id, timeout=120)
|
|
print(f"\n{question}")
|
|
print(f"→ {result['summary'][:150]}...")
|
|
except Exception as e:
|
|
print(f"\n{question}")
|
|
print(f"→ Error: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("LDR Simple Client Examples")
|
|
print("=" * 50)
|
|
print("\nBefore: Complex CSRF handling, HTML parsing, manual polling...")
|
|
print("After: Just login() and quick_research()!")
|
|
print("\nMake sure:")
|
|
print("1. LDR server is running: python -m local_deep_research.web.app")
|
|
print("2. You've updated USERNAME and PASSWORD in this script")
|
|
print("=" * 50)
|
|
|
|
# Uncomment the examples you want to run:
|
|
# example_1_simple()
|
|
# example_2_client()
|
|
# example_3_context_manager()
|
|
# example_4_batch_research()
|
|
|
|
print("\nUncomment the examples in the script to run them!")
|