Katja is a comprehensive AI chat platform featuring 5 specialized modes: language learning with grammar correction, general chat, legal reasoning (Saul-7B), medical queries (Meditron/BioMistral), and a terminal-style console for monitoring all interactions. Built with local-first privacy using Ollama, with optional cloud fallback (OpenAI GPT-4o-mini). All data stays on your machine by default.
- Multi-language support - 7 European languages (Slovene, German, Italian, Croatian, French, English, Portuguese)
- Real-time grammar correction - Instant feedback with explanations in target language
- Spaced repetition - SM-2 algorithm for reviewing grammar patterns
- Export corrections - Save grammar corrections as JSON
- Auto-clear on language switch - Fresh conversation when switching languages
- 14+ LLM models - Choose from Llama, Qwen, GLM4, Gemma, and more
- LaTeX rendering - Math and technical formulas rendered beautifully (inline
$...$or display$$...$$) - Model switching - Live dropdown selector for all available Ollama models
- Structured responses - Optimized system prompts for technical and academic queries
- GPT-4o-mini support - Selectable OpenAI model with automatic routing
- Saul-7B specialized model - Fine-tuned for English law, contracts, torts, and legal reasoning
- LaTeX legal citations - Properly formatted case citations and legal principles
- Precedent explanations - Detailed case law analysis
- Legal doctrine support - Equity, trusts, negligence, contract law
- Meditron & BioMistral - Medical-domain fine-tuned models
- Maritime medical focus - Designed for ship's officers managing medical care without doctors
- Examination guidance - Systematic patient assessment (vital signs, SAMPLE history, physical exam)
- Telemedicine preparation - Organize observations for shore-based physician consultations
- IMGS protocol support - International Medical Guide for Ships compliance
- No diagnosis/treatment - Emphasizes observation and communication, not prescription
- Terminal-style interface - Hacker aesthetic with green monospace text
- Multi-session monitoring - View conversations from all modules in one place
- Real-time updates - Auto-refresh every 3 seconds
- Session filtering - Filter by language learning, general, legal, or medical chat
- Model tracking - See which model was used for each response
- Timestamp tracking - Full conversation history with precise timestamps
- Local-first inference - Uses Ollama for privacy-preserving AI (no cloud API required)
- Cloud fallback - Automatic OpenAI GPT-4o-mini fallback when selected or local models unavailable
- Conversation memory - SQLite database with WAL mode for persistent chat history
- Session management - Multiple conversation sessions with isolated history
- Customizable prompts - Edit system prompts for each mode via settings page ⭐ NEW
- CORS security - Configurable allowed origins for API access
The Legal Chat mode is for educational and research purposes only. It is not a substitute for professional legal advice. Do not rely on responses for actual legal matters. Always consult a qualified attorney for legal questions.
The Maritime Medical Chat mode is designed for ship's officers managing medical care on vessels without doctors. This tool assists with patient examination and observation to prepare for telemedicine consultations with shore-based physicians.
CRITICAL LIMITATIONS:
⚠️ NO DIAGNOSIS OR TREATMENT: Ship's medical officers are NOT authorized to diagnose conditions or initiate treatments (except immediate life-saving measures)⚠️ PHYSICIAN AUTHORIZATION REQUIRED: All medical interventions beyond basic first aid must be authorized by a shore-based physician via radio medical advice (TMAS - Telemedical Assistance Service)⚠️ EXAMINATION ONLY: This tool focuses on gathering complete, accurate information for remote physicians
This is NOT a substitute for professional medical advice. Always contact a shore-based physician for medical guidance.
Katja is a local-first, privacy-focused AI chat platform:
- Privacy: All LLM inference happens locally via Ollama by default. No data sent to third parties unless cloud fallback is used.
- Offline-capable: Works without internet connection (after initial model download).
- Transparent: Open source backend and frontend. No telemetry.
- Flexible: Choose between local models (privacy) or cloud models (performance).
- Minimalist: Simple FastAPI backend + Next.js frontend.
URL: http://localhost:3000 (default landing page)
Grammar corrections in 7 European languages with instant feedback:
- Practice conversational skills in any supported language
- Get real-time grammar corrections with explanations
- Review corrections using spaced repetition algorithm
- Export corrections as JSON for external study tools
URL: http://localhost:3000/chat
General-purpose AI conversations with 14+ models:
- Technical discussions with LaTeX math rendering
- Academic research assistance
- Creative writing and brainstorming
- General knowledge questions
Example queries:
- "What is Bayes' theorem and how is it used in statistics?"
- "Explain quantum entanglement in simple terms"
- "Write a Python function to calculate Fibonacci numbers"
URL: http://localhost:3000/legal-chat
English law queries using Saul-7B specialized legal model:
- Case law analysis and precedent research
- Contract law, torts, equity, trusts
- Legal doctrine explanations
- Properly formatted legal citations
Example queries:
- "What is the leading case in negligence?"
- "Explain the doctrine of consideration in contract law"
- "Is there an obligation of good faith in insurance law?"
URL: http://localhost:3000/medical-chat
Maritime medical guidance for ship's officers using Meditron and BioMistral:
- Systematic patient examination protocols (vital signs, SAMPLE history, physical exam)
- Preparing observations for shore-based physician consultation
- Understanding medical terminology and observations
- IMGS (International Medical Guide for Ships) protocol support
Example queries:
- "How should I perform a complete physical examination on a crew member with chest pain?"
- "What vital signs should I collect and how do I document them for the ship's doctor consultation?"
- "Guide me through assessing a patient's neurological status"
URL: http://localhost:3000/console
Terminal-style monitoring interface for all LLM interactions:
- View conversation history across all modules
- Filter by session type (language, general, legal, medical)
- Track which models were used for each response
- Auto-refresh every 3 seconds
- Export logs for analysis
- 🇸🇮 Slovene
- 🇩🇪 German
- 🇮🇹 Italian
- 🇭🇷 Croatian
- 🇫🇷 French
- 🇬🇧 English
- 🇵🇹 Portuguese
Switch languages via flag buttons in the chat interface.
- Ollama - Install from ollama.ai for local inference
- Pull models - Recommended models:
# General-purpose chat ollama pull llama3:8b-instruct-q4_K_M # English law (Saul 7B) ollama pull adrienbrault/saul-instruct-v1:Q4_K_M # Medical (Meditron) ollama pull meditron-7b # Biomedical (BioMistral) ollama pull biomistral-7b
- Node.js - For frontend (v18+ recommended)
- Python 3.10+ - For backend
- (Optional) OpenAI API Key - For cloud fallback when local models unavailable
git clone https://github.com/SL-MAR/katja.git
cd katja
chmod +x launch-katja.sh
./launch-katja.shThis launches:
- 🎓 Language Learning: http://localhost:3000
- 💬 General Chat: http://localhost:3000/chat
- ⚖️ Legal Chat: http://localhost:3000/legal-chat
- 🏥 Maritime Medical Chat: http://localhost:3000/medical-chat
- 💻 Console: http://localhost:3000/console
- ⚙️ Settings: http://localhost:3000/settings ⭐ NEW
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
Backend:
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Copy environment template
cp .env.example .env
# Start backend
uvicorn main:app --reloadFrontend:
cd frontend
npm install
npm run devThe backend uses environment variables. Copy .env.example to .env and adjust:
# LLM Provider (local = Ollama, openai = fallback)
LLM_PROVIDER=local
# Ollama settings
OLLAMA_MODEL=llama3:8b-instruct-q4_K_M
OLLAMA_BASE_URL=http://localhost:11434
# Optional: OpenAI fallback (if Ollama unavailable)
# OPENAI_API_KEY=your_api_key_here
# CORS origins (comma-separated)
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001,http://localhost:5173Switching models: Use the dropdown in each chat mode's UI or edit OLLAMA_MODEL in .env.
Fallback behavior: If Ollama is unavailable and OPENAI_API_KEY is set, the backend will automatically fall back to OpenAI's API.
Settings Page: http://localhost:3000/settings
Each chat mode has a customizable system prompt that defines the AI assistant's behavior:
- Language Learning: Conversational teacher with grammar correction
- Maritime Medical: Ship's officer examination guidance (no diagnosis/treatment)
- Legal: English common law specialist
- General: Technical and academic assistant
Features:
- ✏️ Live editor - Edit prompts in a Monaco-style textarea
- 💾 Browser storage - Changes saved to localStorage (persist across sessions)
- 🔄 Reset to defaults - Restore original prompts anytime
- 📋 Preview - See formatted prompt before saving
- ⚡ Instant effect - Changes apply on next message
Customization tips:
- Adjust tone (formal/casual)
- Add domain-specific knowledge
- Change output format preferences
- Include LaTeX notation guidance:
$inline$or$$display$$
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Next.js │─────▶│ FastAPI │─────▶│ Ollama │
│ Frontend │◀─────│ Backend │◀─────│ (Local) │
│ (Port 3001) │ │ (Port 8000) │ │ (Port 11434)│
└─────────────┘ └──────────────┘ └─────────────┘
│
▼
┌──────────────┐
│ SQLite │
│ Database │
└──────────────┘
- User types message → Frontend sends to
/katja/chat - Backend receives request → Loads conversation history from SQLite
- Prompt construction → Builds system prompt with grammar patterns + conversation context
- Ollama inference → Sends prompt to local Ollama instance (
http://localhost:11434) - JSON parsing → Extracts structured response (reply + grammar correction)
- Database storage → Saves conversation + corrections to SQLite
- Response → Returns to frontend with grammar feedback
JSON Format enforced via Ollama's format: json parameter:
{
"reply": "Conversational response in target language",
"correction": {
"corrected": "Corrected version of user's text",
"explanation": "Grammar explanation",
"pattern": "Grammar pattern ID (if applicable)",
"severity": "minor|major|critical"
}
}Frontend:
- Next.js (React framework)
- TypeScript
- Tailwind CSS
- FontAwesome icons
- react-markdown + KaTeX (LaTeX rendering) ⭐ NEW
- remark-math + rehype-katex (Math typesetting) ⭐ NEW
Backend:
- FastAPI (Python web framework)
- SQLite with WAL mode (Write-Ahead Logging)
- Pydantic v2 (validation)
- SlowAPI (rate limiting)
LLM:
- Ollama (local inference) - Primary
- OpenAI GPT-4o-mini (cloud fallback) - Optional
- Supports 14+ models including:
llama3:8b-instruct-q4_K_M(general, 4.9GB)adrienbrault/saul-instruct-v1:Q4_K_M(legal, 4.1GB) ⭐meditron-7b(maritime medical, 4.1GB) ⭐biomistral-7b(biomedical, 4.1GB) ⭐glm4,qwen2:7b,gemma3:12b(multi-lingual)
- Response length: 4096 tokens (configurable)
- Temperature: 0.0 (deterministic for medical/legal accuracy)
katja/
├── backend/
│ ├── core/
│ │ ├── database.py # SQLite schema & connection
│ │ ├── db_operations.py # CRUD operations
│ │ ├── llm_router.py # Ollama + OpenAI integration
│ │ └── spaced_repetition.py # SM-2 algorithm
│ ├── flows/
│ │ └── teacher_flow.py # Main conversation logic
│ ├── routers/
│ │ ├── teacher.py # Chat endpoint
│ │ ├── reviews.py # Spaced repetition API
│ │ ├── analytics.py # Progress tracking
│ │ └── system.py # Model switching, logs
│ ├── data/ # SQLite database (auto-created)
│ ├── .env.example # Configuration template
│ └── requirements.txt
├── frontend/
│ ├── components/
│ │ ├── Header.tsx # Navigation, model selector, action buttons
│ │ ├── ChatWindow.tsx # Grammar learning conversation UI
│ │ ├── GenericChat.tsx # Generic/legal/medical chat with LaTeX rendering
│ │ ├── GrammarPanel.tsx # Grammar corrections with localized labels
│ │ └── InputBox.tsx # User input with multilingual placeholders
│ ├── config/
│ │ └── systemPrompts.ts # ⭐ Centralized system prompts for all modes
│ ├── pages/
│ │ ├── index.tsx # 🎓 Language learning page (default)
│ │ ├── chat.tsx # 💬 General chat page
│ │ ├── legal-chat.tsx # ⚖️ Legal chat page (Saul-7B)
│ │ ├── medical-chat.tsx # 🏥 Maritime medical chat page (Meditron/BioMistral)
│ │ ├── console.tsx # 💻 Console log viewer
│ │ ├── settings.tsx # ⚙️ System prompt editor ⭐ NEW
│ │ ├── reviews.tsx # Spaced repetition UI
│ │ └── stats.tsx # Analytics dashboard
│ ├── utils/
│ │ ├── api.ts # API client functions
│ │ ├── languages.ts # Language metadata and labels
│ │ └── promptLoader.ts # ⭐ Load system prompts (custom or default)
│ └── public/
│ └── screenshots/ # UI screenshots for documentation
├── launch-katja.sh # Launcher script
├── CHANGELOG.md # Version history
└── README.md
Multi-language grammar correction with real-time feedback in 7 European languages.
General-purpose AI conversations with model selection and structured responses.
Specialized medical queries using Meditron and BioMistral models.
English law queries using Saul-7B specialized legal model.
Terminal-style log viewer for monitoring all LLM interactions across modules.
POST /katja/chat- Send message, receive grammar-corrected responseDELETE /katja/clear- Clear conversation history for language learning
POST /katja/generic-chat- Generic chat with any model (supports LaTeX)DELETE /katja/generic-chat/clear- Clear generic chat history
GET /katja/console/history?type=language- Get language learning conversation historyGET /katja/console/history?type=general- Get general/legal/medical chat historyGET /katja/system/logs- Stream backend logs (real-time)
GET /katja/models- List all available Ollama modelsGET /katja/system/models- List available models with metadataPOST /katja/system/models/select- Switch active model
GET /katja/reviews/due- Get corrections due for reviewPOST /katja/reviews/{correction_id}/review- Submit review result
GET /katja/analytics/progress- Learning progress stats
cd backend
pytestSQLite database (backend/data/katja.db) auto-initializes with the following tables:
Language Learning Tables:
user_profile- User sessions, language preferences, and statisticsconversation_history- Language learning conversations with original and corrected textgrammar_corrections- Corrections with spaced repetition metadata (SM-2 algorithm)grammar_patterns- Common grammar patterns for 7 languages (seed data)
Multi-Mode Tables:
generic_conversations- Shared conversation history for General Chat, Legal Chat, and Medical Chat modes- Tracks
session_id,role,content,timestamp, andmodel_used - Enables context memory across conversation turns
- Queried by Console mode for monitoring
- Tracks
Features:
- WAL mode enabled - Write-Ahead Logging for better concurrency (multiple reads during writes)
- Session isolation - Each browser tab gets unique
session_idstored in localStorage - Persistence - Conversations survive page refreshes and browser restarts
- Auto-initialization - Tables created automatically on first startup
Database location: /backend/data/katja.db (auto-created, not tracked in git)
Backend won't start:
- Check Ollama is running:
ollama list - Verify Python dependencies:
pip install -r requirements.txt - Check
.envfile exists (copy from.env.example)
No grammar corrections:
- Verify model supports JSON output (use
llama3:8b-instruct-q4_K_M) - Check backend logs in UI or
/tmp/katja-backend.log
Frontend errors:
- Ensure backend is running on port 8000
- Check CORS settings in
.env(add your frontend port)
Apache License 2.0
You are free to use, modify, and redistribute this code. See LICENSE for full terms.
S.M.Laignel. (2025). Katja: A Multi-Mode AI Chat Platform with Specialized LLMs for Language Learning, Legal Reasoning, and Medical Queries.
GitHub Repository. https://github.com/SL-MAR/katja




