regulated-eval 1.0.0__tar.gz
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.
- regulated_eval-1.0.0/.gigacode/.gitignore +7 -0
- regulated_eval-1.0.0/.gigacode/rules/issue-sync.md +8 -0
- regulated_eval-1.0.0/.github/workflows/docs.yml +20 -0
- regulated_eval-1.0.0/.github/workflows/lint.yml +32 -0
- regulated_eval-1.0.0/.github/workflows/matrix.yml +31 -0
- regulated_eval-1.0.0/.github/workflows/test.yml +26 -0
- regulated_eval-1.0.0/.gitignore +67 -0
- regulated_eval-1.0.0/CHANGELOG.md +51 -0
- regulated_eval-1.0.0/CONTRIBUTING.md +86 -0
- regulated_eval-1.0.0/LICENSE +21 -0
- regulated_eval-1.0.0/PKG-INFO +272 -0
- regulated_eval-1.0.0/README.md +223 -0
- regulated_eval-1.0.0/SECURITY.md +36 -0
- regulated_eval-1.0.0/_lint_log.txt +0 -0
- regulated_eval-1.0.0/adr/.gitkeep +0 -0
- regulated_eval-1.0.0/adr/ADR-001-pii-redaction-stack.md +66 -0
- regulated_eval-1.0.0/adr/ADR-002-provider-allowlist.md +73 -0
- regulated_eval-1.0.0/adr/ADR-003-judge-output-validation.md +80 -0
- regulated_eval-1.0.0/adr/ADR-004-otel-instrumentation.md +78 -0
- regulated_eval-1.0.0/adr/ADR-005-annotation-hash-chain.md +78 -0
- regulated_eval-1.0.0/api/.gitkeep +0 -0
- regulated_eval-1.0.0/api/api-contract.yaml +944 -0
- regulated_eval-1.0.0/apply/.gitkeep +0 -0
- regulated_eval-1.0.0/apply/apply.md +237 -0
- regulated_eval-1.0.0/context.md +92 -0
- regulated_eval-1.0.0/datasets/calibration_v1/sample.json +202 -0
- regulated_eval-1.0.0/datasets/tax_qa_v1/sample.json +182 -0
- regulated_eval-1.0.0/datasets/tax_qa_v1/sample.jsonl +20 -0
- regulated_eval-1.0.0/design/.gitkeep +0 -0
- regulated_eval-1.0.0/design/design.md +378 -0
- regulated_eval-1.0.0/docs/152fz.md +130 -0
- regulated_eval-1.0.0/docs/PRD.md +69 -0
- regulated_eval-1.0.0/docs/case_study.md +108 -0
- regulated_eval-1.0.0/docs/methodology.md +162 -0
- regulated_eval-1.0.0/notebooks/.gitkeep +0 -0
- regulated_eval-1.0.0/prompts/.gitkeep +0 -0
- regulated_eval-1.0.0/proposal.md +81 -0
- regulated_eval-1.0.0/pyproject.toml +88 -0
- regulated_eval-1.0.0/reports/.gitkeep +0 -0
- regulated_eval-1.0.0/run_tests.py +22 -0
- regulated_eval-1.0.0/specs/.gitkeep +0 -0
- regulated_eval-1.0.0/specs/eval-pipeline/spec.md +426 -0
- regulated_eval-1.0.0/src/regulated_eval/__init__.py +95 -0
- regulated_eval-1.0.0/src/regulated_eval/ab/__init__.py +268 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/__init__.py +73 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/base.py +126 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/gigachat.py +226 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/openai_compat.py +198 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/retry.py +123 -0
- regulated_eval-1.0.0/src/regulated_eval/adapters/yandexgpt.py +178 -0
- regulated_eval-1.0.0/src/regulated_eval/cli.py +752 -0
- regulated_eval-1.0.0/src/regulated_eval/config.py +112 -0
- regulated_eval-1.0.0/src/regulated_eval/datasets/__init__.py +1 -0
- regulated_eval-1.0.0/src/regulated_eval/datasets/loader.py +145 -0
- regulated_eval-1.0.0/src/regulated_eval/datasets/manifest.py +164 -0
- regulated_eval-1.0.0/src/regulated_eval/datasets/versioning.py +163 -0
- regulated_eval-1.0.0/src/regulated_eval/exceptions.py +39 -0
- regulated_eval-1.0.0/src/regulated_eval/human_loop/__init__.py +13 -0
- regulated_eval-1.0.0/src/regulated_eval/human_loop/annotation_store.py +314 -0
- regulated_eval-1.0.0/src/regulated_eval/judges/__init__.py +24 -0
- regulated_eval-1.0.0/src/regulated_eval/judges/calibration.py +214 -0
- regulated_eval-1.0.0/src/regulated_eval/judges/conflicts.py +200 -0
- regulated_eval-1.0.0/src/regulated_eval/judges/judge.py +268 -0
- regulated_eval-1.0.0/src/regulated_eval/metrics/__init__.py +1 -0
- regulated_eval-1.0.0/src/regulated_eval/metrics/aggregator.py +145 -0
- regulated_eval-1.0.0/src/regulated_eval/observability/__init__.py +66 -0
- regulated_eval-1.0.0/src/regulated_eval/observability/logs.py +321 -0
- regulated_eval-1.0.0/src/regulated_eval/observability/metrics.py +253 -0
- regulated_eval-1.0.0/src/regulated_eval/observability/otel_setup.py +223 -0
- regulated_eval-1.0.0/src/regulated_eval/observability/redaction.py +220 -0
- regulated_eval-1.0.0/src/regulated_eval/pipeline.py +501 -0
- regulated_eval-1.0.0/src/regulated_eval/py.typed +2 -0
- regulated_eval-1.0.0/src/regulated_eval/reports/__init__.py +20 -0
- regulated_eval-1.0.0/src/regulated_eval/reports/html.py +200 -0
- regulated_eval-1.0.0/src/regulated_eval/reports/markdown.py +140 -0
- regulated_eval-1.0.0/src/regulated_eval/schemas.py +263 -0
- regulated_eval-1.0.0/src/regulated_eval/security/__init__.py +50 -0
- regulated_eval-1.0.0/src/regulated_eval/security/audit.py +201 -0
- regulated_eval-1.0.0/src/regulated_eval/security/injection_filter.py +186 -0
- regulated_eval-1.0.0/src/regulated_eval/security/pii_redactor.py +212 -0
- regulated_eval-1.0.0/src/regulated_eval/security/provider_allowlist.py +208 -0
- regulated_eval-1.0.0/src/regulated_eval/security/secrets.py +110 -0
- regulated_eval-1.0.0/tasks/.gitkeep +0 -0
- regulated_eval-1.0.0/tasks/tasks.md +578 -0
- regulated_eval-1.0.0/test-specs/.gitkeep +0 -0
- regulated_eval-1.0.0/test-specs/eval-pipeline/tests.md +791 -0
- regulated_eval-1.0.0/tests/conftest.py +9 -0
- regulated_eval-1.0.0/tests/e2e/test_cli_vs_library.py +189 -0
- regulated_eval-1.0.0/tests/e2e/test_human_loop.py +141 -0
- regulated_eval-1.0.0/tests/integration/test_ab.py +103 -0
- regulated_eval-1.0.0/tests/integration/test_ab_cli.py +309 -0
- regulated_eval-1.0.0/tests/integration/test_adapters.py +311 -0
- regulated_eval-1.0.0/tests/integration/test_calibration.py +61 -0
- regulated_eval-1.0.0/tests/integration/test_metrics.py +170 -0
- regulated_eval-1.0.0/tests/integration/test_metrics_calibration.py +416 -0
- regulated_eval-1.0.0/tests/integration/test_pipeline.py +329 -0
- regulated_eval-1.0.0/tests/integration/test_reports_annotations.py +400 -0
- regulated_eval-1.0.0/tests/integration/test_security.py +238 -0
- regulated_eval-1.0.0/tests/observability/test_otel.py +140 -0
- regulated_eval-1.0.0/tests/performance/test_performance.py +164 -0
- regulated_eval-1.0.0/tests/security/test_annotation_chain.py +136 -0
- regulated_eval-1.0.0/tests/security/test_pii.py +146 -0
- regulated_eval-1.0.0/tests/security/test_secrets.py +173 -0
- regulated_eval-1.0.0/tests/unit/test_datasets.py +225 -0
- regulated_eval-1.0.0/tests/unit/test_judge.py +147 -0
- regulated_eval-1.0.0/tests/unit/test_schemas.py +370 -0
- regulated_eval-1.0.0/threat-model/.gitkeep +0 -0
- regulated_eval-1.0.0/threat-model/threat-model.md +184 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Синхронизация статуса Issue
|
|
2
|
+
|
|
3
|
+
После завершения работы над задачей (ID вида T-xxx), когда код написан и проверен, необходимо:
|
|
4
|
+
1. Найти номер соответствующего Issue на GitHub с помощью команды в терминале:
|
|
5
|
+
`gh issue list --search "T-xxx" --json number -q ".[0].number"`
|
|
6
|
+
2. Закрыть найденный Issue командой:
|
|
7
|
+
`gh issue close <номер> --comment "Реализовано в рамках задачи"`
|
|
8
|
+
3. Если Issue не найден, сообщить об этом пользователю.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: docs-check
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
docs-check:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Check docs exist
|
|
16
|
+
run: |
|
|
17
|
+
test -f docs/PRD.md || { echo "Missing docs/PRD.md"; exit 1; }
|
|
18
|
+
test -f docs/methodology.md || { echo "Missing docs/methodology.md"; exit 1; }
|
|
19
|
+
test -f docs/case_study.md || { echo "Missing docs/case_study.md"; exit 1; }
|
|
20
|
+
echo "All required docs present"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Set up Python
|
|
16
|
+
uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: |
|
|
22
|
+
python -m pip install --upgrade pip
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
|
|
25
|
+
- name: ruff check
|
|
26
|
+
run: ruff check src/ tests/
|
|
27
|
+
|
|
28
|
+
- name: ruff format --check
|
|
29
|
+
run: ruff format --check src/ tests/
|
|
30
|
+
|
|
31
|
+
- name: mypy
|
|
32
|
+
run: mypy src/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: matrix
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
matrix:
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
15
|
+
python-version: ["3.11", "3.12"]
|
|
16
|
+
runs-on: ${{ matrix.os }}
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
|
|
30
|
+
- name: Run pytest
|
|
31
|
+
run: pytest -q
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Set up Python
|
|
16
|
+
uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: |
|
|
22
|
+
python -m pip install --upgrade pip
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
|
|
25
|
+
- name: Run pytest with coverage
|
|
26
|
+
run: pytest --cov=src/regulated_eval --cov-report=term-missing --cov-fail-under=80 -q
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
*.egg
|
|
25
|
+
MANIFEST
|
|
26
|
+
|
|
27
|
+
# Virtual environments
|
|
28
|
+
.env
|
|
29
|
+
.venv
|
|
30
|
+
env/
|
|
31
|
+
venv/
|
|
32
|
+
ENV/
|
|
33
|
+
env.bak/
|
|
34
|
+
venv.bak/
|
|
35
|
+
|
|
36
|
+
# IDE
|
|
37
|
+
.idea/
|
|
38
|
+
.vscode/
|
|
39
|
+
*.swp
|
|
40
|
+
*.swo
|
|
41
|
+
*~
|
|
42
|
+
|
|
43
|
+
# Testing
|
|
44
|
+
.coverage
|
|
45
|
+
htmlcov/
|
|
46
|
+
.pytest_cache/
|
|
47
|
+
.tox/
|
|
48
|
+
.coverage.*
|
|
49
|
+
*.cover
|
|
50
|
+
*.log
|
|
51
|
+
|
|
52
|
+
# PyInstaller
|
|
53
|
+
*.manifest
|
|
54
|
+
*.spec
|
|
55
|
+
|
|
56
|
+
# OS
|
|
57
|
+
.DS_Store
|
|
58
|
+
Thumbs.db
|
|
59
|
+
|
|
60
|
+
# Regulatory data (contains PII)
|
|
61
|
+
datasets/*.jsonl
|
|
62
|
+
datasets/*.json
|
|
63
|
+
|
|
64
|
+
# Secrets
|
|
65
|
+
.env
|
|
66
|
+
.env.*
|
|
67
|
+
!/.env.example
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.0.0] - 2026-11-08
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **Core Framework**
|
|
14
|
+
- Golden set management (JSONL, Pydantic validation, semver, content hash)
|
|
15
|
+
- LLM-as-a-judge with calibration (Cohen's kappa + bootstrap CI)
|
|
16
|
+
- Metrics: hallucination_rate, citation_accuracy, refusal_correctness, factual_consistency
|
|
17
|
+
- Human-in-the-loop (Streamlit UI, hash-chain annotations)
|
|
18
|
+
- A/B testing (Wilcoxon, bootstrap CI, Cohen's d)
|
|
19
|
+
- Adapters: YandexGPT, GigaChat, OpenAI-compatible (opt-in)
|
|
20
|
+
- PII redaction (Presidio + regex for RU: ИНН, СНИЛС, passport, phone, address)
|
|
21
|
+
- Prompt-injection filter (allowlist + heuristics)
|
|
22
|
+
- OTel instrumentation (spans, metrics, audit-logs) with redaction middleware
|
|
23
|
+
- Markdown/HTML reports with delta comparison
|
|
24
|
+
- CLI + Library API (Typer + Python API)
|
|
25
|
+
|
|
26
|
+
- **Observability**
|
|
27
|
+
- Spans: `eval.run`, `judge.evaluate`, `adapter.call`
|
|
28
|
+
- Metrics: `eval.run.duration`, `eval.run.failed`, `llm.request.duration`, `judge.calibration.kappa`, `hallucination.rate`, `citation_accuracy`
|
|
29
|
+
- Audit logs: `pii_redacted`, `injection_suspected`, `conflict_resolved`, `ab_test_completed`
|
|
30
|
+
- SLO: eval.run p95 ≤ 300s, judge p95 ≤ 5000ms, availability 99.0%
|
|
31
|
+
|
|
32
|
+
- **CI/CD**
|
|
33
|
+
- GitHub Actions: lint, test, matrix (ubuntu/macos/windows × py3.11/3.12), docs-check
|
|
34
|
+
- Coverage target: ≥ 80%
|
|
35
|
+
|
|
36
|
+
- **Documentation**
|
|
37
|
+
- PRD, methodology, case_study, 152fz compliance guide
|
|
38
|
+
- OpenSpec artifacts: proposal, specs, design, threat-model, ADR, API contract, test-specs, tasks, apply
|
|
39
|
+
- Traceability matrix, 15 threat models, 5 ADRs
|
|
40
|
+
|
|
41
|
+
- **Tests**
|
|
42
|
+
- 211 tests: unit, integration, E2E, performance, observability
|
|
43
|
+
- Security tests: secrets, hash-chain, PII, injection, provider allowlist
|
|
44
|
+
|
|
45
|
+
### Security
|
|
46
|
+
- Default provider allowlist: Russian providers only (YandexGPT, GigaChat)
|
|
47
|
+
- Foreign provider double opt-in (`--allow-foreign-provider` + `--i-understand-152fz`)
|
|
48
|
+
- PII redaction before LLM submission (recall ≥ 99%)
|
|
49
|
+
- Audit logging without PII values
|
|
50
|
+
- OTel attribute redaction via `RedactingSpanProcessor`
|
|
51
|
+
- Hash-chain annotations for tamper detection
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Contributing Guide
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
1. Fork the repository
|
|
6
|
+
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/regulated-llm-eval-framework.git`
|
|
7
|
+
3. Create a feature branch: `git checkout -b feature/my-feature`
|
|
8
|
+
4. Make changes and commit
|
|
9
|
+
5. Push to your fork: `git push origin feature/my-feature`
|
|
10
|
+
6. Open a Pull Request
|
|
11
|
+
|
|
12
|
+
## Development Setup
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/realrvs/regulated-llm-eval-framework.git
|
|
16
|
+
cd regulated-llm-eval-framework
|
|
17
|
+
|
|
18
|
+
python -m venv .venv
|
|
19
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
20
|
+
|
|
21
|
+
pip install -e ".[dev]"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Running Tests
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# All tests
|
|
28
|
+
pytest -q
|
|
29
|
+
|
|
30
|
+
# With coverage
|
|
31
|
+
pytest --cov=src/regulated_eval --cov-report=term-missing
|
|
32
|
+
|
|
33
|
+
# Target coverage: ≥ 80% for judges, metrics, ab, datasets
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Code Style
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Lint
|
|
40
|
+
ruff check .
|
|
41
|
+
|
|
42
|
+
# Format
|
|
43
|
+
ruff format .
|
|
44
|
+
|
|
45
|
+
# Type checking
|
|
46
|
+
mypy src/regulated_eval
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
All checks must pass before PR merge.
|
|
50
|
+
|
|
51
|
+
## Commit Messages
|
|
52
|
+
|
|
53
|
+
Follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
feat(cli): add calibrate command
|
|
57
|
+
fix(pipeline): handle empty results
|
|
58
|
+
docs: update PRD
|
|
59
|
+
test(security): add hash-chain tests
|
|
60
|
+
ci: add GitHub Actions workflows
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Types: `feat`, `fix`, `docs`, `test`, `ci`, `refactor`, `chore`
|
|
64
|
+
|
|
65
|
+
## Pull Request Checklist
|
|
66
|
+
|
|
67
|
+
- [ ] Tests pass (`pytest -q`)
|
|
68
|
+
- [ ] Coverage ≥ 80% for changed modules
|
|
69
|
+
- [ ] `ruff check` and `ruff format` clean
|
|
70
|
+
- [ ] `mypy` passes
|
|
71
|
+
- [ ] Commit message follows Conventional Commits
|
|
72
|
+
- [ ] Updated documentation if API changed
|
|
73
|
+
- [ ] For security changes: updated `threat-model.md` and added `TM Ref` in tests
|
|
74
|
+
|
|
75
|
+
## Security Contributions
|
|
76
|
+
|
|
77
|
+
For security-related changes:
|
|
78
|
+
|
|
79
|
+
1. Update `threat-model/threat-model.md` with new threat analysis
|
|
80
|
+
2. Add test with `TM Ref` in docstring
|
|
81
|
+
3. Update `docs/152fz.md` if 152-FZ compliance affected
|
|
82
|
+
4. No secrets in code or tests
|
|
83
|
+
|
|
84
|
+
## Questions?
|
|
85
|
+
|
|
86
|
+
Open an issue or use GitHub Discussions.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Regulated LLM Eval Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: regulated-eval
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Regulated LLM Eval Framework — evaluation for LLMs in regulated domains (tax, accounting, legal) with 152-FZ compliance
|
|
5
|
+
Project-URL: Homepage, https://github.com/regulated-llm-eval/regulated-eval
|
|
6
|
+
Project-URL: Repository, https://github.com/regulated-llm-eval/regulated-eval
|
|
7
|
+
Project-URL: Documentation, https://github.com/regulated-llm-eval/regulated-eval#readme
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/regulated-llm-eval/regulated-eval/issues
|
|
9
|
+
Author: Regulated LLM Eval Contributors
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: Pydantic :: 2
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: httpx>=0.27.0
|
|
23
|
+
Requires-Dist: jinja2>=3.1
|
|
24
|
+
Requires-Dist: numpy>=1.26
|
|
25
|
+
Requires-Dist: opentelemetry-api>=1.25.0
|
|
26
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.25.0
|
|
27
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.46b0
|
|
28
|
+
Requires-Dist: opentelemetry-sdk>=1.25.0
|
|
29
|
+
Requires-Dist: pandas>=2.0
|
|
30
|
+
Requires-Dist: pydantic-settings>=2.0
|
|
31
|
+
Requires-Dist: pydantic>=2.0
|
|
32
|
+
Requires-Dist: scikit-learn>=1.3
|
|
33
|
+
Requires-Dist: scipy>=1.11
|
|
34
|
+
Requires-Dist: tenacity>=8.2.0
|
|
35
|
+
Requires-Dist: typer[all]>=0.12.0
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
42
|
+
Requires-Dist: types-jinja2; extra == 'dev'
|
|
43
|
+
Provides-Extra: presidio
|
|
44
|
+
Requires-Dist: presidio-analyzer>=2.2; extra == 'presidio'
|
|
45
|
+
Requires-Dist: presidio-anonymizer>=2.2; extra == 'presidio'
|
|
46
|
+
Provides-Extra: streamlit
|
|
47
|
+
Requires-Dist: streamlit>=1.30; extra == 'streamlit'
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# regulated-llm-eval
|
|
51
|
+
|
|
52
|
+
> Eval-фреймворк для LLM в regulated-доменах (налоги, бухгалтерия, право).
|
|
53
|
+
> Калиброванный LLM-as-a-judge, метрики галлюцинаций и citation accuracy, A/B-тесты промптов, PII-redaction под 152-ФЗ, поддержка YandexGPT и GigaChat.
|
|
54
|
+
|
|
55
|
+
[](https://www.python.org/downloads/)
|
|
56
|
+
[](LICENSE)
|
|
57
|
+
[](docs/PRD.md)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quickstart (≤ 5 минут)
|
|
62
|
+
|
|
63
|
+
### 1. Установка
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install regulated-eval
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. API-ключ провайдера
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# YandexGPT (российский, соответствует 152-ФЗ)
|
|
73
|
+
export YANDEXGPT_API_KEY="your-key"
|
|
74
|
+
|
|
75
|
+
# GigaChat (российский, соответствует 152-ФЗ)
|
|
76
|
+
export GIGACHAT_API_KEY="your-key"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. Первый прогон
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Загрузка sample golden set (20 вопросов по УСН/НДС/взносам)
|
|
83
|
+
regulated-eval dataset load --path datasets/tax_qa_v1/sample.jsonl --version 0.1.0
|
|
84
|
+
|
|
85
|
+
# Прогон через YandexGPT + judge
|
|
86
|
+
regulated-eval run \
|
|
87
|
+
--dataset tax_qa_v1@0.1.0 \
|
|
88
|
+
--model yandexgpt \
|
|
89
|
+
--judge-model yandexgpt \
|
|
90
|
+
--report md
|
|
91
|
+
|
|
92
|
+
# Отчёт: reports/<run_id>.md
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 4. Калибровка (обязательно перед публикацией отчёта)
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
regulated-eval calibrate \
|
|
99
|
+
--dataset calibration_v1 \
|
|
100
|
+
--judge-model yandexgpt \
|
|
101
|
+
--threshold 0.6
|
|
102
|
+
# → PASS (kappa ≥ 0.6) или FAIL + рекомендации
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 5. A/B-сравнение моделей
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
regulated-eval ab \
|
|
109
|
+
--model-a yandexgpt \
|
|
110
|
+
--model-b gigachat \
|
|
111
|
+
--dataset tax_qa_v1@0.1.0 \
|
|
112
|
+
--judge-model yandexgpt
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Что внутри
|
|
116
|
+
|
|
117
|
+
| Возможность | Что даёт |
|
|
118
|
+
|---|---|
|
|
119
|
+
| **Golden set management** | JSONL + Pydantic-схема, semver + content hash, воспроизводимость прогонов |
|
|
120
|
+
| **LLM-as-a-judge с калибровкой** | Score 1–5 + бинарные флаги (hallucination, wrong citation, incorrect refusal), Cohen's kappa с CI, repair-retry на невалидный JSON |
|
|
121
|
+
| **Метрики** | `hallucination_rate`, `citation_accuracy`, `refusal_correctness`, `factual_consistency`, агрегация по category/difficulty/model |
|
|
122
|
+
| **Human-in-the-loop** | Streamlit UI для экспертов, hash-цепочка аннотаций (защита от подмены), CLI для разрешения конфликтов |
|
|
123
|
+
| **A/B-тесты** | Bootstrap CI, Wilcoxon, Cohen's d, интерпретация `not_significant` |
|
|
124
|
+
| **Адаптеры LLM** | YandexGPT, GigaChat, OpenAI-compatible (с явным opt-in под 152-ФЗ) |
|
|
125
|
+
| **PII-redaction** | Presidio + кастомные regex для РФ (ИНН, СНИЛС, паспорт, телефон, адрес), audit-лог без значений |
|
|
126
|
+
| **Prompt-injection фильтр** | Allowlist доменов + эвристики для retrieved-документов (RAG) |
|
|
127
|
+
| **Observability** | OTel-инструментация (spans, metrics, audit-logs) с redaction-middleware, SLO: eval-run p95 ≤ 300s, judge p95 ≤ 5000ms |
|
|
128
|
+
| **Отчёты** | Markdown / HTML с метриками, top-N ошибок, delta между прогонами |
|
|
129
|
+
| **CLI + Library API** | Typer CLI и Python API — одинаковый функционал |
|
|
130
|
+
|
|
131
|
+
## Архитектура
|
|
132
|
+
|
|
133
|
+
```mermaid
|
|
134
|
+
flowchart LR
|
|
135
|
+
CLI[CLI typer] --> Orch[EvalOrchestrator]
|
|
136
|
+
Lib[Library API] --> Orch
|
|
137
|
+
Orch --> DS[datasets<br/>loader + versioning]
|
|
138
|
+
Orch --> Sec[security<br/>pii_redactor + injection_filter]
|
|
139
|
+
Orch --> Ad[adapters<br/>yandexgpt / gigachat / openai]
|
|
140
|
+
Orch --> J[judges<br/>judge + calibration]
|
|
141
|
+
Orch --> M[metrics<br/>hallucination + citation]
|
|
142
|
+
Orch --> R[reports<br/>markdown + html]
|
|
143
|
+
J --> Sec
|
|
144
|
+
Ad --> Sec
|
|
145
|
+
Orch --> Obs[observability<br/>otel + redaction]
|
|
146
|
+
Human[Streamlit UI] --> J
|
|
147
|
+
Human --> Ann[annotation_store<br/>hash-chain]
|
|
148
|
+
Ann --> Orch
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 152-ФЗ и foreign providers
|
|
152
|
+
|
|
153
|
+
По умолчанию разрешены **только российские провайдеры** (YandexGPT, GigaChat) — они соответствуют 152-ФЗ. Для OpenAI-compatible требуется **двойной opt-in**:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
regulated-eval run \
|
|
157
|
+
--dataset tax_qa_v1@0.1.0 \
|
|
158
|
+
--model openai_compat \
|
|
159
|
+
--allow-foreign-provider \
|
|
160
|
+
--i-understand-152fz
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Или через env (для CI, с предупреждением в stderr):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
export REGULATED_EVAL_ALLOW_FOREIGN_PROVIDER=true
|
|
167
|
+
export REGULATED_EVAL_ACK_152FZ=true
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Каждое разрешение фиксируется в audit-логе `provider.foreign.allowed`. Подробнее — в [`docs/152fz.md`](docs/152fz.md).
|
|
171
|
+
|
|
172
|
+
## Метрики качества
|
|
173
|
+
|
|
174
|
+
| Метрика | Как считается | Целевое значение |
|
|
175
|
+
|---|---|---|
|
|
176
|
+
| `judge.calibration.kappa` | Cohen's kappa (judge vs эксперт) | ≥ 0.6 |
|
|
177
|
+
| `hallucination_rate` | LLM-judge + экспертный сэмпл | ниже baseline на ≥ 50% |
|
|
178
|
+
| `citation_accuracy` | Точное/частичное совпадение + judge | ≥ 0.9 для regulated-домена |
|
|
179
|
+
| `refusal_correctness` | Бинарная классификация | ≥ 0.95 |
|
|
180
|
+
| `judge.parse_error.rate` | Доля невалидных JSON от judge | ≤ 5% |
|
|
181
|
+
| `eval.run.duration` p95 | Histogram | ≤ 300s (150 вопросов) |
|
|
182
|
+
| `llm.request.duration{role=judge}` p95 | Histogram | ≤ 5000ms |
|
|
183
|
+
|
|
184
|
+
Полная методология — в [`docs/methodology.md`](docs/methodology.md).
|
|
185
|
+
|
|
186
|
+
## Структура репозитория
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
regulated-llm-eval/
|
|
190
|
+
├── README.md # этот файл
|
|
191
|
+
├── proposal.md # OpenSpec: why / what / impact
|
|
192
|
+
├── context.md # Traceability Matrix, принятые ADR
|
|
193
|
+
├── specs/eval-pipeline/spec.md # FR/NFR + Observability Contract
|
|
194
|
+
├── design/design.md # архитектура, потоки, точки инструментирования
|
|
195
|
+
├── threat-model/threat-model.md # STRIDE + OWASP LLM, 15 угроз, 9 Trust Boundaries
|
|
196
|
+
├── adr/ # 5 ADR (PII, allowlist, judge, OTel, hash-chain)
|
|
197
|
+
├── api/api-contract.yaml # CLI + Library API + JSON Schema
|
|
198
|
+
├── test-specs/eval-pipeline/tests.md # 64 теста, coverage matrix
|
|
199
|
+
├── tasks/tasks.md # 96 задач, ~191 SP
|
|
200
|
+
├── apply/apply.md # миграции, feature flags, observability verification
|
|
201
|
+
├── docs/
|
|
202
|
+
│ ├── PRD.md
|
|
203
|
+
│ ├── methodology.md
|
|
204
|
+
│ ├── case_study.md
|
|
205
|
+
│ └── 152fz.md
|
|
206
|
+
├── scripts/ # PowerShell-скрипты для генерации артефактов
|
|
207
|
+
├── datasets/
|
|
208
|
+
│ ├── tax_qa_v1/
|
|
209
|
+
│ └── calibration_v1/
|
|
210
|
+
└── src/regulated_eval/ # (реализация — по tasks.md)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Разработка
|
|
214
|
+
|
|
215
|
+
### Требования
|
|
216
|
+
|
|
217
|
+
- Python 3.11+
|
|
218
|
+
- Git
|
|
219
|
+
|
|
220
|
+
### Установка для разработки
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
git clone https://github.com/realrvs/regulated-llm-eval-framework.git
|
|
224
|
+
cd regulated-llm-eval-framework
|
|
225
|
+
|
|
226
|
+
python -m venv .venv
|
|
227
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
228
|
+
|
|
229
|
+
pip install -e ".[dev]"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Тесты
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
pytest --cov=regulated_eval --cov-report=term-missing
|
|
236
|
+
# Целевое покрытие: ≥ 80% для judges, metrics, ab, datasets
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Линтеры
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
ruff check .
|
|
243
|
+
mypy src/regulated_eval
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Roadmap
|
|
247
|
+
|
|
248
|
+
- [x] OpenSpec pipeline (proposal → specs → design → threat-model → adr → api-contract → test-specs → tasks → apply)
|
|
249
|
+
- [x] MVP implementation (Foundation, Datasets, Adapters, Security, Judges, Metrics, Pipeline, Reports)
|
|
250
|
+
- [x] Phase 6-10: Human-loop, A/B, Reports, Observability, Pipeline
|
|
251
|
+
- [ ] Phase 11: Tests (T-1101..T-1114)
|
|
252
|
+
- [ ] Phase 12: CI (T-1201..T-1205)
|
|
253
|
+
- [ ] Phase 13: Docs (T-1301..T-1305)
|
|
254
|
+
- [ ] Phase 14: Apply (T-1401..T-1403)
|
|
255
|
+
- [ ] v1.0.0 release (PyPI)
|
|
256
|
+
|
|
257
|
+
Полный план — в [`tasks/tasks.md`](tasks/tasks.md).
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
1. Fork → branch → PR.
|
|
262
|
+
2. Убедитесь, что `pytest --cov` ≥ 80% и `ruff check` / `mypy` зелёные.
|
|
263
|
+
3. Для security-изменений — обновите `threat-model.md` и добавьте тест с `TM Ref`.
|
|
264
|
+
4. Для observability-изменений — обновите Observability Contract в `spec.md` и `test-specs`.
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
MIT — см. [LICENSE](LICENSE).
|
|
269
|
+
|
|
270
|
+
## Security
|
|
271
|
+
|
|
272
|
+
See [SECURITY.md](SECURITY.md) for reporting vulnerabilities.
|