Skip to content
Aiman-DPublic

About

A personal AI assistant powered by Ollama (Llama 3.1) that integrates with Telegram BotFather and provides support for Apple Watch and other clients.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Personal AI Agent with Telegram & Apple Watch Support

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.

Features

  • 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

Setup

Prerequisites

  1. Ollama: Install and run Ollama with Llama 3.1

    # Install Ollama from https://ollama.ai
    ollama pull llama3.1
    ollama serve
  2. Python 3.8+: Ensure Python is installed

  3. Telegram Bot (optional): Create a bot via BotFather

    • Message @BotFather on Telegram
    • Create a new bot with /newbot
    • Copy the API token

Installation

  1. Clone or navigate to the project directory

  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. 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.

Running the Services

Telegram Bot

Run the Telegram bot:

python bot.py

The bot will start polling for messages. Use /commands in Telegram to see all available commands.

REST API Server (for Apple Watch)

Run the API server:

python api.py

The API will be available at http://localhost:5001 (port 5000 is often used by AirPlay on macOS)

API Endpoints

Health Check

GET /health

Chat with AI

POST /chat
Content-Type: application/json

{
  "message": "Your message here"
}

Log Food

POST /log/food
Content-Type: application/json

{
  "food": "ate chicken salad for lunch"
}

Log Workout

POST /log/workout
Content-Type: application/json

{
  "workout": "ran 5km"
}

Log Mood

POST /log/mood
Content-Type: application/json

{
  "mood": "feeling great"
}

Log Weight

POST /log/weight
Content-Type: application/json

{
  "weight": "75"
}

Log Water

POST /log/water
Content-Type: application/json

{
  "glasses": 2
}

Get Reminders

GET /reminders

Set Reminder

POST /reminders
Content-Type: application/json

{
  "message": "remind me to call mom at 6pm"
}

Get Daily Summary

GET /summary

Get Logs

GET /logs?category=all  # or: calories, fitness, mood, water, weight

Quick Actions (Apple Watch)

POST /quick
Content-Type: application/json

{
  "action": "morning"  # Options: morning, evening, water, mood_good, mood_bad, workout
}

Apple Watch Integration

Option 1: Siri Shortcuts (Recommended)

  1. Create Siri Shortcuts that make HTTP requests to your API server

  2. Example shortcuts:

    • Morning Check-in: POST /quick with {"action": "morning"}
    • Log Water: POST /log/water with {"glasses": 1}
    • Log Workout: POST /log/workout with {"workout": "completed workout"}
    • Daily Summary: GET /summary
  3. Add these shortcuts to your Apple Watch face as complications

Option 2: Custom Watch App

For a more integrated experience, you can build a simple watchOS app:

  1. Create a new watchOS project in Xcode
  2. Use URLSession to make HTTP requests to your API server
  3. 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()
}

Network Setup

For Apple Watch to access your API:

  1. Local Network: Ensure your Mac and Apple Watch are on the same Wi-Fi network
  2. Port Forwarding: If accessing from outside your local network, set up port forwarding on your router
  3. Dynamic DNS: Use a service like ngrok for testing:
    ngrok http 5001
  4. Port: The API runs on port 5001 by default (port 5000 is often used by AirPlay on macOS)
  5. HTTPS: For production, use a reverse proxy with SSL (nginx, Caddy, etc.)

Telegram Commands

Lists

  • /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

Health & Fitness

  • /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

Reminders & Notes

  • /remind [message] - Save a reminder
  • /reminders - Show all reminders
  • /note [title] | [content] - Save a note
  • /notes - List all notes
  • /shownote [id] - View a note

Expenses

  • /spend [amount] [category] [description] - Log an expense
  • /expenses - Today's expenses
  • /allexpenses - All recent expenses

Productivity

  • /summary - Today's full summary
  • /logs - Show all today's logs
  • /ask [question] - Ask the AI anything
  • /search [query] - Search the web

Data Storage

All data is stored in SQLite database at ~/myagent/memory.db

Tables:

  • logs - Food, fitness, mood, water, weight entries
  • reminders - Reminders with time and recurrence
  • lists - Todo, grocery, wishlist, etc.
  • notes - Saved notes
  • expenses - Expense tracking
  • habits - Habit tracking
  • snippets - Text snippets

Troubleshooting

Ollama Connection Issues

  • Ensure Ollama is running: ollama serve
  • Check the model is available: ollama list
  • Verify OLLAMA_MODEL in .env matches an installed model

Telegram Bot Not Responding

  • Verify TELEGRAM_TOKEN is correct
  • Check ALLOWED_USER_ID matches your Telegram user ID
  • Ensure the bot is running: python bot.py

API Server Not Accessible from Apple Watch

  • 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

Security Notes

  • 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 .env file secure and never commit it to version control

License

MIT License - Feel free to modify and use for personal projects.

About

A personal AI assistant powered by Ollama (Llama 3.1) that integrates with Telegram BotFather and provides support for Apple Watch and other clients.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages