evalsuite-python 2.1.2__py3-none-any.whl → 2.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evalsuite/_http.py +87 -0
- evalsuite/_parquet.py +631 -0
- evalsuite/_special.py +6 -1
- evalsuite/forecasting.py +27 -8
- evalsuite/llm_benchmarks.py +63 -17
- evalsuite/llm_eval.py +74 -45
- evalsuite/stats/intervals.py +7 -3
- evalsuite/text/_porter.py +260 -0
- evalsuite/text/_wordnet.py +76 -0
- evalsuite/text/data/WORDNET_LICENSE +31 -0
- evalsuite/text/data/wordnet30.txt.xz +0 -0
- evalsuite/text/generation.py +6 -13
- evalsuite/text/report.py +3 -9
- evalsuite/text/semantic.py +4 -16
- evalsuite/text/spice.py +5 -13
- evalsuite/version.py +1 -1
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/METADATA +11 -9
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/RECORD +22 -16
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/WHEEL +0 -0
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/entry_points.txt +0 -0
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/licenses/LICENSE +0 -0
- {evalsuite_python-2.1.2.dist-info → evalsuite_python-2.1.3.dist-info}/licenses/LICENSE-APACHE +0 -0
evalsuite/_http.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Minimal JSON-over-HTTPS client on the standard library (``urllib``), used to call model providers and to
|
|
2
|
+
download benchmark files without third-party SDKs.
|
|
3
|
+
|
|
4
|
+
Errors keep what the retry policy in ``llm_eval`` needs: ``status_code`` and ``response.headers`` (for
|
|
5
|
+
``Retry-After``). API keys are passed in by the caller from environment variables and are never logged or put in
|
|
6
|
+
error messages.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import urllib.error
|
|
13
|
+
import urllib.request
|
|
14
|
+
from collections.abc import Mapping
|
|
15
|
+
from types import SimpleNamespace
|
|
16
|
+
from typing import Any, Optional
|
|
17
|
+
|
|
18
|
+
__all__ = ["HTTPStatusError", "get_bytes", "post_json"]
|
|
19
|
+
|
|
20
|
+
USER_AGENT = "evalsuite-python"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class HTTPStatusError(Exception):
|
|
24
|
+
"""A non-2xx HTTP response. ``status_code`` and ``response.headers`` mirror the provider SDKs' errors."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, status_code: int, message: str, headers: Optional[Mapping[str, str]] = None) -> None:
|
|
27
|
+
super().__init__(f"HTTP {status_code}: {message}")
|
|
28
|
+
self.status_code = status_code
|
|
29
|
+
self.response = SimpleNamespace(
|
|
30
|
+
status_code=status_code, headers={k.lower(): v for k, v in (headers or {}).items()}
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _error_message(body: bytes) -> str:
|
|
35
|
+
"""The provider's own error text (OpenAI / Anthropic / Gemini all nest it under ``error.message``)."""
|
|
36
|
+
try:
|
|
37
|
+
data = json.loads(body.decode("utf-8", "replace"))
|
|
38
|
+
except ValueError:
|
|
39
|
+
return body.decode("utf-8", "replace")[:300]
|
|
40
|
+
err = data.get("error") if isinstance(data, dict) else None
|
|
41
|
+
if isinstance(err, dict):
|
|
42
|
+
return str(err.get("message") or err)[:300]
|
|
43
|
+
return str(err or data)[:300]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _checked(url: str) -> str:
|
|
47
|
+
"""Only http(s): urllib would also open file: and other schemes, which a URL from a config must not reach."""
|
|
48
|
+
if not url.lower().startswith(("https://", "http://")):
|
|
49
|
+
from .core.exceptions import InputValidationError
|
|
50
|
+
|
|
51
|
+
raise InputValidationError(f"Only http(s) URLs are allowed; got {url.split(':', 1)[0]!r}.")
|
|
52
|
+
return url
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _open(req: urllib.request.Request, timeout: float) -> tuple[bytes, Mapping[str, str]]:
|
|
56
|
+
try:
|
|
57
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp: # noqa: S310 - https / user-given base URL
|
|
58
|
+
return resp.read(), dict(resp.headers.items())
|
|
59
|
+
except urllib.error.HTTPError as exc:
|
|
60
|
+
body = exc.read() if hasattr(exc, "read") else b""
|
|
61
|
+
raise HTTPStatusError(
|
|
62
|
+
exc.code, _error_message(body), dict(exc.headers.items()) if exc.headers else {}
|
|
63
|
+
) from None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def post_json(url: str, body: Mapping[str, Any], headers: Mapping[str, str], *, timeout: float = 600.0) -> Any:
|
|
67
|
+
"""POST ``body`` as JSON and return the decoded JSON reply."""
|
|
68
|
+
data = json.dumps(body).encode("utf-8")
|
|
69
|
+
req = urllib.request.Request(_checked(url), data=data, method="POST") # noqa: S310 - scheme checked
|
|
70
|
+
req.add_header("Content-Type", "application/json")
|
|
71
|
+
req.add_header("User-Agent", USER_AGENT)
|
|
72
|
+
for k, v in headers.items():
|
|
73
|
+
req.add_header(k, v)
|
|
74
|
+
raw, _ = _open(req, timeout)
|
|
75
|
+
try:
|
|
76
|
+
return json.loads(raw.decode("utf-8"))
|
|
77
|
+
except ValueError as exc:
|
|
78
|
+
raise HTTPStatusError(502, f"response is not JSON: {raw[:120]!r}") from exc
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def get_bytes(url: str, headers: Optional[Mapping[str, str]] = None, *, timeout: float = 600.0) -> bytes:
|
|
82
|
+
"""GET ``url`` (following redirects) and return the body."""
|
|
83
|
+
req = urllib.request.Request(_checked(url), method="GET") # noqa: S310 - scheme checked
|
|
84
|
+
req.add_header("User-Agent", USER_AGENT)
|
|
85
|
+
for k, v in (headers or {}).items():
|
|
86
|
+
req.add_header(k, v)
|
|
87
|
+
return _open(req, timeout)[0]
|