A personal AI assistant powered by Ollama (Llama 3.1) that integrates with Telegram BotFather and provides a REST API for Apple Watch and other clients.
- AI Chat: Natural language conversations with memory context
- Health Tracking: Log calories, workouts, weight, water, and mood
- Reminders: Set and manage reminders with natural language time parsing
- Lists: Manage todo, grocery, wishlist, watchlist, reading, ideas, and goals
- Notes: Save and retrieve notes
- Expenses: Track spending with categories
- Web Search: Search the web via DuckDuckGo
- Daily Summary: Get AI-powered summaries of your day
-
Ollama: Install and run Ollama with Llama 3.1
# Install Ollama from https://ollama.ai ollama pull llama3.1 ollama serve -
Python 3.8+: Ensure Python is installed
-
Telegram Bot (optional): Create a bot via BotFather
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Copy the API token
-
Clone or navigate to the project directory
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables in
.env:TELEGRAM_TOKEN=your_telegram_bot_token ALLOWED_USER_ID=your_telegram_user_id OLLAMA_MODEL=llama3.1
To get your Telegram user ID, message @userinfobot on Telegram.
Run the Telegram bot:
python bot.pyThe bot will start polling for messages. Use /commands in Telegram to see all available commands.
Run the API server:
python api.pyThe API will be available at http://localhost:5001 (port 5000 is often used by AirPlay on macOS)
GET /health
POST /chat
Content-Type: application/json
{
"message": "Your message here"
}
POST /log/food
Content-Type: application/json
{
"food": "ate chicken salad for lunch"
}
POST /log/workout
Content-Type: application/json
{
"workout": "ran 5km"
}
POST /log/mood
Content-Type: application/json
{
"mood": "feeling great"
}
POST /log/weight
Content-Type: application/json
{
"weight": "75"
}
POST /log/water
Content-Type: application/json
{
"glasses": 2
}
GET /reminders
POST /reminders
Content-Type: application/json
{
"message": "remind me to call mom at 6pm"
}
GET /summary
GET /logs?category=all # or: calories, fitness, mood, water, weight
POST /quick
Content-Type: application/json
{
"action": "morning" # Options: morning, evening, water, mood_good, mood_bad, workout
}
-
Create Siri Shortcuts that make HTTP requests to your API server
-
Example shortcuts:
- Morning Check-in: POST
/quickwith{"action": "morning"} - Log Water: POST
/log/waterwith{"glasses": 1} - Log Workout: POST
/log/workoutwith{"workout": "completed workout"} - Daily Summary: GET
/summary
- Morning Check-in: POST
-
Add these shortcuts to your Apple Watch face as complications
For a more integrated experience, you can build a simple watchOS app:
- Create a new watchOS project in Xcode
- Use URLSession to make HTTP requests to your API server
- Design a simple UI with quick-action buttons
Example Swift code for making requests:
import Foundation
func sendMessage(_ message: String) {
guard let url = URL(string: "http://your-server-ip:5000/chat") else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: String] = ["message": message]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, _, _ in
if let data = data,
let response = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let result = response["response"] as? String {
print(result)
}
}
task.resume()
}For Apple Watch to access your API:
- Local Network: Ensure your Mac and Apple Watch are on the same Wi-Fi network
- Port Forwarding: If accessing from outside your local network, set up port forwarding on your router
- Dynamic DNS: Use a service like ngrok for testing:
ngrok http 5001
- Port: The API runs on port 5001 by default (port 5000 is often used by AirPlay on macOS)
- HTTPS: For production, use a reverse proxy with SSL (nginx, Caddy, etc.)
/want [item]- Add to wishlist/todo [task]- Add to to-do list/grocery [item]- Add to grocery list/watchlist [movie/show]- Add to watchlist/reading [book]- Add to reading list/ideas [idea]- Save an idea/goals [goal]- Add a goal/showlist [name]- Show a list/done [id]- Mark item as done/delete [id]- Delete item/clearlist [name]- Clear entire list
/calories [food]- Log food & auto-estimate calories/workout [description]- Log a workout/weight [kg]- Log your weight/water [glasses]- Log water intake/mood [how you feel]- Log your mood/health- Show today's health summary
/remind [message]- Save a reminder/reminders- Show all reminders/note [title] | [content]- Save a note/notes- List all notes/shownote [id]- View a note
/spend [amount] [category] [description]- Log an expense/expenses- Today's expenses/allexpenses- All recent expenses
/summary- Today's full summary/logs- Show all today's logs/ask [question]- Ask the AI anything/search [query]- Search the web
All data is stored in SQLite database at ~/myagent/memory.db
Tables:
logs- Food, fitness, mood, water, weight entriesreminders- Reminders with time and recurrencelists- Todo, grocery, wishlist, etc.notes- Saved notesexpenses- Expense trackinghabits- Habit trackingsnippets- Text snippets
- Ensure Ollama is running:
ollama serve - Check the model is available:
ollama list - Verify OLLAMA_MODEL in
.envmatches an installed model
- Verify TELEGRAM_TOKEN is correct
- Check ALLOWED_USER_ID matches your Telegram user ID
- Ensure the bot is running:
python bot.py
- Check firewall settings on your Mac
- Ensure devices are on the same network
- Test with curl:
curl http://localhost:5000/health - Use ngrok for external testing:
ngrok http 5000
- The API server currently has no authentication - add API keys for production use
- Telegram bot is restricted to a single user ID
- Consider adding HTTPS for production deployments
- Keep your
.envfile secure and never commit it to version control
MIT License - Feel free to modify and use for personal projects.