Download testing/agent_evaluation/backend/__init__.py from yuhanqin/ut-evaluation: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/backend/__init__.py
- Command line
-
hf download hf://datasets/yuhanqin/ut-evaluation/testing/agent_evaluation/backend/__init__.py
-
curl -L -o __init__.py https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/backend/__init__.py
1.8 kB
| """Native implementations of ExperimentBackend and TraceStore.""" | |
| from .experiment_backend import NativeExperimentBackend | |
| from .store import NativeStore | |
| from .trace_store import NativeTraceStore | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| class NativeAdapters: | |
| experiment_backend: NativeExperimentBackend | |
| trace_store: NativeTraceStore | |
| def create_native_adapters(database: str | Path, endpoint: str) -> NativeAdapters: | |
| """Compose native adapters and verify that the collector is the intended store.""" | |
| import json | |
| from urllib.request import build_opener, ProxyHandler | |
| from urllib.parse import urlsplit | |
| parsed = urlsplit(endpoint) | |
| try: | |
| parsed.port # force malformed-port validation | |
| except ValueError as exc: | |
| raise ValueError("native backend endpoint must be a valid HTTP origin") from exc | |
| if (parsed.scheme != "http" or parsed.hostname not in {"127.0.0.1", "localhost"} | |
| or parsed.username or parsed.password or parsed.path not in {"", "/"} | |
| or parsed.query or parsed.fragment): | |
| raise ValueError("native backend endpoint must be a loopback HTTP origin") | |
| store = NativeStore(database) | |
| with build_opener(ProxyHandler({})).open(endpoint.rstrip("/") + "/api/health", timeout=5) as response: | |
| health = json.load(response) | |
| if health.get("backend") != "native" or health.get("database_id") != store.database_id: | |
| raise ValueError("collector and evaluator must use the same --database") | |
| trace = NativeTraceStore(store) | |
| return NativeAdapters(experiment_backend=NativeExperimentBackend(store, trace_store=trace, ui_url=endpoint), | |
| trace_store=trace) | |
| __all__ = ["NativeExperimentBackend", "NativeStore", "NativeTraceStore"] | |