Add OpenRouter support and improve JSON parsing robustness
- Add OpenRouter as third LLM provider option in config.py - Implement _extract_json() to handle markdown-wrapped JSON responses - Add default values for missing required fields in ScriptPlan - Handle navigation_strategy as list or string - Add .env.example with configuration templates - Add test script and sample generated scrapers for RWTH and KAUST 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
45
test_rwth.py
Normal file
45
test_rwth.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
"""Test script to run the agent for RWTH Aachen University."""
|
||||
import os
|
||||
|
||||
# Configure OpenRouter - set OPENROUTER_API_KEY environment variable
|
||||
import winreg
|
||||
|
||||
def get_user_env(name):
|
||||
"""Get user environment variable on Windows."""
|
||||
try:
|
||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Environment") as key:
|
||||
return winreg.QueryValueEx(key, name)[0]
|
||||
except Exception:
|
||||
return os.environ.get(name)
|
||||
|
||||
openrouter_key = get_user_env("OPENROUTER_API_KEY")
|
||||
if not openrouter_key:
|
||||
raise ValueError("Please set OPENROUTER_API_KEY environment variable")
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = openrouter_key
|
||||
os.environ["CODEGEN_MODEL_PROVIDER"] = "openrouter"
|
||||
os.environ["CODEGEN_OPENROUTER_MODEL"] = "anthropic/claude-3-opus"
|
||||
|
||||
print("Using OpenRouter with Claude 3 Opus")
|
||||
|
||||
# Run the agent
|
||||
from university_agent import GenerationEngine, GenerationRequest, Settings
|
||||
|
||||
settings = Settings()
|
||||
print(f"Provider: {settings.model_provider}")
|
||||
print(f"Model: {settings.openrouter_model}")
|
||||
|
||||
engine = GenerationEngine(settings)
|
||||
request = GenerationRequest(
|
||||
target_url="https://www.kaust.edu.sa/en/",
|
||||
campus_name="KAUST",
|
||||
assumed_language="English",
|
||||
max_depth=3,
|
||||
max_pages=30,
|
||||
)
|
||||
|
||||
print("Starting generation for KAUST...")
|
||||
result = engine.generate(request, capture_snapshot=True)
|
||||
print(f"Script saved to: {result.script_path}")
|
||||
print(f"Project slug: {result.plan.project_slug}")
|
||||
Reference in New Issue
Block a user