Skip to content

Commit cda822b

Browse files
ktiyabclaude
andcommitted
Release 0.1.0.20260121: Local LLM support, .env configuration, security
Features: - Add OllamaProvider for local LLM (Ollama, LM Studio, LocalAI) - Add .env file configuration with auto-loading (python-dotenv) - Add automatic .env gitignore protection in babel init - Add --version flag to CLI - Add .env.example template with comprehensive documentation Documentation: - Update Quick Install with LLM configuration options - Add "Using .env Files" section - Add "Local LLM (Ollama)" section with setup instructions - Update FAQ with local LLM option Security: - babel init automatically adds .env to .gitignore - Priority: Remote API > Local LLM > MockProvider Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cbce522 commit cda822b

9 files changed

Lines changed: 649 additions & 48 deletions

File tree

.env.example

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# =============================================================================
2+
# Babel Configuration (.env)
3+
# =============================================================================
4+
#
5+
# Copy this file to .env and customize for your setup:
6+
# cp .env.example .env
7+
#
8+
# Then source it before using Babel:
9+
# source .env
10+
#
11+
# Or place .env in your project root for automatic loading (requires python-dotenv).
12+
#
13+
# =============================================================================
14+
#
15+
# ⚠️ SECURITY WARNING - READ BEFORE PROCEEDING
16+
# =============================================================================
17+
#
18+
# NEVER COMMIT YOUR .env FILE TO VERSION CONTROL!
19+
#
20+
# Your .env file contains sensitive API keys and credentials. If committed:
21+
# - Keys are exposed in git history PERMANENTLY (even after deletion)
22+
# - Public repos are scanned by bots within minutes for leaked credentials
23+
# - Leaked keys can lead to unauthorized usage, billing attacks, data breaches
24+
# - Rotating compromised keys is disruptive and may not undo damage
25+
#
26+
# REQUIRED: Ensure .env is in your .gitignore:
27+
#
28+
# echo ".env" >> .gitignore
29+
#
30+
# VERIFY before committing:
31+
#
32+
# git status # .env should NOT appear in untracked/modified files
33+
#
34+
# If you accidentally committed .env:
35+
# 1. Immediately rotate ALL exposed API keys
36+
# 2. Remove from history: git filter-branch or BFG Repo-Cleaner
37+
# 3. Force push (coordinate with team if shared repo)
38+
#
39+
# =============================================================================
40+
41+
# -----------------------------------------------------------------------------
42+
# LLM Provider Selection
43+
# -----------------------------------------------------------------------------
44+
#
45+
# Available providers:
46+
# - claude : Anthropic Claude (requires ANTHROPIC_API_KEY)
47+
# - openai : OpenAI GPT (requires OPENAI_API_KEY)
48+
# - gemini : Google Gemini (requires GOOGLE_API_KEY)
49+
# - ollama : Local LLM via Ollama (no API key needed)
50+
#
51+
# PRIORITY LOGIC:
52+
# If a remote API key is set, the remote provider will be used by default,
53+
# even if BABEL_LLM_PROVIDER=ollama is configured. This ensures that users
54+
# with API keys get the expected behavior while allowing local-only setups.
55+
#
56+
# Priority order: Remote API key > Local LLM > Mock provider
57+
#
58+
# Default: claude (if ANTHROPIC_API_KEY is set)
59+
#
60+
# BABEL_LLM_PROVIDER=claude
61+
62+
# -----------------------------------------------------------------------------
63+
# Remote LLM API Keys (choose one based on your provider)
64+
# -----------------------------------------------------------------------------
65+
#
66+
# IMPORTANT: API keys are sensitive. Never commit them to version control.
67+
# Only ONE provider API key is needed based on your BABEL_LLM_PROVIDER choice.
68+
#
69+
70+
# Anthropic Claude API Key
71+
# Get your key at: https://console.anthropic.com/
72+
# ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
73+
74+
# OpenAI API Key
75+
# Get your key at: https://platform.openai.com/api-keys
76+
# OPENAI_API_KEY=sk-your-key-here
77+
78+
# Google Gemini API Key
79+
# Get your key at: https://makersuite.google.com/app/apikey
80+
# GOOGLE_API_KEY=your-key-here
81+
82+
# -----------------------------------------------------------------------------
83+
# Model Selection
84+
# -----------------------------------------------------------------------------
85+
#
86+
# Override the default model for your chosen provider.
87+
# If not set, uses the provider's default model.
88+
#
89+
# Claude models:
90+
# - claude-opus-4-1-20250414 (Large/Powerful)
91+
# - claude-opus-4-20250514 (Large/Powerful)
92+
# - claude-sonnet-4-20250514 (Balanced - default)
93+
# - claude-3-7-sonnet-20250219 (Lightweight)
94+
# - claude-3-5-haiku-20241022 (Cost-efficient)
95+
#
96+
# OpenAI models:
97+
# - gpt-5.2, gpt-5.2-pro (Large/Powerful)
98+
# - gpt-5-mini (Balanced - default)
99+
# - gpt-5-nano (Cost-efficient)
100+
#
101+
# Gemini models:
102+
# - gemini-2.5-pro (Large/Powerful)
103+
# - gemini-2.5-flash (Balanced - default)
104+
# - gemini-2.5-flash-lite (Cost-efficient)
105+
#
106+
# Ollama models (any locally installed model):
107+
# - llama3.2 (default)
108+
# - mistral
109+
# - phi3
110+
# - codellama
111+
# - etc. (run 'ollama list' to see installed models)
112+
#
113+
# BABEL_LLM_MODEL=claude-sonnet-4-20250514
114+
115+
# -----------------------------------------------------------------------------
116+
# Local LLM Configuration (Ollama)
117+
# -----------------------------------------------------------------------------
118+
#
119+
# For local LLM usage with Ollama or compatible servers (LM Studio, LocalAI).
120+
#
121+
# To use local LLM:
122+
# 1. Install Ollama: curl -fsSL https://ollama.com/install.sh | sh
123+
# 2. Pull a model: ollama pull llama3.2
124+
# 3. Start Ollama: ollama serve
125+
# 4. Set provider: BABEL_LLM_PROVIDER=ollama
126+
#
127+
# Base URL for Ollama API (default: http://localhost:11434)
128+
# Change this if using a different port or remote Ollama server.
129+
#
130+
# BABEL_LLM_BASE_URL=http://localhost:11434
131+
#
132+
# For LM Studio (OpenAI-compatible):
133+
# BABEL_LLM_PROVIDER=ollama
134+
# BABEL_LLM_BASE_URL=http://localhost:1234/v1
135+
#
136+
# For LocalAI:
137+
# BABEL_LLM_PROVIDER=ollama
138+
# BABEL_LLM_BASE_URL=http://localhost:8080/v1
139+
140+
# -----------------------------------------------------------------------------
141+
# Example Configurations
142+
# -----------------------------------------------------------------------------
143+
#
144+
# === Remote LLM (Claude - Recommended) ===
145+
# BABEL_LLM_PROVIDER=claude
146+
# ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
147+
# BABEL_LLM_MODEL=claude-sonnet-4-20250514
148+
#
149+
# === Remote LLM (OpenAI) ===
150+
# BABEL_LLM_PROVIDER=openai
151+
# OPENAI_API_KEY=sk-your-key-here
152+
# BABEL_LLM_MODEL=gpt-5-mini
153+
#
154+
# === Local LLM (Ollama - Privacy-focused) ===
155+
# BABEL_LLM_PROVIDER=ollama
156+
# BABEL_LLM_MODEL=llama3.2
157+
# BABEL_LLM_BASE_URL=http://localhost:11434
158+
#
159+
# === Local LLM (LM Studio) ===
160+
# BABEL_LLM_PROVIDER=ollama
161+
# BABEL_LLM_MODEL=local-model
162+
# BABEL_LLM_BASE_URL=http://localhost:1234/v1
163+
#
164+
# === Air-gapped Environment (No network) ===
165+
# BABEL_LLM_PROVIDER=ollama
166+
# BABEL_LLM_MODEL=mistral
167+
# # No API keys needed - fully offline operation
168+
169+
# =============================================================================
170+
# Your Configuration (uncomment and edit as needed)
171+
# =============================================================================
172+
173+
# Provider (claude, openai, gemini, ollama)
174+
# BABEL_LLM_PROVIDER=claude
175+
176+
# API Key (for remote providers)
177+
# ANTHROPIC_API_KEY=
178+
179+
# Model override (optional)
180+
# BABEL_LLM_MODEL=
181+
182+
# Base URL (for local LLM)
183+
# BABEL_LLM_BASE_URL=

README.md

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
# Install
1515
git clone https://github.com/ktiyab/babel-tool.git
1616
cd babel-tool && ./install.sh
17+
18+
# Configure LLM (choose one)
19+
export ANTHROPIC_API_KEY="sk-ant-..." # Cloud: Claude (recommended)
20+
# OR use local LLM: export BABEL_LLM_PROVIDER=ollama
1721
```
1822

23+
> **Security:** `babel init` automatically adds `.env` to `.gitignore` to prevent credential leakage.
24+
1925
**Then, only 4 commands to start:**
2026

2127
```bash
@@ -30,7 +36,7 @@ That's it. Your AI assistant handles the 30+ commands—you just review.
3036

3137
> **Other AIs?** `babel prompt --install` auto-configures Claude Code and Cursor. For others, use `babel prompt > /path/to/ai/instructions.md` to write the prompt directly to the path expected by your AI.
3238
33-
**Requirements:** Python 3.9+ • **More options:** [Installation & Configuration](#installation--configuration)
39+
**Requirements:** Python 3.9+ • **LLM options:** [Cloud API](#setting-up-api-keys) or [Local Ollama](#local-llm-ollama)**Full config:** [Installation & Configuration](#installation--configuration)
3440

3541
---
3642

@@ -2604,6 +2610,72 @@ export GOOGLE_API_KEY="..."
26042610

26052611
Add to your shell profile (`~/.bashrc`, `~/.zshrc`) to persist across sessions.
26062612

2613+
#### Using .env Files
2614+
2615+
For project-specific configuration, use a `.env` file:
2616+
2617+
```bash
2618+
# Copy the template
2619+
cp ~/.babel-tool/.env.example .env
2620+
2621+
# Edit with your settings
2622+
nano .env
2623+
```
2624+
2625+
**Example `.env` file:**
2626+
```bash
2627+
# Provider (claude, openai, gemini, ollama)
2628+
BABEL_LLM_PROVIDER=claude
2629+
2630+
# API Key
2631+
ANTHROPIC_API_KEY=sk-ant-...
2632+
2633+
# Model override (optional)
2634+
BABEL_LLM_MODEL=claude-sonnet-4-20250514
2635+
```
2636+
2637+
> **Security:** `babel init` automatically adds `.env` to `.gitignore` to prevent credential leakage. Never commit `.env` files containing API keys.
2638+
2639+
Babel auto-loads `.env` files from:
2640+
1. Current directory (`./.env`)
2641+
2. User config (`~/.babel/.env`)
2642+
2643+
Install `python-dotenv` for automatic loading: `pip install babel-tool[dotenv]`
2644+
2645+
#### Local LLM (Ollama)
2646+
2647+
Run Babel entirely offline with a local LLM—no API keys, no data sent externally.
2648+
2649+
**Setup:**
2650+
```bash
2651+
# 1. Install Ollama
2652+
curl -fsSL https://ollama.com/install.sh | sh
2653+
2654+
# 2. Pull a model
2655+
ollama pull llama3.2
2656+
2657+
# 3. Start Ollama
2658+
ollama serve
2659+
2660+
# 4. Configure Babel
2661+
export BABEL_LLM_PROVIDER=ollama
2662+
export BABEL_LLM_MODEL=llama3.2
2663+
```
2664+
2665+
**Or in `.env`:**
2666+
```bash
2667+
BABEL_LLM_PROVIDER=ollama
2668+
BABEL_LLM_MODEL=llama3.2
2669+
BABEL_LLM_BASE_URL=http://localhost:11434 # Optional, this is the default
2670+
```
2671+
2672+
**Compatible local LLM servers:**
2673+
- [Ollama](https://ollama.com) (recommended)
2674+
- [LM Studio](https://lmstudio.ai) — set `BABEL_LLM_BASE_URL=http://localhost:1234/v1`
2675+
- [LocalAI](https://localai.io) — set `BABEL_LLM_BASE_URL=http://localhost:8080/v1`
2676+
2677+
**Priority logic:** If both an API key and local LLM are configured, Babel uses the remote provider. This ensures users with API keys get cloud quality while allowing offline-only setups.
2678+
26072679
#### Selecting a Provider
26082680

26092681
```bash
@@ -2676,8 +2748,8 @@ For CI/CD or temporary overrides:
26762748

26772749
```bash
26782750
# Override provider for this session
2679-
export INTENT_LLM_PROVIDER=openai
2680-
export INTENT_LLM_MODEL=gpt-5-nano
2751+
export BABEL_LLM_PROVIDER=openai
2752+
export BABEL_LLM_MODEL=gpt-5-nano
26812753

26822754
babel scan # Uses OpenAI with gpt-5-nano
26832755
```
@@ -2730,6 +2802,8 @@ babel capture "..." # Falls back to pattern matching
27302802
babel scan # Requires LLM
27312803
```
27322804

2805+
**Want LLM features offline?** Use [Local LLM (Ollama)](#local-llm-ollama) — full LLM capabilities without sending data externally.
2806+
27332807
### Display Options
27342808

27352809
```bash
@@ -2908,8 +2982,9 @@ With an API key, Babel's internal LLM summarizes and structures that history *be
29082982
**The tradeoff:**
29092983
- No API key = works offline, but context overload risk at scale
29102984
- With API key = optimized context, scales to large projects (pennies per query)
2985+
- With local LLM (Ollama) = full LLM features offline, no data sent externally
29112986

2912-
**Recommendation:** Set up an API key early. Claude Sonnet is the default and offers a good balance of quality and cost.
2987+
**Recommendation:** Set up an API key early (Claude Sonnet is the default). Or use [Ollama](#local-llm-ollama) for fully private, offline operation.
29132988

29142989
### How does my AI assistant know about Babel?
29152990

babel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
babel hooks install
2222
"""
2323

24-
__version__ = "0.1.0"
24+
__version__ = "0.1.0.20260121"
2525

2626
# Core layer (data)
2727
from .core.events import EventStore, DualEventStore, Event, EventType

babel/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from .commands.gaps import GapsCommand
6161
from .preferences import MemoManager
6262
from .content import HELP_TEXT, PRINCIPLES_TEXT
63+
from . import __version__
6364

6465

6566
class IntentCLI:
@@ -679,6 +680,12 @@ def main():
679680
help='Project directory (default: current)'
680681
)
681682

683+
parser.add_argument(
684+
'--version', '-V',
685+
action='version',
686+
version=f'babel {__version__}'
687+
)
688+
682689
subparsers = parser.add_subparsers(dest='command', help='Commands')
683690

684691
# init

0 commit comments

Comments
 (0)