Skip to content

dechang64/pai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Ž PAI β€” Philanthropic Asset Intelligence

AI-Powered Charitable Investment Optimization, Giving Strategy & Impact Measurement

Python Streamlit Tests LOC License

Prototype v0.4 Β· Gates Foundation Grand Challenges 2026 Β· Project 3: AI to Accelerate Charitable Giving


What is PAI?

PAI uses Federated Retrieval-Augmented Generation (Federated RAG) to ground every AI recommendation in verified institutional knowledge while ensuring sensitive data never leaves local servers. It uniquely unifies investment optimization, grant recommendations, and impact measurement into a closed-loop system where real-world outcomes continuously improve future decisions.

Key stat: A pre-registered experiment (White et al., 2026, N=1,949) showed LLM-based dialogue increases effective charitable donations by 45.9% β€” the strongest causal evidence to date that AI can accelerate giving.


Architecture

PAI/
β”œβ”€β”€ app.py                          # Streamlit Cloud single-file version (v0.4, 1,226 lines)
β”œβ”€β”€ requirements.txt                # Cloud dependencies
β”œβ”€β”€ LICENSE                         # MIT License
β”œβ”€β”€ README.md                       # This file
β”‚
└── pai-audit/                      # Full modular version (v0.4) ← main development
    β”œβ”€β”€ app.py                      # Streamlit dashboard (7 tabs)
    β”œβ”€β”€ pyproject.toml              # Package config (v0.4.0)
    β”œβ”€β”€ requirements.txt            # Full dependencies
    β”œβ”€β”€ core/
    β”‚   β”œβ”€β”€ __init__.py             # Module exports
    β”‚   β”œβ”€β”€ portfolio_optimizer.py  # Markowitz MVO + Impact-Aware optimization
    β”‚   β”œβ”€β”€ llm_client.py           # GiveSmart LLM advisor
    β”‚   β”œβ”€β”€ give_nudge.py           # GiveNudge behavioral engine
    β”‚   β”œβ”€β”€ impact_feedback.py      # Impact Feedback Loop
    β”‚   β”œβ”€β”€ federated_learning.py   # FedShield reference implementation
    β”‚   └── federated_rag/          # Federated RAG module
    β”‚       β”œβ”€β”€ __init__.py
    β”‚       β”œβ”€β”€ config.py           # Dataclass configs
    β”‚       β”œβ”€β”€ document_loader.py  # PDF/CSV/JSON/MD loader
    β”‚       β”œβ”€β”€ embeddings.py       # sentence-transformers wrapper
    β”‚       β”œβ”€β”€ vector_store.py     # FAISS vector store
    β”‚       β”œβ”€β”€ federated_client.py # Federated aggregation client
    β”‚       β”œβ”€β”€ reranker.py         # Cross-encoder reranker
    β”‚       β”œβ”€β”€ hallucination_detector.py  # Claim verification engine
    β”‚       └── streamlit_ui.py     # Streamlit integration
    β”œβ”€β”€ tests/
    β”‚   β”œβ”€β”€ test_portfolio.py       # Portfolio optimizer tests
    β”‚   β”œβ”€β”€ test_llm_client.py      # LLM advisor tests
    β”‚   β”œβ”€β”€ test_federated_rag.py   # Federated RAG tests
    β”‚   └── test_v04_modules.py     # GiveNudge + Impact Loop + Hallucination tests
    └── data/
        └── knowledge_base/         # Verified reference data
            β”œβ”€β”€ givewell_charities.md
            β”œβ”€β”€ daf_investment.md
            β”œβ”€β”€ daf_tax_strategies.md
            β”œβ”€β”€ impact_measurement.md
            β”œβ”€β”€ behavioral_economics.md
            β”œβ”€β”€ rare_disease.md
            └── federated_learning.md

Modules

πŸ“Š InvestOpt β€” Impact-Aware Portfolio Optimization

Extends Markowitz Mean-Variance Optimization to jointly maximize financial returns and charitable impact. Recognizes that the highest-returning portfolio may produce less good if gains flow to saturated programs.

  • Maximum Sharpe, Minimum Variance, Risk Parity strategies
  • Impact-Aware optimization (v0.4): maximizes U = Ξ±Β·Sharpe + Ξ²Β·Impact
  • Efficient frontier visualization
  • DAF-specific optimization with charitable impact metrics
  • Financial vs. Impact portfolio comparison

πŸ€– GiveSmart β€” LLM Donation Advisor

Personalized donation strategy with hallucination detection. Every claim is verified against institutional knowledge bases.

  • Real OpenAI/Anthropic API integration (demo fallback)
  • Tax optimization (DAFs, bunching, appreciated securities)
  • Charity matching using GiveWell/ACE evidence ratings
  • Hallucination Detection (v0.4): claim extraction β†’ KB verification β†’ confidence scoring
  • +45.9% effective giving increase (White et al. 2026)

🎯 ImpactLens β€” Charity Effectiveness Evaluation

Multi-dimensional charity scoring aligned with GiveWell's cost-effectiveness methodology.

  • QALY/DALY-based scoring
  • Cost per life saved analysis
  • Evidence strength ratings
  • Radar chart visualization

πŸ’‘ GiveNudge β€” Behavioral Engagement Engine (v0.4)

Data-driven donation optimization based on behavioral economics (Andreoni 1990 warm-glow theory).

  • 6 nudge types: default reminder, social proof, matching, impact framing, urgency, warm-glow
  • 4 delivery channels: email, in-app, SMS, push
  • 5 donor segments with tailored strategies
  • Built-in A/B testing framework
  • Optimal timing engine (year-end 1.45Γ— conversion boost)

πŸ”„ Impact Feedback Loop (v0.4)

PAI's most transformative component β€” connects measured outcomes to future allocation decisions.

  • Effect signal collection (health, education, environmental metrics)
  • Saturation detection: diminishing returns curves per cause area
  • Automatic reallocation recommendations
  • "What happened" β†’ "What should we do next" closed loop

πŸ›‘οΈ FedShield β€” Federated Learning

Reference implementation for privacy-preserving cross-institutional collaboration.

  • FedAvg algorithm (McMahan et al. 2017)
  • Differential privacy support
  • Audit trail with blockchain-style logging
  • Simulated multi-institution training

πŸ” Federated RAG β€” Cross-Institutional Knowledge Retrieval

First architecture combining LLM conversational ability, RAG factual grounding, and federated privacy for charitable giving.

  • Embeddings: sentence-transformers (all-MiniLM-L6-v2)
  • Vector search: FAISS
  • Cross-encoder reranking (ms-marco-MiniLM)
  • Federated embedding training
  • Knowledge sharing without data sharing

Quick Start

Streamlit Cloud (single file)

pip install streamlit pandas numpy plotly scipy
streamlit run app.py

Full modular version

cd pai-audit
pip install -r requirements.txt
streamlit run app.py

Run tests

cd pai-audit
pytest tests/ -v
# 110 tests passed

Dashboard (7 Tabs)

Tab Module Description
1 InvestOpt Portfolio optimization with 63 mutual funds
2 GiveSmart AI donation advisor with hallucination detection
3 ImpactLens Charity effectiveness evaluation
4 GiveNudge Behavioral engagement engine
5 Impact Loop Closed-loop outcome measurement
6 Rare Disease Rare disease foundation blueprint + FedShield
7 Federated RAG Cross-institutional knowledge retrieval

Tech Stack

Component Technology
Frontend Streamlit
Charts Plotly
Optimization SciPy
Embeddings sentence-transformers (all-MiniLM-L6-v2)
Vector Search FAISS
Federated Training PyTorch + FedAvg
LLM OpenAI / Anthropic / Demo fallback
Data Pandas + NumPy

Key References

  1. White, J.P. et al. (2026). Increasing the effectiveness of charitable giving with AI-generated persuasion. PsyArXiv. β€” LLM dialogue increases effective donations by 45.9%
  2. Andreoni, J. (1990). Impure Altruism and Donations to Public Goods. The Economic Journal, 100(401), 464-477. β€” Warm-glow giving theory
  3. Lo, A., Matveyev, A., & Zeume, S. (2025). The Risk, Reward, and Asset Allocation of Nonprofit Endowment Funds. NBER Working Paper. β€” Charity endowments systematically underperform
  4. Gates Foundation (2026). AI to Accelerate Charitable Giving. Grand Challenges RFP.
  5. GiveWell. Cost-Effectiveness Analysis. β€” ~$3,000-5,000 per life saved (top charities)
  6. McMahan, B. et al. (2017). Communication-Efficient Learning of Deep Networks from Decentralized Data. AISTATS. β€” FedAvg algorithm

Related Projects

Project Description
FundFL Mutual fund analysis (Rust + Python)
organoid-fl Federated learning for medical images
defect-fl PCB defect detection with FL

License

MIT License


Built for the Gates Foundation Grand Challenges 2026