Skip to content

yoosuf/KeepAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Why KeepAI?

Every AI SaaS sends your data to someone else's server. Not this one.

KeepAI is a privacy-first, production-ready backend that runs large language models (Llama 3, Mistral, CodeLlama, etc.) on your own infrastructure β€” no cloud dependency, no data leaks, no API usage fees.

"The best AI is the one that respects your privacy."

πŸ† What Makes It Different

Feature KeepAI OpenAI API Other Backends
Data Privacy πŸ”’ 100% local ❌ Data leaves your infra ❌ Usually cloud
Cost πŸ’° Free (your hardware) πŸ’Έ Per-token billing πŸ’Έ SaaS fees
Models πŸ”„ Any Ollama model πŸ”’ GPT only πŸ”’ Limited choices
Auth & RBAC βœ… Built-in JWT + RBAC ❌ Not included ❌ Rarely included
Structured Output βœ… JSON mode βœ… Supported ❌ Usually missing
Database βœ… PostgreSQL ❌ No persistence ⚠️ Varies
Clean Architecture βœ… Hexagonal ❌ N/A ⚠️ Rarely

✨ Features

  • πŸ€– Local LLM Inference β€” Run Llama 3, Mistral, CodeLlama, DeepSeek, and 100+ models locally via Ollama
  • πŸ” JWT Authentication β€” Register, login, token-based auth out of the box
  • πŸ›‘οΈ Role-Based Access Control β€” Database-driven permissions (Admin/User roles, granular permissions)
  • πŸ“‹ Structured JSON Extraction β€” Extract invoices, contracts, forms as validated JSON
  • πŸ—„οΈ PostgreSQL Persistence β€” Async SQLAlchemy + Alembic migrations
  • 🐳 Docker Ready β€” One command to start everything
  • πŸ—οΈ Clean Architecture β€” Hexagonal/ports-and-adapters pattern, fully testable
  • πŸ“Š Observability β€” Structured JSON logging, request tracking
  • βœ… Tested β€” pytest + async tests + CI pipeline

πŸš€ Quick Start

One-liner (Docker)

git clone https://github.com/yoosuf/KeepAI.git
cd fastapi-ollama-backend
docker compose up --build -d
docker compose exec ollama ollama pull llama3

That's it. Your AI backend runs at http://localhost:8000 with Swagger docs at http://localhost:8000/docs.

Or without Docker

git clone https://github.com/yoosuf/KeepAI.git
cd fastapi-ollama-backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Set up PostgreSQL and Ollama, then:
./entrypoint.sh

First API Call

# Register
curl -X POST http://localhost:8000/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email": "demo@example.com", "password": "demo1234"}'

# Login
TOKEN=$(curl -s -X POST http://localhost:8000/api/v1/auth/login \
  -F "username=demo@example.com" \
  -F "password=demo1234" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")

# Generate AI response
curl -X POST http://localhost:8000/api/v1/prompts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"prompt_text": "Explain quantum computing in 3 sentences."}'

πŸ’‘ Use Cases

πŸ“„ Document Intelligence

Extract structured data from invoices, contracts, forms, and legal documents.

curl -X POST "http://localhost:8000/api/v1/extract-invoice?text_content=Invoice%20%23999%20from%20TechCorp.%20Date:%202026-01-15.%202%20Laptops%20at%20%241000%20each.%20Total:%20%242000." \
  -H "Authorization: Bearer $TOKEN"

πŸ₯ Privacy-First Healthcare

Process patient records, clinical notes, and medical documents on-premises β€” HIPAA-friendly by design.

βš–οΈ Legal Document Analysis

Extract clauses, parties, and obligations from contracts without sending sensitive data to third parties.

πŸ“Š Natural Language to SQL

Ask questions in English and get SQL queries β€” the structured JSON pattern makes this trivial.

πŸ”¬ Research & Academia

Run AI assistants with full data privacy for sensitive research data.

🏒 Enterprise Internal Assistant

Deploy behind your firewall with role-based access for different teams.


πŸ“– API Overview

Method Endpoint Auth Description
GET /health β€” Health check
POST /api/v1/auth/register β€” Register new user
POST /api/v1/auth/login β€” Login, get JWT token
POST /api/v1/prompts JWT Send prompt to LLM
GET /api/v1/prompts JWT List your prompts
GET /api/v1/prompts/{id} JWT Get prompt details
POST /api/v1/extract-invoice JWT Extract JSON from text
GET /api/v1/admin/users Admin List all users
GET /api/v1/admin/all-prompts Admin List all prompts

πŸ“˜ Full API docs: API_DOCUMENTATION.md or live at /docs (Swagger).


πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     KeepAI App      β”‚
β”‚  Router β†’ Service    β”‚
β”‚     β†’ Interface      β”‚
β”‚        ↓             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  PostgreSQL   β”‚   β”‚
β”‚  β”‚  (asyncpg)    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚        ↓             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Ollama API   β”‚   β”‚
β”‚  β”‚  (local LLM)  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Clean Architecture / Hexagonal β€” Router (presentation) β†’ Service (application) β†’ LLMInterface (port) β†’ OllamaClient (adapter).

Each layer is independently testable and swappable. Swap Ollama for OpenAI, Anthropic, or any API β€” change one file.

Full architecture doc β†’


πŸ—ΊοΈ Roadmap

  • JWT Auth + RBAC
  • PostgreSQL persistence
  • Structured JSON extraction
  • Docker Compose
  • Streaming responses (SSE)
  • Chat history & conversations
  • Web UI (React + Monaco Editor)
  • Multi-model routing
  • RAG (Retrieval-Augmented Generation)
  • Code generation agents
  • API key management
  • Rate limiting
  • Usage analytics dashboard

Full roadmap β†’


🀝 Contributing

We love contributions! Check out our Contributing Guidelines and Code of Conduct.

Ways to contribute:

  • πŸ› Report bugs via GitHub Issues
  • πŸ’‘ Suggest features
  • πŸ“ Improve documentation
  • πŸ”§ Submit pull requests

πŸ›‘οΈ Security

Found a vulnerability? Please read our Security Policy for reporting instructions.

Key security features:

  • JWT tokens with configurable expiry
  • bcrypt password hashing
  • Database-driven RBAC
  • No cloud dependencies β€” your data stays yours
  • Non-root user in Docker

πŸ“„ License

Distributed under the MIT License. See LICENSE for details.


πŸ“¬ Contact

Yoosuf Mohamed β€” mayoosuf@gmail.com

Project Link: https://github.com/yoosuf/KeepAI


⭐ Star this project if you find it useful! ⭐
Built with ❀️ for the open-source community

About

KeepAPI: Your private AI backend. Run LLMs locally. Own your data.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors