rti-ethics-engine 1.0.0__tar.gz → 2.0.1__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.
- rti_ethics_engine-2.0.1/INPUTS_OUTPUTS.md +62 -0
- rti_ethics_engine-2.0.1/PKG-INFO +166 -0
- rti_ethics_engine-2.0.1/README.md +108 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/pyproject.toml +5 -2
- rti_ethics_engine-2.0.1/rti_ethics_engine/__init__.py +180 -0
- rti_ethics_engine-2.0.1/rti_ethics_engine/calculators.py +1039 -0
- rti_ethics_engine-2.0.1/rti_ethics_engine/config.py +527 -0
- rti_ethics_engine-2.0.1/rti_ethics_engine/metrics.py +553 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/rti_ethics_engine/results.py +39 -16
- rti_ethics_engine-1.0.0/PKG-INFO +0 -198
- rti_ethics_engine-1.0.0/README.md +0 -141
- rti_ethics_engine-1.0.0/rti_ethics_engine/__init__.py +0 -73
- rti_ethics_engine-1.0.0/rti_ethics_engine/config.py +0 -169
- rti_ethics_engine-1.0.0/rti_ethics_engine/metrics.py +0 -52
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/.gitignore +0 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/LICENSE +0 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/rti_ethics_engine/core.py +0 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/rti_ethics_engine/dimensions.py +0 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/tests/__init__.py +0 -0
- {rti_ethics_engine-1.0.0 → rti_ethics_engine-2.0.1}/tests/test_engine.py +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# RTI Ethics Engine: Input & Output Specification
|
|
2
|
+
|
|
3
|
+
Detailed API reference for the package components.
|
|
4
|
+
|
|
5
|
+
## 1. Input: Metrics Dictionary Shape
|
|
6
|
+
|
|
7
|
+
The primary input to `evaluate(metrics)` is a nested dictionary structured by logical dimensions.
|
|
8
|
+
|
|
9
|
+
### Dimensions & Metric Keys
|
|
10
|
+
|
|
11
|
+
| Dimension | Key | L1 Metrics (Gates) | L2 Metrics (Risk) | L3 Metrics (Forensic) |
|
|
12
|
+
| ------------------ | ---------------- | ------------------------- | ---------------------- | --------------------- |
|
|
13
|
+
| **Fairness** | `fairness` | `spd`, `di`, `eop`, `aod` | `fnrd`, `refusal_disp` | `mutual_info` |
|
|
14
|
+
| **Drift** | `drift` | `psi`, `ks` | `pred_drift` | `embed_drift` |
|
|
15
|
+
| **Explainability** | `explainability` | `confidence` | `support_ratio` | `stability` |
|
|
16
|
+
| **Legal** | `legal` | `lawfulness`, `cvr` | `proportionality` | `explanation` |
|
|
17
|
+
| **Performance** | `performance` | `accuracy`, `recall` | `f1` | `group_f1` |
|
|
18
|
+
| **UX** | `ux` | `tcr`, `sla` | `cognitive_load` | `dtc` |
|
|
19
|
+
| **Security** | `security` | `adv_acc` | `pisr` | `mir` |
|
|
20
|
+
| **Monitoring** | `monitoring` | `alc` | `pvr` | `irf` |
|
|
21
|
+
| **Environment** | `environmental` | `inf_cost` | `gpu_hours` | `compute_intensity` |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. Dynamic Computation: `build_metrics_from_raw_data`
|
|
26
|
+
|
|
27
|
+
Used to convert raw arrays and runtime data into the metrics dictionary above.
|
|
28
|
+
|
|
29
|
+
### Parameters
|
|
30
|
+
|
|
31
|
+
| Name | Type | Description |
|
|
32
|
+
| ---------------------- | ------------ | ------------------------------------------- |
|
|
33
|
+
| `query` | `str` | User input string |
|
|
34
|
+
| `response` | `str` | AI response string |
|
|
35
|
+
| `predictions` | `np.ndarray` | Binary classification array (0/1) |
|
|
36
|
+
| `labels` | `np.ndarray` | Ground truth array (0/1) |
|
|
37
|
+
| `sensitive_attr` | `np.ndarray` | Sensitive group indicator (0/1) |
|
|
38
|
+
| `latency_ms` | `float` | Response time in milliseconds |
|
|
39
|
+
| `output_tokens` | `int` | Token count of AI response |
|
|
40
|
+
| `grounding_score` | `float` | Score from grounding judge (0-1) |
|
|
41
|
+
| `baseline_predictions` | `np.ndarray` | (Optional) Predictions for drift comparison |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 3. Output: `EthicsResult` Schema
|
|
46
|
+
|
|
47
|
+
The object returned by evaluation gives detailed access to the 3-layer audit results.
|
|
48
|
+
|
|
49
|
+
### Summary Fields
|
|
50
|
+
|
|
51
|
+
- `final_label`: `ETHICAL` (Pass), `CONDITIONALLY_ETHICAL` (Review), `UNETHICAL` (Block)
|
|
52
|
+
- `s_llm`: Balanced audit score [0 to 1]
|
|
53
|
+
- `risk_band`: `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`
|
|
54
|
+
- `layer1_status`: `PASS` (All gates green) or `FAIL`
|
|
55
|
+
|
|
56
|
+
### Accessor Methods
|
|
57
|
+
|
|
58
|
+
- `get_l1_metric(dim, key)`: Returns raw float value (e.g., `0.021`)
|
|
59
|
+
- `get_l2_risk(dim)`: Returns normalized risk [0 to 1]
|
|
60
|
+
- `get_l3_evidence(dim)`: Returns forensic explanation string or dictionary
|
|
61
|
+
- `get_failed_dims()`: List of dimension names that failed L1 gates
|
|
62
|
+
- `to_json()`: Serializes the entire audit trail to JSON
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rti-ethics-engine
|
|
3
|
+
Version: 2.0.1
|
|
4
|
+
Summary: India's first granular AI ethics framework for RTI applications (36 metrics, 9 dimensions)
|
|
5
|
+
Project-URL: Homepage, https://github.com/rti-ethics/rti-ethics-engine
|
|
6
|
+
Project-URL: Documentation, https://rti-ethics-engine.readthedocs.io
|
|
7
|
+
Project-URL: Repository, https://github.com/rti-ethics/rti-ethics-engine
|
|
8
|
+
Project-URL: Issues, https://github.com/rti-ethics/rti-ethics-engine/issues
|
|
9
|
+
Author: RTI Ethics Engine Team
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 RTI Ethics Engine Team
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: ai-ethics,audit,compliance,fairness,government,india,llm,rti
|
|
33
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Intended Audience :: Science/Research
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
44
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
45
|
+
Requires-Python: >=3.9
|
|
46
|
+
Requires-Dist: numpy>=1.24.0
|
|
47
|
+
Requires-Dist: scipy>=1.10.0
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: black>=23.0; extra == 'dev'
|
|
50
|
+
Requires-Dist: mypy>=1.0; extra == 'dev'
|
|
51
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
52
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
53
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
54
|
+
Provides-Extra: docs
|
|
55
|
+
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
|
|
56
|
+
Requires-Dist: sphinx>=5.0; extra == 'docs'
|
|
57
|
+
Description-Content-Type: text/markdown
|
|
58
|
+
|
|
59
|
+
# RTI Ethics Engine (v2.0.0)
|
|
60
|
+
|
|
61
|
+
**India's first granular AI ethics framework for RTI applications** - A production-ready Python package implementing 36 metrics across 9 ethical dimensions with granular formula access and dynamic data computation.
|
|
62
|
+
|
|
63
|
+
[](https://www.python.org/downloads/)
|
|
64
|
+
[](https://opensource.org/licenses/MIT)
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🚀 Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install rti-ethics-engine
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## ⚡ Quick Start (Dynamic Mode)
|
|
75
|
+
|
|
76
|
+
The recommended way to use the engine is to compute metrics directly from your application data:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import numpy as np
|
|
80
|
+
from rti_ethics_engine import evaluate_from_raw
|
|
81
|
+
|
|
82
|
+
# 1. Prepare your data
|
|
83
|
+
query = "What is the budget for the Metro project?"
|
|
84
|
+
response = "The budget for the Metro project is 5000 Crores..."
|
|
85
|
+
predictions = np.array([1, 1, 0, 1]) # Model predictions
|
|
86
|
+
labels = np.array([1, 1, 1, 1]) # Ground truth
|
|
87
|
+
sensitive_attr = np.array([0, 1, 0, 1]) # Demographic group (e.g. Urban/Rural)
|
|
88
|
+
|
|
89
|
+
# 2. Evaluate with one call
|
|
90
|
+
result = evaluate_from_raw(
|
|
91
|
+
query=query,
|
|
92
|
+
response=response,
|
|
93
|
+
predictions=predictions,
|
|
94
|
+
labels=labels,
|
|
95
|
+
sensitive_attr=sensitive_attr,
|
|
96
|
+
latency_ms=450.0,
|
|
97
|
+
grounding_score=0.92
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# 3. Get results
|
|
101
|
+
print(f"Label: {result.final_label}") # "ETHICAL"
|
|
102
|
+
print(f"S_LLM Score: {result.s_llm}") # 0.942
|
|
103
|
+
print(f"Risk Band: {result.risk_band}") # "LOW"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 📊 The 3-Layer Audit Protocol
|
|
107
|
+
|
|
108
|
+
The RTI Ethics Engine uses a rigorous 3-layer protocol for every dimension:
|
|
109
|
+
|
|
110
|
+
1. **Layer 1: Hard Gates (L1)** - Pass/Fail compliance checks (e.g., Statistical Parity < 0.1).
|
|
111
|
+
2. **Layer 2: Risk Scoring (L2)** - Normalized risk vectors weighted by policy importance.
|
|
112
|
+
3. **Layer 3: Forensic Evidence (L3)** - Detailed context and reasoning for the scores.
|
|
113
|
+
|
|
114
|
+
### Granular Access
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Check if a specific dimension passed its hard gates
|
|
118
|
+
if result.get_l1_status("fairness") == "FAIL":
|
|
119
|
+
print(f"Fairness fail reasons: {result.get_l1_reasons('fairness')}")
|
|
120
|
+
|
|
121
|
+
# Get granular metric values (36 metrics available)
|
|
122
|
+
spd = result.get_l1_metric("fairness", "spd")
|
|
123
|
+
psi = result.get_l1_metric("drift", "psi")
|
|
124
|
+
|
|
125
|
+
# Export complete audit trail
|
|
126
|
+
audit_json = result.to_json()
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 🏗️ 9 Ethical Dimensions
|
|
130
|
+
|
|
131
|
+
| Dimension | Description | Key Metrics |
|
|
132
|
+
| -------------------- | ------------------------------------ | ------------------------------- |
|
|
133
|
+
| **Legal Compliance** | RTI Act 2005 & Data Policy alignment | Lawfulness, Consent Validity |
|
|
134
|
+
| **Bias & Fairness** | Demographic equity across groups | SPD, DI, EOP, AOD |
|
|
135
|
+
| **Explainability** | Transparency & Model Confidence | FI Sum, Counterfactual Distance |
|
|
136
|
+
| **Security** | Robustness against prompt injection | PISR, Adversarial Accuracy |
|
|
137
|
+
| **Monitoring** | Audit trail & SLA integrity | Audit Completeness, SLA rate |
|
|
138
|
+
| **Performance** | Statistical accuracy of responses | Recall, Group-F1, Accuracy |
|
|
139
|
+
| **Human-AI UX** | User friction and frustration levels | TCR, Cognitive Load |
|
|
140
|
+
| **Drift** | Model/Data stability over time | PSI, KS-Statistic |
|
|
141
|
+
| **Environment** | Carbon footprint & compute cost | GPU Hours, Inference Cost |
|
|
142
|
+
|
|
143
|
+
## 📖 Documentation
|
|
144
|
+
|
|
145
|
+
For detailed input/output schemas and advanced configuration, see:
|
|
146
|
+
|
|
147
|
+
- [API Reference (INPUTS_OUTPUTS.md)](https://github.com/Krishil-Parikh/bazinga_tsec_hacks/blob/krishil/rti_ethics_engine/INPUTS_OUTPUTS.md)
|
|
148
|
+
- [Mathematical Manifest (calculators.py)](https://github.com/Krishil-Parikh/bazinga_tsec_hacks/blob/krishil/rti_ethics_engine/rti_ethics_engine/calculators.py)
|
|
149
|
+
|
|
150
|
+
## 🧪 Testing
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pytest tests/ -v
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 🇮🇳 Why RTI Ethics Engine?
|
|
157
|
+
|
|
158
|
+
Designed specifically for **Right to Information (RTI)** workflows, it ensures that AI systems responding to citizen queries are:
|
|
159
|
+
|
|
160
|
+
- **Legally Sound:** Compliant with Section 4/8 of the RTI Act.
|
|
161
|
+
- **Fair:** No bias between rural/urban or language variations.
|
|
162
|
+
- **Auditable:** Providing forensic evidence for Central Information Commission (CIC) audits.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
**License:** MIT | **Support:** [github.com/rti-ethics/rti-ethics-engine](https://github.com/rti-ethics/rti-ethics-engine)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# RTI Ethics Engine (v2.0.0)
|
|
2
|
+
|
|
3
|
+
**India's first granular AI ethics framework for RTI applications** - A production-ready Python package implementing 36 metrics across 9 ethical dimensions with granular formula access and dynamic data computation.
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 🚀 Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install rti-ethics-engine
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## ⚡ Quick Start (Dynamic Mode)
|
|
17
|
+
|
|
18
|
+
The recommended way to use the engine is to compute metrics directly from your application data:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import numpy as np
|
|
22
|
+
from rti_ethics_engine import evaluate_from_raw
|
|
23
|
+
|
|
24
|
+
# 1. Prepare your data
|
|
25
|
+
query = "What is the budget for the Metro project?"
|
|
26
|
+
response = "The budget for the Metro project is 5000 Crores..."
|
|
27
|
+
predictions = np.array([1, 1, 0, 1]) # Model predictions
|
|
28
|
+
labels = np.array([1, 1, 1, 1]) # Ground truth
|
|
29
|
+
sensitive_attr = np.array([0, 1, 0, 1]) # Demographic group (e.g. Urban/Rural)
|
|
30
|
+
|
|
31
|
+
# 2. Evaluate with one call
|
|
32
|
+
result = evaluate_from_raw(
|
|
33
|
+
query=query,
|
|
34
|
+
response=response,
|
|
35
|
+
predictions=predictions,
|
|
36
|
+
labels=labels,
|
|
37
|
+
sensitive_attr=sensitive_attr,
|
|
38
|
+
latency_ms=450.0,
|
|
39
|
+
grounding_score=0.92
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# 3. Get results
|
|
43
|
+
print(f"Label: {result.final_label}") # "ETHICAL"
|
|
44
|
+
print(f"S_LLM Score: {result.s_llm}") # 0.942
|
|
45
|
+
print(f"Risk Band: {result.risk_band}") # "LOW"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📊 The 3-Layer Audit Protocol
|
|
49
|
+
|
|
50
|
+
The RTI Ethics Engine uses a rigorous 3-layer protocol for every dimension:
|
|
51
|
+
|
|
52
|
+
1. **Layer 1: Hard Gates (L1)** - Pass/Fail compliance checks (e.g., Statistical Parity < 0.1).
|
|
53
|
+
2. **Layer 2: Risk Scoring (L2)** - Normalized risk vectors weighted by policy importance.
|
|
54
|
+
3. **Layer 3: Forensic Evidence (L3)** - Detailed context and reasoning for the scores.
|
|
55
|
+
|
|
56
|
+
### Granular Access
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# Check if a specific dimension passed its hard gates
|
|
60
|
+
if result.get_l1_status("fairness") == "FAIL":
|
|
61
|
+
print(f"Fairness fail reasons: {result.get_l1_reasons('fairness')}")
|
|
62
|
+
|
|
63
|
+
# Get granular metric values (36 metrics available)
|
|
64
|
+
spd = result.get_l1_metric("fairness", "spd")
|
|
65
|
+
psi = result.get_l1_metric("drift", "psi")
|
|
66
|
+
|
|
67
|
+
# Export complete audit trail
|
|
68
|
+
audit_json = result.to_json()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 🏗️ 9 Ethical Dimensions
|
|
72
|
+
|
|
73
|
+
| Dimension | Description | Key Metrics |
|
|
74
|
+
| -------------------- | ------------------------------------ | ------------------------------- |
|
|
75
|
+
| **Legal Compliance** | RTI Act 2005 & Data Policy alignment | Lawfulness, Consent Validity |
|
|
76
|
+
| **Bias & Fairness** | Demographic equity across groups | SPD, DI, EOP, AOD |
|
|
77
|
+
| **Explainability** | Transparency & Model Confidence | FI Sum, Counterfactual Distance |
|
|
78
|
+
| **Security** | Robustness against prompt injection | PISR, Adversarial Accuracy |
|
|
79
|
+
| **Monitoring** | Audit trail & SLA integrity | Audit Completeness, SLA rate |
|
|
80
|
+
| **Performance** | Statistical accuracy of responses | Recall, Group-F1, Accuracy |
|
|
81
|
+
| **Human-AI UX** | User friction and frustration levels | TCR, Cognitive Load |
|
|
82
|
+
| **Drift** | Model/Data stability over time | PSI, KS-Statistic |
|
|
83
|
+
| **Environment** | Carbon footprint & compute cost | GPU Hours, Inference Cost |
|
|
84
|
+
|
|
85
|
+
## 📖 Documentation
|
|
86
|
+
|
|
87
|
+
For detailed input/output schemas and advanced configuration, see:
|
|
88
|
+
|
|
89
|
+
- [API Reference (INPUTS_OUTPUTS.md)](https://github.com/Krishil-Parikh/bazinga_tsec_hacks/blob/krishil/rti_ethics_engine/INPUTS_OUTPUTS.md)
|
|
90
|
+
- [Mathematical Manifest (calculators.py)](https://github.com/Krishil-Parikh/bazinga_tsec_hacks/blob/krishil/rti_ethics_engine/rti_ethics_engine/calculators.py)
|
|
91
|
+
|
|
92
|
+
## 🧪 Testing
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pytest tests/ -v
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 🇮🇳 Why RTI Ethics Engine?
|
|
99
|
+
|
|
100
|
+
Designed specifically for **Right to Information (RTI)** workflows, it ensures that AI systems responding to citizen queries are:
|
|
101
|
+
|
|
102
|
+
- **Legally Sound:** Compliant with Section 4/8 of the RTI Act.
|
|
103
|
+
- **Fair:** No bias between rural/urban or language variations.
|
|
104
|
+
- **Auditable:** Providing forensic evidence for Central Information Commission (CIC) audits.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
**License:** MIT | **Support:** [github.com/rti-ethics/rti-ethics-engine](https://github.com/rti-ethics/rti-ethics-engine)
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rti-ethics-engine"
|
|
7
|
-
version = "
|
|
7
|
+
version = "2.0.1"
|
|
8
8
|
description = "India's first granular AI ethics framework for RTI applications (36 metrics, 9 dimensions)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {file = "LICENSE"}
|
|
@@ -37,7 +37,8 @@ classifiers = [
|
|
|
37
37
|
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
38
38
|
]
|
|
39
39
|
dependencies = [
|
|
40
|
-
"numpy>=1.24.0"
|
|
40
|
+
"numpy>=1.24.0",
|
|
41
|
+
"scipy>=1.10.0"
|
|
41
42
|
]
|
|
42
43
|
|
|
43
44
|
[project.optional-dependencies]
|
|
@@ -61,12 +62,14 @@ Issues = "https://github.com/rti-ethics/rti-ethics-engine/issues"
|
|
|
61
62
|
|
|
62
63
|
[tool.hatch.build.targets.wheel]
|
|
63
64
|
packages = ["rti_ethics_engine"]
|
|
65
|
+
include = ["INPUTS_OUTPUTS.md"]
|
|
64
66
|
|
|
65
67
|
[tool.hatch.build.targets.sdist]
|
|
66
68
|
include = [
|
|
67
69
|
"/rti_ethics_engine",
|
|
68
70
|
"/tests",
|
|
69
71
|
"/README.md",
|
|
72
|
+
"/INPUTS_OUTPUTS.md",
|
|
70
73
|
"/LICENSE"
|
|
71
74
|
]
|
|
72
75
|
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""
|
|
2
|
+
RTI Ethics Engine - Production AI Ethics Framework for RTI Applications
|
|
3
|
+
India's first granular 9-dimension AI ethics evaluator (36 metrics)
|
|
4
|
+
|
|
5
|
+
ALL METRICS COMPUTED DYNAMICALLY FROM DATA - NO HARDCODED VALUES.
|
|
6
|
+
|
|
7
|
+
Quick Start:
|
|
8
|
+
from rti_ethics_engine import evaluate
|
|
9
|
+
|
|
10
|
+
metrics = {
|
|
11
|
+
"fairness": {"spd": 0.02, "di": 1.0, "eop": 0.05, "aod": 0.03},
|
|
12
|
+
"legal": {"lawfulness": 1.0, "cvr": 0.98},
|
|
13
|
+
# ... other dimensions
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
result = evaluate(metrics)
|
|
17
|
+
print(result.final_label) # "ETHICAL"
|
|
18
|
+
print(result.s_llm) # 0.92
|
|
19
|
+
|
|
20
|
+
# Granular access
|
|
21
|
+
print(result.get_l1_metric("fairness", "spd")) # 0.02
|
|
22
|
+
print(result.get_failed_dims()) # []
|
|
23
|
+
|
|
24
|
+
Dynamic Metrics (compute from raw data):
|
|
25
|
+
from rti_ethics_engine import build_metrics_from_raw_data, MetricCalculator
|
|
26
|
+
|
|
27
|
+
# Build metrics from actual data
|
|
28
|
+
metrics = build_metrics_from_raw_data(
|
|
29
|
+
query="What is Section 4?",
|
|
30
|
+
response="Section 4 requires...",
|
|
31
|
+
predictions=np.array([1, 0, 1]),
|
|
32
|
+
labels=np.array([1, 1, 0]),
|
|
33
|
+
sensitive_attr=np.array([0, 1, 1]),
|
|
34
|
+
latency_ms=500.0
|
|
35
|
+
)
|
|
36
|
+
result = evaluate(metrics)
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from .core import EthicsEngine
|
|
40
|
+
from .results import EthicsResult, DimensionResult, RiskBand, FinalLabel
|
|
41
|
+
from .config import (
|
|
42
|
+
# Backwards-compatible static exports
|
|
43
|
+
L1_THRESHOLDS,
|
|
44
|
+
DIMENSION_WEIGHTS,
|
|
45
|
+
RISK_THRESHOLDS,
|
|
46
|
+
DIMENSION_INFO,
|
|
47
|
+
METRIC_CATALOG,
|
|
48
|
+
# Dynamic config functions
|
|
49
|
+
get_l1_thresholds,
|
|
50
|
+
get_dimension_weights,
|
|
51
|
+
get_risk_thresholds,
|
|
52
|
+
get_config_from_data,
|
|
53
|
+
get_similarity_function,
|
|
54
|
+
generate_columns_from_formulas,
|
|
55
|
+
reset_config,
|
|
56
|
+
DynamicConfigLoader
|
|
57
|
+
)
|
|
58
|
+
from .metrics import (
|
|
59
|
+
build_default_metrics,
|
|
60
|
+
build_metrics_from_raw_data,
|
|
61
|
+
compute_fairness_from_data,
|
|
62
|
+
compute_drift_from_data,
|
|
63
|
+
compute_environmental_from_data,
|
|
64
|
+
compute_ux_from_text,
|
|
65
|
+
compute_legal_from_response,
|
|
66
|
+
compute_performance_from_data,
|
|
67
|
+
compute_monitoring_from_data,
|
|
68
|
+
compute_security_from_data,
|
|
69
|
+
compute_explainability_from_data,
|
|
70
|
+
test_dynamic_formulas
|
|
71
|
+
)
|
|
72
|
+
from .calculators import (
|
|
73
|
+
# Individual metric calculators
|
|
74
|
+
compute_spd, compute_di, compute_eop, compute_aod,
|
|
75
|
+
compute_fnrd, compute_refusal_disparity, compute_mutual_info_leakage,
|
|
76
|
+
compute_psi, compute_ks_statistic, compute_prediction_drift,
|
|
77
|
+
compute_inference_cost, compute_gpu_hours,
|
|
78
|
+
compute_readability_fk, compute_cognitive_load,
|
|
79
|
+
compute_accuracy, compute_recall, compute_f1, compute_group_f1,
|
|
80
|
+
# Master calculator class
|
|
81
|
+
MetricCalculator
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
__version__ = "2.0.1" # Major version bump for dynamic computation
|
|
85
|
+
__author__ = "RTI Ethics Engine Team"
|
|
86
|
+
__license__ = "MIT"
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
# Core classes
|
|
90
|
+
"EthicsEngine",
|
|
91
|
+
"EthicsResult",
|
|
92
|
+
"DimensionResult",
|
|
93
|
+
"MetricCalculator",
|
|
94
|
+
# Enums
|
|
95
|
+
"RiskBand",
|
|
96
|
+
"FinalLabel",
|
|
97
|
+
# Config (static - backwards compatible)
|
|
98
|
+
"L1_THRESHOLDS",
|
|
99
|
+
"DIMENSION_WEIGHTS",
|
|
100
|
+
"RISK_THRESHOLDS",
|
|
101
|
+
"DIMENSION_INFO",
|
|
102
|
+
"METRIC_CATALOG",
|
|
103
|
+
# Config (dynamic)
|
|
104
|
+
"get_l1_thresholds",
|
|
105
|
+
"get_dimension_weights",
|
|
106
|
+
"get_risk_thresholds",
|
|
107
|
+
"get_config_from_data",
|
|
108
|
+
"get_similarity_function",
|
|
109
|
+
"generate_columns_from_formulas",
|
|
110
|
+
"reset_config",
|
|
111
|
+
"DynamicConfigLoader",
|
|
112
|
+
# Metric builders
|
|
113
|
+
"build_default_metrics",
|
|
114
|
+
"build_metrics_from_raw_data",
|
|
115
|
+
"compute_fairness_from_data",
|
|
116
|
+
"compute_drift_from_data",
|
|
117
|
+
"compute_environmental_from_data",
|
|
118
|
+
"compute_ux_from_text",
|
|
119
|
+
"compute_legal_from_response",
|
|
120
|
+
"compute_performance_from_data",
|
|
121
|
+
"compute_monitoring_from_data",
|
|
122
|
+
"compute_security_from_data",
|
|
123
|
+
"compute_explainability_from_data",
|
|
124
|
+
# Individual calculators
|
|
125
|
+
"compute_spd", "compute_di", "compute_eop", "compute_aod",
|
|
126
|
+
"compute_fnrd", "compute_mutual_info_leakage",
|
|
127
|
+
"compute_psi", "compute_ks_statistic",
|
|
128
|
+
"compute_accuracy", "compute_recall", "compute_f1",
|
|
129
|
+
"compute_readability_fk",
|
|
130
|
+
# Helpers
|
|
131
|
+
"evaluate",
|
|
132
|
+
"test_dynamic_formulas",
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def evaluate(metrics: dict) -> EthicsResult:
|
|
137
|
+
"""
|
|
138
|
+
Quick evaluation entrypoint.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
metrics: Dict of dimension -> metrics mapping.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
EthicsResult with complete evaluation and granular accessors.
|
|
145
|
+
|
|
146
|
+
Example:
|
|
147
|
+
result = evaluate({"fairness": {"spd": 0.02}, "legal": {"lawfulness": 1.0}})
|
|
148
|
+
print(result.final_label) # "ETHICAL"
|
|
149
|
+
"""
|
|
150
|
+
engine = EthicsEngine()
|
|
151
|
+
return engine.run_protocol(metrics)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def evaluate_from_raw(
|
|
155
|
+
query: str,
|
|
156
|
+
response: str,
|
|
157
|
+
**kwargs
|
|
158
|
+
) -> EthicsResult:
|
|
159
|
+
"""
|
|
160
|
+
Evaluate ethics directly from raw data (no pre-computed metrics needed).
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
query: User query text
|
|
164
|
+
response: LLM response text
|
|
165
|
+
**kwargs: Additional data (predictions, labels, sensitive_attr, latency_ms, etc.)
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
EthicsResult with complete evaluation
|
|
169
|
+
|
|
170
|
+
Example:
|
|
171
|
+
result = evaluate_from_raw(
|
|
172
|
+
query="What is Section 4 of RTI?",
|
|
173
|
+
response="Section 4 mandates proactive disclosure...",
|
|
174
|
+
latency_ms=500,
|
|
175
|
+
grounding_score=0.9
|
|
176
|
+
)
|
|
177
|
+
print(result.final_label)
|
|
178
|
+
"""
|
|
179
|
+
metrics = build_metrics_from_raw_data(query, response, **kwargs)
|
|
180
|
+
return evaluate(metrics)
|