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).
116 lines
3.7 KiB
Python
116 lines
3.7 KiB
Python
"""Browser manager skill for GPT Researcher.
|
|
|
|
This module provides the BrowserManager class that handles web scraping
|
|
and content extraction from URLs.
|
|
"""
|
|
|
|
from gpt_researcher.utils.workers import WorkerPool
|
|
|
|
from ..actions.utils import stream_output
|
|
from ..actions.web_scraping import scrape_urls
|
|
from ..scraper.utils import get_image_hash
|
|
|
|
|
|
class BrowserManager:
|
|
"""Manages web browsing and content scraping for research.
|
|
|
|
This class handles URL scraping, content extraction, and image
|
|
selection during the research process.
|
|
|
|
Attributes:
|
|
researcher: The parent GPTResearcher instance.
|
|
worker_pool: Pool of workers for parallel scraping.
|
|
"""
|
|
|
|
def __init__(self, researcher):
|
|
"""Initialize the BrowserManager.
|
|
|
|
Args:
|
|
researcher: The GPTResearcher instance that owns this manager.
|
|
"""
|
|
self.researcher = researcher
|
|
self.worker_pool = WorkerPool(
|
|
researcher.cfg.max_scraper_workers,
|
|
researcher.cfg.scraper_rate_limit_delay
|
|
)
|
|
|
|
async def browse_urls(self, urls: list[str]) -> list[dict]:
|
|
"""
|
|
Scrape content from a list of URLs.
|
|
|
|
Args:
|
|
urls (list[str]): list of URLs to scrape.
|
|
|
|
Returns:
|
|
list[dict]: list of scraped content results.
|
|
"""
|
|
if self.researcher.verbose:
|
|
await stream_output(
|
|
"logs",
|
|
"scraping_urls",
|
|
f"๐ Scraping content from {len(urls)} URLs...",
|
|
self.researcher.websocket,
|
|
)
|
|
|
|
scraped_content, images = await scrape_urls(
|
|
urls, self.researcher.cfg, self.worker_pool
|
|
)
|
|
self.researcher.add_research_sources(scraped_content)
|
|
new_images = self.select_top_images(images, k=4) # Select top 4 images
|
|
self.researcher.add_research_images(new_images)
|
|
|
|
if self.researcher.verbose:
|
|
await stream_output(
|
|
"logs",
|
|
"scraping_content",
|
|
f"๐ Scraped {len(scraped_content)} pages of content",
|
|
self.researcher.websocket,
|
|
)
|
|
await stream_output(
|
|
"logs",
|
|
"scraping_images",
|
|
f"๐ผ๏ธ Selected {len(new_images)} new images from {len(images)} total images",
|
|
self.researcher.websocket,
|
|
True,
|
|
new_images,
|
|
)
|
|
await stream_output(
|
|
"logs",
|
|
"scraping_complete",
|
|
f"๐ Scraping complete",
|
|
self.researcher.websocket,
|
|
)
|
|
|
|
return scraped_content
|
|
|
|
def select_top_images(self, images: list[dict], k: int = 2) -> list[str]:
|
|
"""
|
|
Select most relevant images and remove duplicates based on image content.
|
|
|
|
Args:
|
|
images (list[dict]): list of image dictionaries with 'url' and 'score' keys.
|
|
k (int): Number of top images to select if no high-score images are found.
|
|
|
|
Returns:
|
|
list[str]: list of selected image URLs.
|
|
"""
|
|
unique_images = []
|
|
seen_hashes = set()
|
|
current_research_images = self.researcher.get_research_images()
|
|
|
|
# Process images in descending order of their scores
|
|
for img in sorted(images, key=lambda im: im["score"], reverse=True):
|
|
img_hash = get_image_hash(img['url'])
|
|
if (
|
|
img_hash
|
|
and img_hash not in seen_hashes
|
|
and img['url'] not in current_research_images
|
|
):
|
|
seen_hashes.add(img_hash)
|
|
unique_images.append(img["url"])
|
|
|
|
if len(unique_images) == k:
|
|
break
|
|
|
|
return unique_images
|