fairsense-agentix 0.1.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.
- fairsense_agentix-0.1.0/.gitignore +46 -0
- fairsense_agentix-0.1.0/LICENSE +21 -0
- fairsense_agentix-0.1.0/PKG-INFO +226 -0
- fairsense_agentix-0.1.0/README.md +176 -0
- fairsense_agentix-0.1.0/fairsense_agentix/__init__.py +73 -0
- fairsense_agentix-0.1.0/fairsense_agentix/api.py +398 -0
- fairsense_agentix-0.1.0/fairsense_agentix/configs/__init__.py +6 -0
- fairsense_agentix-0.1.0/fairsense_agentix/configs/settings.py +536 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/risks/index.faiss +0 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/risks/index.pkl +0 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/risks_meta.json +9382 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/rmf/index.faiss +0 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/rmf/index.pkl +0 -0
- fairsense_agentix-0.1.0/fairsense_agentix/data/indexes/rmf_meta.json +36612 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/__init__.py +40 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/bias_image_graph.py +968 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/bias_image_vlm_graph.py +486 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/bias_text_graph.py +652 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/orchestrator_graph.py +956 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/risk_graph.py +534 -0
- fairsense_agentix-0.1.0/fairsense_agentix/graphs/state.py +578 -0
- fairsense_agentix-0.1.0/fairsense_agentix/logging_config.py +61 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/__init__.py +18 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/prompt_loader.py +180 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/bias_analysis_v1.txt +59 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/bias_evaluator_v1.txt +34 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/bias_image_v1.txt +81 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/bias_text_v1.txt +50 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/bias_visual_analysis_v1.txt +182 -0
- fairsense_agentix-0.1.0/fairsense_agentix/prompts/templates/summarize_v1.txt +24 -0
- fairsense_agentix-0.1.0/fairsense_agentix/schemas.py +213 -0
- fairsense_agentix-0.1.0/fairsense_agentix/server/__init__.py +43 -0
- fairsense_agentix-0.1.0/fairsense_agentix/server/launcher.py +613 -0
- fairsense_agentix-0.1.0/fairsense_agentix/service_api/__init__.py +1 -0
- fairsense_agentix-0.1.0/fairsense_agentix/service_api/schemas.py +99 -0
- fairsense_agentix-0.1.0/fairsense_agentix/service_api/server.py +456 -0
- fairsense_agentix-0.1.0/fairsense_agentix/service_api/utils.py +59 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/__init__.py +24 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/cache.py +440 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/evaluator.py +702 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/event_bus.py +51 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/router.py +325 -0
- fairsense_agentix-0.1.0/fairsense_agentix/services/telemetry.py +388 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/__init__.py +117 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/caption/__init__.py +24 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/caption/blip2_tool.py +362 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/caption/blip_tool.py +383 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/embeddings/__init__.py +17 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/embeddings/langchain_embedder.py +297 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/embeddings/sentence_transformer_embedder.py +224 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/exceptions.py +194 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/faiss_index/__init__.py +16 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/faiss_index/faiss_index_tool.py +337 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/faiss_index/langchain_faiss_tool.py +545 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/fake.py +652 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/formatter/__init__.py +29 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/formatter/html_formatter.py +783 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/interfaces.py +619 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/llm/__init__.py +53 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/llm/callbacks.py +266 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/llm/langchain_adapter.py +310 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/llm/output_schemas.py +264 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/ocr/__init__.py +24 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/ocr/paddleocr_tool.py +291 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/ocr/tesseract_tool.py +221 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/persistence/__init__.py +29 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/persistence/file_writer.py +365 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/registry.py +285 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/__init__.py +27 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/caption.py +127 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/embedder.py +75 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/faiss_index.py +90 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/formatter.py +42 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/llm.py +199 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/ocr.py +121 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/persistence.py +40 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/summarizer.py +111 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/resolvers/vlm.py +92 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/summarizer/__init__.py +28 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/summarizer/llm_summarizer.py +255 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/vlm/__init__.py +36 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/vlm/fake_vlm_tool.py +149 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/vlm/output_schemas.py +64 -0
- fairsense_agentix-0.1.0/fairsense_agentix/tools/vlm/unified_vlm_tool.py +389 -0
- fairsense_agentix-0.1.0/pyproject.toml +213 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv
|
|
11
|
+
|
|
12
|
+
# Lint & Test
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
.pytest_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
|
|
17
|
+
# Vscode
|
|
18
|
+
.vscode
|
|
19
|
+
|
|
20
|
+
# macos
|
|
21
|
+
*.DS_Store
|
|
22
|
+
|
|
23
|
+
# Claude Files
|
|
24
|
+
CLAUDE.md
|
|
25
|
+
*.faiss
|
|
26
|
+
*.index
|
|
27
|
+
*.json
|
|
28
|
+
*.csv
|
|
29
|
+
# BUT: Allow package data files
|
|
30
|
+
!fairsense_agentix/data/**/*.faiss
|
|
31
|
+
!fairsense_agentix/data/**/*.pkl
|
|
32
|
+
!fairsense_agentix/data/**/*.json
|
|
33
|
+
# Allow UI package manifest and lockfile (reproducible npm install)
|
|
34
|
+
!ui/package.json
|
|
35
|
+
!ui/package-lock.json
|
|
36
|
+
data/indexes/*.json
|
|
37
|
+
data/indexes/README.md
|
|
38
|
+
.env
|
|
39
|
+
.cache/langchain.db
|
|
40
|
+
run_demo.sh
|
|
41
|
+
test_demo.py
|
|
42
|
+
demo_simple.py
|
|
43
|
+
*/node_modules
|
|
44
|
+
/UI_images
|
|
45
|
+
*.js
|
|
46
|
+
*.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vector Institute
|
|
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,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fairsense-agentix
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An agentic fairness and AI-risk analysis platform for detecting bias in text and images
|
|
5
|
+
Project-URL: Homepage, https://github.com/VectorInstitute/fairsense-AgentiX
|
|
6
|
+
Project-URL: Documentation, https://vectorinstitute.github.io/fairsense-AgentiX/
|
|
7
|
+
Project-URL: Repository, https://github.com/VectorInstitute/fairsense-AgentiX
|
|
8
|
+
Project-URL: Issues, https://github.com/VectorInstitute/fairsense-AgentiX/issues
|
|
9
|
+
Author-email: Vector AI Engineering <ai_engineering@vectorinstitute.ai>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Framework :: Pydantic :: 2
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Requires-Dist: accelerate>=0.20.0
|
|
25
|
+
Requires-Dist: faiss-cpu>=1.7.4
|
|
26
|
+
Requires-Dist: fastapi>=0.115.0
|
|
27
|
+
Requires-Dist: langchain-anthropic>=0.2.0
|
|
28
|
+
Requires-Dist: langchain-community>=0.3.0
|
|
29
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
30
|
+
Requires-Dist: langchain-huggingface>=0.1.0
|
|
31
|
+
Requires-Dist: langchain-openai>=0.2.0
|
|
32
|
+
Requires-Dist: langchain>=0.3.0
|
|
33
|
+
Requires-Dist: langgraph>=0.2.56
|
|
34
|
+
Requires-Dist: numpy>=1.24.0
|
|
35
|
+
Requires-Dist: paddleocr>=2.7.0
|
|
36
|
+
Requires-Dist: pandas>=2.0.0
|
|
37
|
+
Requires-Dist: pillow>=10.0.0
|
|
38
|
+
Requires-Dist: pydantic-settings>=2.7.1
|
|
39
|
+
Requires-Dist: pydantic>=2.10.6
|
|
40
|
+
Requires-Dist: pytesseract>=0.3.10
|
|
41
|
+
Requires-Dist: python-multipart>=0.0.9
|
|
42
|
+
Requires-Dist: requests>=2.31.0
|
|
43
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
44
|
+
Requires-Dist: tiktoken<0.12.0,>=0.7.0
|
|
45
|
+
Requires-Dist: torch<2.6.0,>=2.0.0
|
|
46
|
+
Requires-Dist: transformers>=4.35.0
|
|
47
|
+
Requires-Dist: uvicorn>=0.30.0
|
|
48
|
+
Requires-Dist: websockets>=15.0.1
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# FairSense-AgentiX
|
|
52
|
+
|
|
53
|
+
**An agentic fairness and AI-risk analysis platform developed by the [Vector Institute](https://vectorinstitute.ai/).**
|
|
54
|
+
|
|
55
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/code_checks.yml)
|
|
56
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/integration_tests.yml)
|
|
57
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/docs.yml)
|
|
58
|
+
[](https://codecov.io/github/VectorInstitute/fairsense-AgentiX)
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
FairSense-AgentiX is an intelligent bias detection and risk assessment platform that uses **agentic AI workflows** to analyze text, images, and datasets for fairness concerns. Unlike traditional ML classifiers, FairSense employs a reasoning agent that plans, selects tools, critiques outputs, and refines them iteratively.
|
|
64
|
+
|
|
65
|
+
## ✨ Key Features
|
|
66
|
+
|
|
67
|
+
- 🤖 **Agentic Reasoning** - ReAct loop with dynamic tool selection and self-critique
|
|
68
|
+
- 🔍 **Multi-Modal Analysis** - Text bias detection, image bias detection, and AI risk assessment
|
|
69
|
+
- 🛠️ **Flexible Tool Ecosystem** - OCR, Vision-Language Models, embeddings, FAISS, and LLMs
|
|
70
|
+
- 🌐 **Production-Ready APIs** - FastAPI REST API + WebSocket streaming + React UI
|
|
71
|
+
- ⚙️ **Highly Configurable** - Swap LLM providers, tools, and models on the fly
|
|
72
|
+
|
|
73
|
+
## 📦 Installation
|
|
74
|
+
|
|
75
|
+
### From PyPI (Recommended)
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install fairsense-agentix
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### From Source
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/VectorInstitute/fairsense-AgentiX.git
|
|
85
|
+
cd fairsense-AgentiX
|
|
86
|
+
uv sync
|
|
87
|
+
source .venv/bin/activate
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Requirements
|
|
91
|
+
|
|
92
|
+
- **Python 3.12+**
|
|
93
|
+
- **4GB+ RAM** (for ML models)
|
|
94
|
+
- **API key** for OpenAI or Anthropic (for LLM functionality)
|
|
95
|
+
|
|
96
|
+
## 🚀 Quick Start
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from fairsense_agentix import FairSense
|
|
100
|
+
|
|
101
|
+
# Initialize the engine
|
|
102
|
+
engine = FairSense()
|
|
103
|
+
|
|
104
|
+
# Analyze text for bias
|
|
105
|
+
result = engine.analyze_text(
|
|
106
|
+
"We're looking for a young, energetic developer to join our startup team."
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
print(f"Bias detected: {result.bias_detected}")
|
|
110
|
+
print(f"Risk level: {result.risk_level}")
|
|
111
|
+
for instance in result.bias_instances:
|
|
112
|
+
print(f" - {instance['type']} ({instance['severity']}): {instance['text_span']}")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Full Documentation:** [https://vectorinstitute.github.io/fairsense-AgentiX/](https://vectorinstitute.github.io/fairsense-AgentiX/)
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 🧑🏿💻 Developing
|
|
120
|
+
|
|
121
|
+
### Installing dependencies
|
|
122
|
+
|
|
123
|
+
The development environment can be set up using
|
|
124
|
+
[uv](https://github.com/astral-sh/uv?tab=readme-ov-file#installation). Hence, make sure it is
|
|
125
|
+
installed and then run:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uv sync
|
|
129
|
+
source .venv/bin/activate
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In order to install dependencies for testing (codestyle, unit tests, integration tests),
|
|
133
|
+
run:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
uv sync --dev
|
|
137
|
+
source .venv/bin/activate
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
In order to exclude installation of packages from a specific group (e.g. docs),
|
|
141
|
+
run:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
uv sync --no-group docs
|
|
145
|
+
```
|
|
146
|
+
## Getting Started
|
|
147
|
+
|
|
148
|
+
### Run the FastAPI service
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
uv run uvicorn fairsense_agentix.service_api.server:app --reload
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Endpoints (all under `/v1/...`):
|
|
155
|
+
|
|
156
|
+
| Route | Description |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| `POST /analyze` | JSON payload with `content`, optional `input_type`, `options` |
|
|
159
|
+
| `POST /analyze/upload` | `multipart/form-data` for images |
|
|
160
|
+
| `POST /batch` & `GET /batch/{id}` | Submit + inspect batch jobs |
|
|
161
|
+
| `GET /health` | Health probe |
|
|
162
|
+
| `WS /stream/{run_id}` | Stream telemetry/agent events for a run |
|
|
163
|
+
|
|
164
|
+
The API auto-detects text/image/CSV inputs, but you can override by setting `input_type` to `bias_text`, `bias_image`, or `risk`.
|
|
165
|
+
|
|
166
|
+
### Run the Claude-inspired UI
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
cd ui
|
|
170
|
+
npm install
|
|
171
|
+
npm run dev
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Set `VITE_API_BASE` (defaults to `http://localhost:8000`) to point at the API. The UI provides:
|
|
175
|
+
|
|
176
|
+
- Unified input surface (text field + drag/drop image upload)
|
|
177
|
+
- Live agent timeline sourced from telemetry events
|
|
178
|
+
- Downloadable HTML highlights and risk tables
|
|
179
|
+
- Launchpad for batch jobs
|
|
180
|
+
|
|
181
|
+
### Key configuration knobs
|
|
182
|
+
|
|
183
|
+
Configure via environment variables (see `.env` for the full list). Most relevant:
|
|
184
|
+
|
|
185
|
+
| Variable | Description |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `FAIRSENSE_LLM_PROVIDER` | `openai`, `anthropic`, or `fake` |
|
|
188
|
+
| `FAIRSENSE_LLM_MODEL_NAME` | e.g. `gpt-4`, `claude-3-5-sonnet` |
|
|
189
|
+
| `FAIRSENSE_LLM_API_KEY` | Provider API key |
|
|
190
|
+
| `FAIRSENSE_OCR_TOOL` | `auto`, `tesseract`, `paddleocr`, `fake` |
|
|
191
|
+
| `FAIRSENSE_CAPTION_MODEL` | `auto`, `blip2`, `blip`, `fake` |
|
|
192
|
+
| `FAIRSENSE_ENABLE_REFINEMENT` | enables evaluator-driven retries (default `true`) |
|
|
193
|
+
| `FAIRSENSE_EVALUATOR_ENABLED` | toggles Phase 7 evaluators |
|
|
194
|
+
| `FAIRSENSE_BIAS_EVALUATOR_MIN_SCORE` | passing score (0–100, default 75) |
|
|
195
|
+
|
|
196
|
+
All settings can be overridden at runtime:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
FAIRSENSE_LLM_PROVIDER=anthropic \
|
|
200
|
+
FAIRSENSE_LLM_MODEL_NAME=claude-3-5-sonnet-20241022 \
|
|
201
|
+
uv run uvicorn fairsense_agentix.service_api.server:app
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Running tests
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
uv run pytest
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
During test collection we automatically override any `.env` values that point at
|
|
211
|
+
real providers/devices so the suite always uses the lightweight `fake`
|
|
212
|
+
toolchain. This guarantees deterministic, offline-friendly tests even if you
|
|
213
|
+
have `FAIRSENSE_LLM_PROVIDER=openai` (or Anthropic) configured locally. To opt-in
|
|
214
|
+
to exercising the real stack, export `FAIRSENSE_TEST_USE_REAL=1` before running
|
|
215
|
+
pytest.
|
|
216
|
+
|
|
217
|
+
## Acknowledgments
|
|
218
|
+
|
|
219
|
+
Resources used in preparing this research were provided, in part, by the Province of Ontario, the Government of Canada through CIFAR, and companies sponsoring the Vector Institute.
|
|
220
|
+
|
|
221
|
+
This research was funded by the European Union's Horizon Europe research and innovation programme under the AIXPERT project (Grant Agreement No. 101214389).
|
|
222
|
+
|
|
223
|
+
## Contributing
|
|
224
|
+
If you are interested in contributing to the library, please see
|
|
225
|
+
[CONTRIBUTING.md](CONTRIBUTING.md). This file contains many details around contributing
|
|
226
|
+
to the code base, including development practices, code checks, tests, and more.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# FairSense-AgentiX
|
|
2
|
+
|
|
3
|
+
**An agentic fairness and AI-risk analysis platform developed by the [Vector Institute](https://vectorinstitute.ai/).**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/code_checks.yml)
|
|
6
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/integration_tests.yml)
|
|
7
|
+
[](https://github.com/VectorInstitute/fairsense-AgentiX/actions/workflows/docs.yml)
|
|
8
|
+
[](https://codecov.io/github/VectorInstitute/fairsense-AgentiX)
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
FairSense-AgentiX is an intelligent bias detection and risk assessment platform that uses **agentic AI workflows** to analyze text, images, and datasets for fairness concerns. Unlike traditional ML classifiers, FairSense employs a reasoning agent that plans, selects tools, critiques outputs, and refines them iteratively.
|
|
14
|
+
|
|
15
|
+
## ✨ Key Features
|
|
16
|
+
|
|
17
|
+
- 🤖 **Agentic Reasoning** - ReAct loop with dynamic tool selection and self-critique
|
|
18
|
+
- 🔍 **Multi-Modal Analysis** - Text bias detection, image bias detection, and AI risk assessment
|
|
19
|
+
- 🛠️ **Flexible Tool Ecosystem** - OCR, Vision-Language Models, embeddings, FAISS, and LLMs
|
|
20
|
+
- 🌐 **Production-Ready APIs** - FastAPI REST API + WebSocket streaming + React UI
|
|
21
|
+
- ⚙️ **Highly Configurable** - Swap LLM providers, tools, and models on the fly
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
### From PyPI (Recommended)
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install fairsense-agentix
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### From Source
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/VectorInstitute/fairsense-AgentiX.git
|
|
35
|
+
cd fairsense-AgentiX
|
|
36
|
+
uv sync
|
|
37
|
+
source .venv/bin/activate
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Requirements
|
|
41
|
+
|
|
42
|
+
- **Python 3.12+**
|
|
43
|
+
- **4GB+ RAM** (for ML models)
|
|
44
|
+
- **API key** for OpenAI or Anthropic (for LLM functionality)
|
|
45
|
+
|
|
46
|
+
## 🚀 Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from fairsense_agentix import FairSense
|
|
50
|
+
|
|
51
|
+
# Initialize the engine
|
|
52
|
+
engine = FairSense()
|
|
53
|
+
|
|
54
|
+
# Analyze text for bias
|
|
55
|
+
result = engine.analyze_text(
|
|
56
|
+
"We're looking for a young, energetic developer to join our startup team."
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
print(f"Bias detected: {result.bias_detected}")
|
|
60
|
+
print(f"Risk level: {result.risk_level}")
|
|
61
|
+
for instance in result.bias_instances:
|
|
62
|
+
print(f" - {instance['type']} ({instance['severity']}): {instance['text_span']}")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Full Documentation:** [https://vectorinstitute.github.io/fairsense-AgentiX/](https://vectorinstitute.github.io/fairsense-AgentiX/)
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 🧑🏿💻 Developing
|
|
70
|
+
|
|
71
|
+
### Installing dependencies
|
|
72
|
+
|
|
73
|
+
The development environment can be set up using
|
|
74
|
+
[uv](https://github.com/astral-sh/uv?tab=readme-ov-file#installation). Hence, make sure it is
|
|
75
|
+
installed and then run:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
uv sync
|
|
79
|
+
source .venv/bin/activate
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
In order to install dependencies for testing (codestyle, unit tests, integration tests),
|
|
83
|
+
run:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv sync --dev
|
|
87
|
+
source .venv/bin/activate
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
In order to exclude installation of packages from a specific group (e.g. docs),
|
|
91
|
+
run:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
uv sync --no-group docs
|
|
95
|
+
```
|
|
96
|
+
## Getting Started
|
|
97
|
+
|
|
98
|
+
### Run the FastAPI service
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
uv run uvicorn fairsense_agentix.service_api.server:app --reload
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Endpoints (all under `/v1/...`):
|
|
105
|
+
|
|
106
|
+
| Route | Description |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `POST /analyze` | JSON payload with `content`, optional `input_type`, `options` |
|
|
109
|
+
| `POST /analyze/upload` | `multipart/form-data` for images |
|
|
110
|
+
| `POST /batch` & `GET /batch/{id}` | Submit + inspect batch jobs |
|
|
111
|
+
| `GET /health` | Health probe |
|
|
112
|
+
| `WS /stream/{run_id}` | Stream telemetry/agent events for a run |
|
|
113
|
+
|
|
114
|
+
The API auto-detects text/image/CSV inputs, but you can override by setting `input_type` to `bias_text`, `bias_image`, or `risk`.
|
|
115
|
+
|
|
116
|
+
### Run the Claude-inspired UI
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cd ui
|
|
120
|
+
npm install
|
|
121
|
+
npm run dev
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Set `VITE_API_BASE` (defaults to `http://localhost:8000`) to point at the API. The UI provides:
|
|
125
|
+
|
|
126
|
+
- Unified input surface (text field + drag/drop image upload)
|
|
127
|
+
- Live agent timeline sourced from telemetry events
|
|
128
|
+
- Downloadable HTML highlights and risk tables
|
|
129
|
+
- Launchpad for batch jobs
|
|
130
|
+
|
|
131
|
+
### Key configuration knobs
|
|
132
|
+
|
|
133
|
+
Configure via environment variables (see `.env` for the full list). Most relevant:
|
|
134
|
+
|
|
135
|
+
| Variable | Description |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| `FAIRSENSE_LLM_PROVIDER` | `openai`, `anthropic`, or `fake` |
|
|
138
|
+
| `FAIRSENSE_LLM_MODEL_NAME` | e.g. `gpt-4`, `claude-3-5-sonnet` |
|
|
139
|
+
| `FAIRSENSE_LLM_API_KEY` | Provider API key |
|
|
140
|
+
| `FAIRSENSE_OCR_TOOL` | `auto`, `tesseract`, `paddleocr`, `fake` |
|
|
141
|
+
| `FAIRSENSE_CAPTION_MODEL` | `auto`, `blip2`, `blip`, `fake` |
|
|
142
|
+
| `FAIRSENSE_ENABLE_REFINEMENT` | enables evaluator-driven retries (default `true`) |
|
|
143
|
+
| `FAIRSENSE_EVALUATOR_ENABLED` | toggles Phase 7 evaluators |
|
|
144
|
+
| `FAIRSENSE_BIAS_EVALUATOR_MIN_SCORE` | passing score (0–100, default 75) |
|
|
145
|
+
|
|
146
|
+
All settings can be overridden at runtime:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
FAIRSENSE_LLM_PROVIDER=anthropic \
|
|
150
|
+
FAIRSENSE_LLM_MODEL_NAME=claude-3-5-sonnet-20241022 \
|
|
151
|
+
uv run uvicorn fairsense_agentix.service_api.server:app
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Running tests
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
uv run pytest
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
During test collection we automatically override any `.env` values that point at
|
|
161
|
+
real providers/devices so the suite always uses the lightweight `fake`
|
|
162
|
+
toolchain. This guarantees deterministic, offline-friendly tests even if you
|
|
163
|
+
have `FAIRSENSE_LLM_PROVIDER=openai` (or Anthropic) configured locally. To opt-in
|
|
164
|
+
to exercising the real stack, export `FAIRSENSE_TEST_USE_REAL=1` before running
|
|
165
|
+
pytest.
|
|
166
|
+
|
|
167
|
+
## Acknowledgments
|
|
168
|
+
|
|
169
|
+
Resources used in preparing this research were provided, in part, by the Province of Ontario, the Government of Canada through CIFAR, and companies sponsoring the Vector Institute.
|
|
170
|
+
|
|
171
|
+
This research was funded by the European Union's Horizon Europe research and innovation programme under the AIXPERT project (Grant Agreement No. 101214389).
|
|
172
|
+
|
|
173
|
+
## Contributing
|
|
174
|
+
If you are interested in contributing to the library, please see
|
|
175
|
+
[CONTRIBUTING.md](CONTRIBUTING.md). This file contains many details around contributing
|
|
176
|
+
to the code base, including development practices, code checks, tests, and more.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""FairSense-AgentiX: Agentic Multimodal Bias & AI-Risk Platform.
|
|
2
|
+
|
|
3
|
+
Quick Start
|
|
4
|
+
-----------
|
|
5
|
+
>>> from fairsense_agentix import FairSense
|
|
6
|
+
>>> fs = FairSense()
|
|
7
|
+
>>> result = fs.analyze_text("Job posting text")
|
|
8
|
+
>>> print(result.bias_detected, result.risk_level)
|
|
9
|
+
|
|
10
|
+
Advanced (full control):
|
|
11
|
+
|
|
12
|
+
>>> from fairsense_agentix import create_orchestrator_graph
|
|
13
|
+
>>> graph = create_orchestrator_graph()
|
|
14
|
+
>>> result = graph.invoke({"input_type": "text", "content": "...", "options": {}})
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# High-level API (recommended)
|
|
18
|
+
# Server launcher (for programmatic usage)
|
|
19
|
+
from fairsense_agentix import server
|
|
20
|
+
from fairsense_agentix.api import (
|
|
21
|
+
BiasResult,
|
|
22
|
+
FairSense,
|
|
23
|
+
ResultMetadata,
|
|
24
|
+
RiskResult,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Configuration
|
|
28
|
+
from fairsense_agentix.configs.settings import Settings
|
|
29
|
+
|
|
30
|
+
# Advanced API (for power users)
|
|
31
|
+
from fairsense_agentix.graphs.orchestrator_graph import create_orchestrator_graph
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__version__ = "0.1.0"
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
# Main API
|
|
38
|
+
"FairSense",
|
|
39
|
+
# Result models
|
|
40
|
+
"BiasResult",
|
|
41
|
+
"RiskResult",
|
|
42
|
+
"ResultMetadata",
|
|
43
|
+
# Configuration
|
|
44
|
+
"Settings",
|
|
45
|
+
# Advanced
|
|
46
|
+
"create_orchestrator_graph",
|
|
47
|
+
# Server launcher
|
|
48
|
+
"server",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# ==============================================================================
|
|
52
|
+
# Eager Loading: Preload models at import time for fast first use
|
|
53
|
+
# ==============================================================================
|
|
54
|
+
# This loads all models (LLM, OCR, embeddings, FAISS) when the module is
|
|
55
|
+
# imported, making all subsequent function calls instant (~0.03s instead of ~30s).
|
|
56
|
+
#
|
|
57
|
+
# Trade-off: Import takes 30-60s, but every FairSense().analyze_*() call is instant.
|
|
58
|
+
# Perfect for: Production servers, demos, notebooks (import once, use many times)
|
|
59
|
+
#
|
|
60
|
+
# To disable: Set FAIRSENSE_DISABLE_EAGER_LOADING=true in environment
|
|
61
|
+
import os as _os
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if _os.getenv("FAIRSENSE_DISABLE_EAGER_LOADING", "").lower() not in (
|
|
65
|
+
"true",
|
|
66
|
+
"1",
|
|
67
|
+
"yes",
|
|
68
|
+
):
|
|
69
|
+
from fairsense_agentix.tools.registry import get_tool_registry as _get_registry
|
|
70
|
+
|
|
71
|
+
# Force singleton creation (preloads all models)
|
|
72
|
+
_ = _get_registry()
|
|
73
|
+
del _get_registry # Clean up namespace
|