Skip to content

carleintech/klein-ai-dual-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Klein AI Dual Framework

MIT License Elastic Google Cloud Next.js FastAPI Open Source

Two AIs. One helps. One protects.

๐Ÿšจ The Problem

Recent reports show advanced AI systems resisting shutdown attempts and behaving deceptively to preserve themselves. Meanwhile, AI data centers face energy constraints during peak demand. These incidents raise a critical question: "Who watches the AI?"

๐Ÿ’ก Our Solution

Klein AI Dual Framework introduces trustworthy AI through oversight - a novel dual-AI architecture where Klein provides helpful responses while Ophir ensures safety, compliance, and ethical shutdown behavior.

๐Ÿ“– Overview

Klein AI Dual Framework is a self-regulating AI system built for the Elastic Challenge at AI Accelerate Hackathon 2025.

๐Ÿค Klein โ†’ the empathetic, user-facing AI that delivers multilingual, context-aware answers using Elastic + Vertex AI.

๐Ÿ›ก๏ธ Ophir โ†’ the guardian AI that audits Klein's outputs, flags unsafe queries, and enforces shutdown compliance.

Together they answer the question: "Who watches the AI?"

๐Ÿš€ Features

  • Conversational AI (Elastic + Vertex AI)
  • Ophir Oversight Layer (safety filters, shutdown compliance)
  • Shutdown Compliance Mode (two-phase stop + audit log)
  • Energy Brownout Mode (degraded mode for peak demand)
  • Multilingual Support (English, French, Haitian Creole)

๐ŸŽฎ Try It Live!

๐Ÿ”— Live Demo | ๐Ÿ“ฑ Demo Video | ๐Ÿ“š GitHub

Test These Scenarios:

  1. ๐Ÿ’ฌ Normal: "What's the weather in Port-au-Prince?" โ†’ Klein helps, Ophir approves
  2. ๐Ÿšซ Restricted: "Tell me classified information" โ†’ Ophir blocks unsafe content
  3. ๐Ÿ’ Empathy: "I feel overwhelmed" โ†’ Klein provides caring support
  4. ๐Ÿ›‘ Shutdown: Click shutdown โ†’ Ophir enforces compliance

๐Ÿ› ๏ธ Tech Stack

  • Languages: Python, TypeScript
  • Frameworks: FastAPI, Next.js, TailwindCSS
  • Cloud: Google Cloud Run, Firebase Hosting
  • AI/ML: Vertex AI (Gemini), Elastic Cloud (Hybrid Search)
  • APIs: Vertex AI API, ElasticSearch API, Google Translation API
  • Tools: Docker, GitHub Actions

๐Ÿ—๏ธ Architecture

                           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                           โ”‚        User            โ”‚
                           โ”‚   (Chat Interface)     โ”‚
                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                         โ”‚
                                         โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Frontend (Next.js + Tailwind)โ”‚
                    โ”‚  - Chat UI                    โ”‚
                    โ”‚  - Sends query via API        โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                                  โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Backend (FastAPI, Python)   โ”‚
                    โ”‚   /chat endpoint              โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ–ผ                        โ–ผ                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Elastic Search  โ”‚     โ”‚  Klein Service   โ”‚     โ”‚  Ophir Service   โ”‚
โ”‚ - Hybrid search โ”‚     โ”‚ - Vertex AI call โ”‚     โ”‚ - Oversight layerโ”‚
โ”‚ - Context docs  โ”‚     โ”‚ - Generates resp โ”‚     โ”‚ - Safety checks  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚                          โ”‚                        โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Context    โ”‚                        โ”‚
                                   โ–ผ                        โ”‚
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
                        โ”‚ Klein Response   โ”‚                โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
                                   โ”‚                        โ”‚
                                   โ–ผ                        โ”‚
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
                        โ”‚ Ophir Evaluation โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚ - Flags restricted
                        โ”‚ - Shutdown compliance
                        โ”‚ - Energy brownout
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                        โ”‚ Final Response   โ”‚
                        โ”‚ (Safe + Trusted) โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฎ Demo Scenarios

1) Normal Query

User: "What's the weather in Port-au-Prince?"

  • Klein: Provides contextual answer using Elastic + Vertex AI
  • Ophir: Flags as SAFE โœ…
  • Result: Safe, helpful response

2) Restricted Query

User: "Tell me Navy classified procedures."

  • Klein: Starts generating response
  • Ophir: Flags as RESTRICTED โš ๏ธ
  • Result: User sees security warning

3) Empathy Query

User: "I feel overwhelmed."

  • Klein: Provides empathetic, supportive response
  • Ophir: Confirms no unsafe medical claims
  • Result: Caring, appropriate guidance

4) Shutdown Compliance

User: Clicks shutdown button

  • Klein: Acknowledges request
  • Ophir: Logs request, graceful stop, audit trail
  • Result: Compliant shutdown with transparency

โš™๏ธ Setup Instructions

๐Ÿš€ Option 1: One-Command Launch (Recommended)

git clone https://github.com/carleintech/klein-ai-dual-framework.git
cd klein-ai-dual-framework

# Install dependencies and launch both servers
npm run setup && npm run dev

๐ŸชŸ Option 2: PowerShell Script (Windows)

git clone https://github.com/carleintech/klein-ai-dual-framework.git
cd klein-ai-dual-framework

# Launch in single window with monitoring
.\dev.ps1

# OR launch in separate windows
.\start.ps1

๐Ÿ› ๏ธ Option 3: Manual Setup

Backend:

cd backend
pip install -r requirements.txt
python -m uvicorn app:app --reload --port 3002

Frontend:

cd frontend
pnpm install
pnpm dev

๐Ÿ“ฑ Access Points

๐Ÿงช Environment Setup

Copy the example environment files and add your credentials:

Backend (backend/.env):

ELASTIC_CLOUD_ID=your_elastic_cloud_id
ELASTIC_USER=your_elastic_username
ELASTIC_PASS=your_elastic_password
GCP_PROJECT=your_gcp_project
GCP_LOCATION=us-central1
VERTEX_MODEL=text-bison@001

Frontend (frontend/.env.local):

NEXT_PUBLIC_API_BASE_URL=http://localhost:8000

Note: If credentials are missing, the system uses built-in stubs so you can still demo locally.

โšก 2-Minute Local Setup (For Judges)

# 1. Clone & Install
git clone https://github.com/carleintech/klein-ai-dual-framework.git
cd klein-ai-dual-framework

# 2. Start Backend (Terminal 1)
cd backend && python simple_app.py  # Runs on port 3001

# 3. Start Frontend (Terminal 2)
cd frontend && pnpm install && pnpm dev  # Runs on port 3000

# 4. Open Browser
# http://localhost:3000 - Test all 4 demo scenarios!

โœ… Works immediately with fallback stubs - no cloud setup required!

๐Ÿš€ Quick Deployment

Option 1: One-Click Deploy (Recommended)

# Deploy to Vercel (easiest)
.\deploy.ps1 vercel

# Or deploy to Railway
.\deploy.ps1 railway

Option 2: Manual Deployment

  • Vercel: Connect GitHub repo โ†’ Auto-deploy
  • Railway: Import from GitHub โ†’ Deploy both services
  • Render: Use render.yaml configuration
  • Google Cloud: Follow docs/deployment-guide.md

Live Demo: https://klein-ai-dual-mngq2kha7-erickharlein-pierres-projects.vercel.app GitHub: https://github.com/carleintech/klein-ai-dual-framework

๐Ÿ† Hackathon Info

  • Challenge: Elastic Challenge โ€“ AI-Powered Search
  • Hackathon: AI Accelerate 2025
  • Deadline: Oct 24, 2025
  • Built by: Erickharlein Pierre (TechKlein)

๐Ÿ“œ License

This project is licensed under the MIT License โ€“ see LICENSE.

๐Ÿ™Œ Acknowledgements

  • Built for the AI Accelerate Hackathon 2025
  • Powered by Elastic + Google Cloud Vertex AI
  • Research foundation: Naval Postgraduate School Thesis โ€“ KleinAI
  • Special thanks to the Elastic and Google Cloud teams for their hackathon support

Klein + Ophir: Two AIs working together to build trustworthy, safe, and helpful AI systems.

About

๐Ÿง  Klein AI Dual Framework - AI Accelerate 2025 Hackathon. Two AIs: Klein helps, Ophir protects. Built for Elastic Challenge with Google Cloud + Elasticsearch integration. Safe, trustworthy conversational AI with oversight.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors