120 lines
3.3 KiB
Markdown
120 lines
3.3 KiB
Markdown
# Enabling AI Prompt Generation
|
|
|
|
The Daily Check-in system can use AI to automatically:
|
|
- Parse freeform text ("I take vitamin D every morning")
|
|
- Create structured entries (medications, vitals, exercise, etc.)
|
|
- Generate daily tracking prompts with pre-filled values
|
|
- Learn patterns from repeated entries
|
|
|
|
## Current Status
|
|
|
|
✅ Code is ready and deployed
|
|
❌ Gemini API key not configured
|
|
|
|
## Setup Instructions
|
|
|
|
### 1. Get a Gemini API Key
|
|
|
|
1. Go to https://aistudio.google.com/app/apikey
|
|
2. Create a new API key (free tier available)
|
|
3. Copy the key
|
|
|
|
### 2. Configure on Staging
|
|
|
|
```bash
|
|
# On staging server (192.168.1.253)
|
|
echo "GEMINI_API_KEY=YOUR_KEY_HERE" > /tank/inou/api/anthropic.env
|
|
|
|
# Restart API service
|
|
ssh johan@192.168.1.253 "sudo systemctl restart inou-api"
|
|
# Or use the standard restart:
|
|
ssh johan@192.168.1.253 "/tank/inou/stop.sh && /tank/inou/start.sh"
|
|
```
|
|
|
|
### 3. Configure on Production
|
|
|
|
```bash
|
|
# On production server (192.168.100.2)
|
|
echo "GEMINI_API_KEY=YOUR_KEY_HERE" > /tank/inou/api/anthropic.env
|
|
|
|
# Restart API service
|
|
ssh johan@192.168.100.2 "sudo systemctl restart inou-api"
|
|
```
|
|
|
|
### 4. Verify
|
|
|
|
Check the API logs to confirm the key loaded:
|
|
|
|
```bash
|
|
ssh johan@192.168.1.253 "tail -20 /tank/inou/logs/api.log | grep -i gemini"
|
|
```
|
|
|
|
You should see: `Gemini API key loaded.`
|
|
|
|
## Testing
|
|
|
|
Once configured, test by entering freeform text on the prompts page:
|
|
|
|
**Test inputs:**
|
|
- "I take vitamin D 5000 IU every morning"
|
|
- "Blood pressure 120/80"
|
|
- "Walked 30 minutes today"
|
|
|
|
**Expected behavior:**
|
|
1. Entry is created immediately
|
|
2. System analyzes the pattern
|
|
3. If it detects a trackable pattern, it creates a new daily prompt
|
|
4. You see a notification: "✓ Saved! Added new tracking prompt."
|
|
5. The new prompt appears on the page for tomorrow
|
|
|
|
## How It Works
|
|
|
|
### Architecture
|
|
|
|
```
|
|
User Input → Triage (category detection) → Extraction (structure) → Create entries + prompts
|
|
```
|
|
|
|
### Prompts
|
|
|
|
AI prompts are stored in `/tank/inou/prompts/`:
|
|
- `triage.md` - Determines category (medication, vital, exercise, etc.)
|
|
- `extract_*.md` - Category-specific extraction (one per category)
|
|
|
|
### Code
|
|
|
|
- `api/api_llm.go` - Main LLM integration
|
|
- `api/api_prompts.go:192` - `tryGeneratePromptFromFreeform()` entry point
|
|
- `lib/llm.go` - Gemini API wrapper
|
|
|
|
## Cost Estimate
|
|
|
|
Gemini 1.5 Flash (used by default):
|
|
- **Free tier**: 15 requests/minute, 1500 requests/day
|
|
- **Paid tier**: $0.00001875/1K characters input, $0.000075/1K characters output
|
|
|
|
For typical use (10-20 prompts/day), free tier is sufficient.
|
|
|
|
## Alternative: Claude API
|
|
|
|
The code can be adapted to use Claude instead of Gemini. Would need:
|
|
1. Replace `lib.CallGemini()` with Claude API calls
|
|
2. Update prompt formatting (Claude uses different message format)
|
|
3. Set `ANTHROPIC_API_KEY` instead
|
|
|
|
## Fallback Without AI
|
|
|
|
If no API key is configured:
|
|
- Freeform entries still work (saves as plain notes)
|
|
- No automatic prompt generation
|
|
- Users can manually create prompts via the UI (not yet implemented)
|
|
- Or add prompts directly to database
|
|
|
|
## Next Steps
|
|
|
|
1. **Get API key** - Start with Gemini free tier
|
|
2. **Test on staging** - Verify prompt generation works
|
|
3. **Monitor usage** - Check if free tier is sufficient
|
|
4. **Consider Claude** - If Gemini isn't accurate enough
|
|
5. **Build manual prompt creator** - Fallback for users without AI
|