auditkit 1.0.0__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.
- auditkit/README.md +99 -0
- auditkit/__init__.py +177 -0
- auditkit/__main__.py +3 -0
- auditkit/_bootstrap.py +77 -0
- auditkit/_identity_guard.py +99 -0
- auditkit/adapter.py +264 -0
- auditkit/annotator.py +339 -0
- auditkit/api.py +502 -0
- auditkit/assets/auditkit_logo.png +0 -0
- auditkit/cache.py +47 -0
- auditkit/cli.py +417 -0
- auditkit/comparison.py +563 -0
- auditkit/diff.py +265 -0
- auditkit/errors.py +54 -0
- auditkit/evaluator.py +20 -0
- auditkit/experiment.py +145 -0
- auditkit/hf_publish.py +262 -0
- auditkit/lmeval_engine.py +550 -0
- auditkit/loaders.py +121 -0
- auditkit/logs.py +18 -0
- auditkit/metric.py +199 -0
- auditkit/metrics/README.md +15 -0
- auditkit/metrics/__init__.py +0 -0
- auditkit/metrics/code.py +222 -0
- auditkit/metrics/embedding.py +131 -0
- auditkit/metrics/encoder_judge.py +423 -0
- auditkit/metrics/generation.py +331 -0
- auditkit/metrics/guard.py +412 -0
- auditkit/metrics/hallucination.py +45 -0
- auditkit/metrics/judge.py +547 -0
- auditkit/metrics/pairwise.py +153 -0
- auditkit/metrics/perf.py +53 -0
- auditkit/metrics/rag.py +149 -0
- auditkit/metrics/security.py +64 -0
- auditkit/metrics/toxicity.py +238 -0
- auditkit/model/README.md +16 -0
- auditkit/model/__init__.py +485 -0
- auditkit/model/anthropic.py +94 -0
- auditkit/model/api_gen.py +133 -0
- auditkit/model/groq_gen.py +121 -0
- auditkit/model/hf_gen.py +385 -0
- auditkit/model/lexsi.py +155 -0
- auditkit/model/litellm_gen.py +65 -0
- auditkit/model/openai.py +90 -0
- auditkit/model/openrouter_gen.py +152 -0
- auditkit/model/vllm_gen.py +316 -0
- auditkit/model_compare.py +655 -0
- auditkit/redteam/README.md +9 -0
- auditkit/redteam/__init__.py +26 -0
- auditkit/redteam/detector.py +37 -0
- auditkit/redteam/detectors/README.md +5 -0
- auditkit/redteam/detectors/builtin.py +126 -0
- auditkit/redteam/probe.py +39 -0
- auditkit/redteam/probes/README.md +5 -0
- auditkit/redteam/probes/builtin.py +85 -0
- auditkit/redteam/runner.py +206 -0
- auditkit/registry.py +65 -0
- auditkit/report.py +278 -0
- auditkit/report_format.py +52 -0
- auditkit/router.py +54 -0
- auditkit/runner.py +575 -0
- auditkit/runspec.py +159 -0
- auditkit/sample.py +40 -0
- auditkit/scenario.py +88 -0
- auditkit/scenarios/README.md +10 -0
- auditkit/scenarios/__init__.py +4 -0
- auditkit/scenarios/arc.py +33 -0
- auditkit/scenarios/gsm8k.py +32 -0
- auditkit/scenarios/hellaswag.py +33 -0
- auditkit/scenarios/humaneval.py +32 -0
- auditkit/scenarios/mmlu.py +34 -0
- auditkit/scenarios/truthfulqa.py +33 -0
- auditkit/score.py +165 -0
- auditkit/scorers.py +117 -0
- auditkit/scoring.py +79 -0
- auditkit/types.py +69 -0
- auditkit-1.0.0.dist-info/METADATA +396 -0
- auditkit-1.0.0.dist-info/RECORD +81 -0
- auditkit-1.0.0.dist-info/WHEEL +4 -0
- auditkit-1.0.0.dist-info/entry_points.txt +2 -0
- auditkit-1.0.0.dist-info/licenses/LICENSE.md +92 -0
auditkit/hf_publish.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""HuggingFace Hub publishing with AuditKIT dataset-card branding.
|
|
2
|
+
|
|
3
|
+
``brand_hf_repo`` creates a Hub **dataset** repo if needed, uploads the packaged
|
|
4
|
+
logo, and writes README.md. Logos ship inside the package
|
|
5
|
+
(``auditkit/assets/*.png``) and are copied into the destination repo — image
|
|
6
|
+
srcs point at that repo, never a personal Hugging Face CDN URL.
|
|
7
|
+
|
|
8
|
+
Same pattern as AlignTune ``aligntune.utils.hf_publish`` and CuratorKIT
|
|
9
|
+
``curatorkit.utils.hf_publish``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
import os
|
|
16
|
+
import tempfile
|
|
17
|
+
from datetime import datetime, timezone
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Optional
|
|
20
|
+
|
|
21
|
+
from .errors import ExtraNotInstalled
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
AUDITKIT_REPO_URL = "https://github.com/Lexsi-Labs/AuditKIT"
|
|
26
|
+
LEXSI_URL = "https://lexsi.ai/"
|
|
27
|
+
|
|
28
|
+
_ASSETS_DIR = Path(__file__).resolve().parent / "assets"
|
|
29
|
+
_LOGO_ASSET = _ASSETS_DIR / "auditkit_logo.png"
|
|
30
|
+
_LOGO_REPO_NAME = "auditkit_logo.png"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _resolve_token(token: Optional[str] = None) -> str:
|
|
34
|
+
token = (
|
|
35
|
+
token
|
|
36
|
+
or os.environ.get("HF_TOKEN")
|
|
37
|
+
or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
|
38
|
+
)
|
|
39
|
+
if not token:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
"No HuggingFace token found. Pass token=..., set HF_TOKEN "
|
|
42
|
+
"or HUGGING_FACE_HUB_TOKEN, or run huggingface-cli login."
|
|
43
|
+
)
|
|
44
|
+
return token
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _hub_import():
|
|
48
|
+
try:
|
|
49
|
+
from huggingface_hub import HfApi
|
|
50
|
+
except ImportError as e:
|
|
51
|
+
raise ExtraNotInstalled(
|
|
52
|
+
"interop",
|
|
53
|
+
"pip install auditkit[interop]",
|
|
54
|
+
) from e
|
|
55
|
+
return HfApi
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _hub_asset_url(repo_id: str, filename: str) -> str:
|
|
59
|
+
return f"https://huggingface.co/datasets/{repo_id}/resolve/main/{filename}"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _upload_packaged_asset(api, repo_id: str, token: str, local: Path, name: str) -> Optional[str]:
|
|
63
|
+
if not local.exists():
|
|
64
|
+
logger.warning("Packaged branding asset missing: %s", local)
|
|
65
|
+
return None
|
|
66
|
+
api.upload_file(
|
|
67
|
+
path_or_fileobj=str(local),
|
|
68
|
+
path_in_repo=name,
|
|
69
|
+
repo_id=repo_id,
|
|
70
|
+
repo_type="dataset",
|
|
71
|
+
token=token,
|
|
72
|
+
)
|
|
73
|
+
return _hub_asset_url(repo_id, name)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _branding_header(logo_url: Optional[str]) -> str:
|
|
77
|
+
if not logo_url:
|
|
78
|
+
return ""
|
|
79
|
+
return f"""<div align="center">
|
|
80
|
+
<table border="0" cellspacing="0" cellpadding="0" style="border: none; border-collapse: collapse;">
|
|
81
|
+
<tr>
|
|
82
|
+
<td align="center" style="border: none; vertical-align: middle;">
|
|
83
|
+
<a href="{LEXSI_URL}"><img src="{logo_url}" alt="AuditKIT" style="height: 60px; border-radius: 12px;"/></a>
|
|
84
|
+
</td>
|
|
85
|
+
</tr>
|
|
86
|
+
</table>
|
|
87
|
+
</div>
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def render_dataset_card(
|
|
92
|
+
repo_id: str,
|
|
93
|
+
kind: str = "run",
|
|
94
|
+
method: str = "",
|
|
95
|
+
model: str = "",
|
|
96
|
+
extra_notes: str = "",
|
|
97
|
+
logo_url: Optional[str] = None,
|
|
98
|
+
built_on: str = "",
|
|
99
|
+
) -> str:
|
|
100
|
+
"""Hub dataset README: YAML tags + method / model table."""
|
|
101
|
+
name = repo_id.split("/")[-1]
|
|
102
|
+
method = method or "evaluate"
|
|
103
|
+
model_shown = model or "—"
|
|
104
|
+
header = _branding_header(logo_url)
|
|
105
|
+
stamp = built_on or datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
|
106
|
+
return f"""---
|
|
107
|
+
license: other
|
|
108
|
+
pretty_name: {name}
|
|
109
|
+
task_categories:
|
|
110
|
+
- text-generation
|
|
111
|
+
tags:
|
|
112
|
+
- auditkit
|
|
113
|
+
- lexsi-labs
|
|
114
|
+
- evaluation
|
|
115
|
+
- {kind}
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
{header}
|
|
119
|
+
# {name}
|
|
120
|
+
|
|
121
|
+
Built using [AuditKIT]({AUDITKIT_REPO_URL}) — evaluate any model on any dataset and any task.
|
|
122
|
+
|
|
123
|
+
| | |
|
|
124
|
+
|---|---|
|
|
125
|
+
| **Method** | {method} |
|
|
126
|
+
| **Model** | `{model_shown}` |
|
|
127
|
+
| **Artifact** | {kind} |
|
|
128
|
+
| **Published** | {stamp} |
|
|
129
|
+
|
|
130
|
+
{extra_notes}
|
|
131
|
+
|
|
132
|
+
## Usage
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from datasets import load_dataset
|
|
136
|
+
|
|
137
|
+
ds = load_dataset("{repo_id}")
|
|
138
|
+
```
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def brand_hf_repo(
|
|
143
|
+
repo_id: str,
|
|
144
|
+
kind: str = "run",
|
|
145
|
+
method: str = "",
|
|
146
|
+
model: str = "",
|
|
147
|
+
private: bool = False,
|
|
148
|
+
token: Optional[str] = None,
|
|
149
|
+
extra_notes: str = "",
|
|
150
|
+
) -> str:
|
|
151
|
+
"""Create the Hub dataset repo if needed, upload the packaged logo, write README.md.
|
|
152
|
+
|
|
153
|
+
Always ``repo_type="dataset"``. Does not upload rows — call after a push helper.
|
|
154
|
+
"""
|
|
155
|
+
HfApi = _hub_import()
|
|
156
|
+
token = _resolve_token(token)
|
|
157
|
+
api = HfApi(token=token)
|
|
158
|
+
built_on = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
|
159
|
+
api.create_repo(
|
|
160
|
+
repo_id,
|
|
161
|
+
repo_type="dataset",
|
|
162
|
+
private=private,
|
|
163
|
+
exist_ok=True,
|
|
164
|
+
token=token,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
logo_url = _upload_packaged_asset(api, repo_id, token, _LOGO_ASSET, _LOGO_REPO_NAME)
|
|
168
|
+
readme = render_dataset_card(
|
|
169
|
+
repo_id,
|
|
170
|
+
kind=kind,
|
|
171
|
+
method=method,
|
|
172
|
+
model=model,
|
|
173
|
+
extra_notes=extra_notes,
|
|
174
|
+
logo_url=logo_url,
|
|
175
|
+
built_on=built_on,
|
|
176
|
+
)
|
|
177
|
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
|
|
178
|
+
f.write(readme)
|
|
179
|
+
readme_path = f.name
|
|
180
|
+
try:
|
|
181
|
+
api.upload_file(
|
|
182
|
+
path_or_fileobj=readme_path,
|
|
183
|
+
path_in_repo="README.md",
|
|
184
|
+
repo_id=repo_id,
|
|
185
|
+
repo_type="dataset",
|
|
186
|
+
token=token,
|
|
187
|
+
)
|
|
188
|
+
finally:
|
|
189
|
+
os.remove(readme_path)
|
|
190
|
+
|
|
191
|
+
url = f"https://huggingface.co/datasets/{repo_id}"
|
|
192
|
+
logger.info("Branded %s", url)
|
|
193
|
+
return url
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _brand_safe(
|
|
197
|
+
repo_id: str,
|
|
198
|
+
kind: str = "run",
|
|
199
|
+
method: str = "",
|
|
200
|
+
model: str = "",
|
|
201
|
+
private: bool = False,
|
|
202
|
+
token: Optional[str] = None,
|
|
203
|
+
extra_notes: str = "",
|
|
204
|
+
) -> str:
|
|
205
|
+
"""Brand the repo; a branding failure does not undo a successful push."""
|
|
206
|
+
try:
|
|
207
|
+
return brand_hf_repo(
|
|
208
|
+
repo_id,
|
|
209
|
+
kind=kind,
|
|
210
|
+
method=method,
|
|
211
|
+
model=model,
|
|
212
|
+
private=private,
|
|
213
|
+
token=token,
|
|
214
|
+
extra_notes=extra_notes,
|
|
215
|
+
)
|
|
216
|
+
except Exception as e:
|
|
217
|
+
logger.warning("Dataset card branding skipped for %s: %s", repo_id, e)
|
|
218
|
+
return f"https://huggingface.co/datasets/{repo_id}"
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _parquet_safe_value(value: Any) -> Any:
|
|
222
|
+
"""Parquet cannot write a struct with no child fields (empty ``{}``)."""
|
|
223
|
+
if isinstance(value, dict):
|
|
224
|
+
if not value:
|
|
225
|
+
return None
|
|
226
|
+
return {k: _parquet_safe_value(v) for k, v in value.items()}
|
|
227
|
+
if isinstance(value, (list, tuple)):
|
|
228
|
+
return [_parquet_safe_value(v) for v in value]
|
|
229
|
+
return value
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _parquet_safe_rows(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
233
|
+
return [{k: _parquet_safe_value(v) for k, v in row.items()} for row in rows]
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def push_rows_to_hub(
|
|
237
|
+
rows: list[dict[str, Any]],
|
|
238
|
+
repo_id: str,
|
|
239
|
+
private: bool = False,
|
|
240
|
+
token: Optional[str] = None,
|
|
241
|
+
kind: str = "run",
|
|
242
|
+
method: str = "",
|
|
243
|
+
model: str = "",
|
|
244
|
+
extra_notes: str = "",
|
|
245
|
+
) -> str:
|
|
246
|
+
"""Push rows as a Hub dataset, then stamp the Lexsi / AuditKIT card."""
|
|
247
|
+
try:
|
|
248
|
+
from datasets import Dataset
|
|
249
|
+
except ImportError as e:
|
|
250
|
+
raise ExtraNotInstalled("interop", "pip install auditkit[interop]") from e
|
|
251
|
+
safe = _parquet_safe_rows(rows)
|
|
252
|
+
ds = Dataset.from_list(safe) if safe else Dataset.from_dict({"sample_id": []})
|
|
253
|
+
ds.push_to_hub(repo_id, private=private, token=token)
|
|
254
|
+
return _brand_safe(
|
|
255
|
+
repo_id,
|
|
256
|
+
kind=kind,
|
|
257
|
+
method=method,
|
|
258
|
+
model=model,
|
|
259
|
+
private=private,
|
|
260
|
+
token=token,
|
|
261
|
+
extra_notes=extra_notes,
|
|
262
|
+
)
|