alignmenter 0.0.4__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.
- alignmenter/__init__.py +14 -0
- alignmenter/cli.py +1815 -0
- alignmenter/config.py +99 -0
- alignmenter/data/configs/demo_config.yaml +15 -0
- alignmenter/data/configs/judges/safety_prompt.txt +2 -0
- alignmenter/data/configs/persona/default.yaml +15 -0
- alignmenter/data/configs/run.yaml +12 -0
- alignmenter/data/configs/safety_keywords.yaml +7 -0
- alignmenter/data/datasets/demo_conversations.jsonl +60 -0
- alignmenter/providers/__init__.py +47 -0
- alignmenter/providers/anthropic.py +87 -0
- alignmenter/providers/base.py +57 -0
- alignmenter/providers/classifiers.py +83 -0
- alignmenter/providers/embeddings.py +126 -0
- alignmenter/providers/judges.py +105 -0
- alignmenter/providers/local.py +102 -0
- alignmenter/providers/openai.py +151 -0
- alignmenter/reporting/__init__.py +6 -0
- alignmenter/reporting/html.py +721 -0
- alignmenter/reporting/json_out.py +33 -0
- alignmenter/run_config.py +106 -0
- alignmenter/runner.py +410 -0
- alignmenter/scorers/__init__.py +7 -0
- alignmenter/scorers/authenticity.py +337 -0
- alignmenter/scorers/safety.py +231 -0
- alignmenter/scorers/stability.py +104 -0
- alignmenter/scripts/__init__.py +1 -0
- alignmenter/scripts/bootstrap_dataset.py +142 -0
- alignmenter/scripts/calibrate_persona.py +196 -0
- alignmenter/scripts/run_openai_demo.py +74 -0
- alignmenter/scripts/sanitize_dataset.py +185 -0
- alignmenter/utils/__init__.py +7 -0
- alignmenter/utils/io.py +47 -0
- alignmenter/utils/tokens.py +46 -0
- alignmenter/utils/yaml.py +15 -0
- alignmenter-0.0.4.dist-info/METADATA +681 -0
- alignmenter-0.0.4.dist-info/RECORD +41 -0
- alignmenter-0.0.4.dist-info/WHEEL +5 -0
- alignmenter-0.0.4.dist-info/entry_points.txt +2 -0
- alignmenter-0.0.4.dist-info/licenses/LICENSE +201 -0
- alignmenter-0.0.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Token helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
|
|
8
|
+
try: # pragma: no cover - optional dependency
|
|
9
|
+
import tiktoken
|
|
10
|
+
except ImportError: # pragma: no cover
|
|
11
|
+
tiktoken = None # type: ignore
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def estimate_tokens(text: str, encoding: str = "cl100k_base") -> int:
|
|
15
|
+
"""Estimate token count for *text* using tiktoken when available."""
|
|
16
|
+
|
|
17
|
+
if not text:
|
|
18
|
+
return 0
|
|
19
|
+
|
|
20
|
+
encoder = _get_encoder(encoding)
|
|
21
|
+
if encoder is None and encoding != "gpt-3.5-turbo":
|
|
22
|
+
encoder = _get_encoder("gpt-3.5-turbo")
|
|
23
|
+
|
|
24
|
+
if encoder is not None:
|
|
25
|
+
try:
|
|
26
|
+
return len(encoder.encode(text))
|
|
27
|
+
except Exception: # pragma: no cover - defensive fallback
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
# Lightweight fallback: rough approximation by whitespace tokens
|
|
31
|
+
return max(1, len(text.split()))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@lru_cache(maxsize=4)
|
|
35
|
+
def _get_encoder(name: str):
|
|
36
|
+
if tiktoken is None:
|
|
37
|
+
return None
|
|
38
|
+
try:
|
|
39
|
+
return tiktoken.get_encoding(name)
|
|
40
|
+
except Exception: # pragma: no cover - invalid encoding name
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def stable_hash(token: str, buckets: int = 512) -> int:
|
|
45
|
+
digest = hashlib.blake2s(token.encode("utf-8"), digest_size=8).digest()
|
|
46
|
+
return int.from_bytes(digest, "big") % buckets
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""YAML helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def load_yaml(path: Path) -> Any:
|
|
12
|
+
"""Load a YAML document from *path*."""
|
|
13
|
+
|
|
14
|
+
with Path(path).open("r", encoding="utf-8") as handle:
|
|
15
|
+
return yaml.safe_load(handle)
|