Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
3.0 KiB
3.0 KiB
Advanced Patterns Reference
Table of Contents
- Custom Callbacks
- Custom WebSocket Handler
- LangChain Integration
- Search Restrictions
- Error Handling Patterns
Custom Callbacks
def cost_callback(cost: float):
print(f"API call cost: ${cost}")
researcher = GPTResearcher(query="...")
researcher.add_costs = cost_callback # Override cost tracking
Custom WebSocket Handler
class CustomWebSocket:
def __init__(self):
self.messages = []
async def send_json(self, data):
self.messages.append(data)
if data['type'] == 'logs':
print(f"Progress: {data['output']}")
researcher = GPTResearcher(query="...", websocket=CustomWebSocket())
LangChain Integration
Using with LangChain Documents
from langchain.document_loaders import DirectoryLoader
loader = DirectoryLoader('./docs', glob="**/*.md")
documents = loader.load()
researcher = GPTResearcher(
query="Summarize the documentation",
report_source="langchain_documents",
documents=documents,
)
Using with Vector Store
from langchain.vectorstores import Chroma
vectorstore = Chroma.from_documents(documents, embeddings)
researcher = GPTResearcher(
query="Find relevant information",
report_source="langchain_vectorstore",
vector_store=vectorstore,
vector_store_filter={"source": "docs"},
)
Search Restrictions
Restricting Search Domains
researcher = GPTResearcher(
query="Company news",
query_domains=["reuters.com", "bloomberg.com", "wsj.com"],
)
Using Specific Source URLs
researcher = GPTResearcher(
query="Analyze these articles",
source_urls=[
"https://example.com/article1",
"https://example.com/article2",
],
complement_source_urls=True, # Also do web search
)
Error Handling Patterns
Graceful Degradation
# In skills, always check is_enabled()
async def execute(self, ...):
if not self.is_enabled():
logger.warning("Feature not enabled, skipping")
return [] # Return empty, don't crash
try:
result = await self.provider.execute(...)
return result
except Exception as e:
logger.error(f"Feature error: {e}")
await stream_output("logs", "feature_error", f"⚠️ Error: {e}", self.websocket)
return [] # Graceful degradation
API Rate Limiting
# Providers should handle rate limits
async def execute(self, ...):
try:
return await self._call_api(...)
except RateLimitError as e:
logger.warning(f"Rate limited, waiting...")
await asyncio.sleep(60)
return await self._call_api(...) # Retry
WebSocket None Check
# Always check websocket before sending
if self.researcher.websocket:
await stream_output("logs", "event", "message", self.researcher.websocket)