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).
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
from collections.abc import AsyncIterator
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import httpx_aiohttp
|
|
import litellm.llms.custom_httpx.aiohttp_transport
|
|
import pytest
|
|
import vcr.stubs.httpcore_stubs
|
|
from lmi.utils import (
|
|
ANTHROPIC_API_KEY_HEADER,
|
|
CROSSREF_KEY_HEADER,
|
|
OPENAI_API_KEY_HEADER,
|
|
SEMANTIC_SCHOLAR_KEY_HEADER,
|
|
)
|
|
|
|
TESTS_DIR = Path(__file__).parent
|
|
CASSETTES_DIR = TESTS_DIR / "cassettes"
|
|
|
|
|
|
@pytest.fixture(scope="session", name="vcr_config")
|
|
def fixture_vcr_config() -> dict[str, Any]:
|
|
return {
|
|
"filter_headers": [
|
|
CROSSREF_KEY_HEADER,
|
|
SEMANTIC_SCHOLAR_KEY_HEADER,
|
|
OPENAI_API_KEY_HEADER, # Works for Nvidia API key too as it's OpenAI-compatible
|
|
ANTHROPIC_API_KEY_HEADER,
|
|
"cookie",
|
|
],
|
|
"record_mode": "once",
|
|
"cassette_library_dir": str(CASSETTES_DIR),
|
|
# "drop_unused_requests": True, # Restore after https://github.com/kevin1024/vcrpy/issues/961
|
|
}
|
|
|
|
|
|
class PreReadCompatibleAiohttpResponseStream(
|
|
httpx_aiohttp.transport.AiohttpResponseStream
|
|
):
|
|
"""aiohttp-backed response stream that works if the response was pre-read."""
|
|
|
|
async def __aiter__(self) -> AsyncIterator[bytes]:
|
|
with httpx_aiohttp.transport.map_aiohttp_exceptions():
|
|
if self._aiohttp_response._body is not None:
|
|
# Happens if some intermediary called `await _aiohttp_response.read()`
|
|
# TODO: take into account chunk size
|
|
yield self._aiohttp_response._body
|
|
else:
|
|
async for chunk in self._aiohttp_response.content.iter_chunked(
|
|
self.CHUNK_SIZE
|
|
):
|
|
yield chunk
|
|
|
|
|
|
async def _vcr_handle_async_request(
|
|
cassette, # noqa: ARG001
|
|
real_handle_async_request,
|
|
self,
|
|
real_request,
|
|
):
|
|
"""VCR handler that only sends, not possibly recording or playing back responses."""
|
|
return await real_handle_async_request(self, real_request)
|
|
|
|
|
|
# Permanently patch the original response stream,
|
|
# to work around https://github.com/karpetrosyan/httpx-aiohttp/issues/23
|
|
# and https://github.com/BerriAI/litellm/issues/11724
|
|
httpx_aiohttp.transport.AiohttpResponseStream = ( # type: ignore[misc]
|
|
litellm.llms.custom_httpx.aiohttp_transport.AiohttpResponseStream # type: ignore[misc]
|
|
) = PreReadCompatibleAiohttpResponseStream # type: ignore[assignment]
|
|
|
|
# Permanently patch vcrpy's async VCR recording functionality,
|
|
# to work around https://github.com/kevin1024/vcrpy/issues/944
|
|
vcr.stubs.httpcore_stubs._vcr_handle_async_request = _vcr_handle_async_request
|