Senechal is a personal API designed to retrieve data from various sources and expose it through a structured FastAPI service. It features a unified LLM service for content processing, health data tracking, and learning management.
- Unified LLM Service: Process content from URLs or text using various AI models with flexible prompts
- Health Data Integration: Track rowing workouts and health metrics with automated data extraction
- Learning Management: Extract knowledge from content and save structured learning notes
- Content Analysis: Summarize, classify, extract key information, and analyze sentiment
- Secure API key-based authentication with role-based access control (RBAC)
- RESTful API design with comprehensive OpenAPI documentation
- Designed to be run as a systemd service for stability
- Reverse proxied via NGINX for HTTPS access
- Runs inside a Python virtual environment (venv) for dependency management
cd /home/ubuntu/api/
git clone https://github.com/yourusername/senechal.gitcd /home/ubuntu/api/senechal
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtModify config/api_keys.yaml and config/api_roles.yaml:
api_keys:
"abc123": "read"
"xyz789": "write"roles:
read:
access:
- "/getTest"
write:
access:
- "/getTest"
- "/setTest"Ensure these files are not publicly accessible by setting permissions:
chmod 600 /home/ubuntu/api/senechal/config/api_keys.yaml
chmod 600 /home/ubuntu/api/senechal/config/api_roles.yamlCreate the systemd service file:
sudo nano /etc/systemd/system/senechal.service[Unit]
Description=Senechal API (FastAPI)
After=network.target
[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/api/senechal
ExecStart=/home/ubuntu/api/senechal/venv/bin/uvicorn main:app --host 127.0.0.1 --port 8000
Restart=always
[Install]
WantedBy=multi-user.targetReload and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable senechal
sudo systemctl start senechal
sudo systemctl status senechalEnsure that NGINX is correctly proxying requests to the FastAPI service. Edit the NGINX site configuration:
sudo nano /etc/nginx/sites-enabled/yourwebsite.confAdd the following:
location /api/senechal/ {
proxy_pass http://127.0.0.1:8000/;
rewrite ^/api/senechal(/.*)$ $1 break;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}Test and reload NGINX:
sudo nginx -t
sudo systemctl reload nginxAll LLM operations are now consolidated under /llm/ endpoints:
POST /llm/process- Unified LLM processing with full parameter controlGET /llm/prompts- List available named promptsGET /llm/list- List all saved LLM resultsGET /llm/file/{id}- Retrieve saved result by IDDELETE /llm/file/{id}- Delete saved result
POST /llm/extract- Extract learning points from content (equivalent to/learning/scrape)POST /llm/analyze- Analyze content with various types (summary, extraction, classification)POST /llm/custom- Process content with custom prompts
POST /health/rowing/submit- Submit rowing workout image for data extractionGET /health/rowing/get/{period}- Get rowing workout dataGET /health/summary/{period}- Get health metrics summaryGET /health/profile- Get health profile
POST /learning/scrape- Now uses unified LLM service internallyPOST /analysis/analyze- Now uses unified LLM service internallyGET /analysis/list- List analysis resultsGET /analysis/types- Get available analysis types
curl -X POST "https://yoursite.com/api/senechal/llm/extract" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"query_url": "https://example.com/article", "save_result": true}'curl -X POST "https://yoursite.com/api/senechal/llm/analyze" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"analysis_type": "summary",
"query_text": "Your text content here",
"save_result": false
}'curl -X POST "https://yoursite.com/api/senechal/llm/custom" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"custom_prompt": "Translate this to French:",
"query_text": "Hello, how are you?",
"save_result": false
}'curl -H "X-API-Key: your-api-key" \
"https://yoursite.com/api/senechal/llm/prompts"Test basic functionality:
curl -H "X-API-Key: HandwritingRepair" https://yourwebsite.com/api/senechal/getTestTest unified LLM service:
curl -H "X-API-Key: HandwritingRepair" https://yourwebsite.com/api/senechal/llm/promptsExpected prompts output:
{
"status": "success",
"message": "Found 5 available prompts",
"data": [
{"name": "extract_learning", "description": "Extract key learning points", "category": "learning"},
{"name": "analyze_summary", "description": "Generate comprehensive summary", "category": "analysis"}
]
}If errors occur, check logs:
sudo journalctl -u senechal --no-pager --lines=50
sudo tail -f /var/log/nginx/error.log# Database Paths
WITHINGS_DB_PATH=/path/to/withings.db
SENECHAL_DB_PATH=/path/to/senechal.db
# File Locations
LEARNING_CONTENT_PATH=/path/to/learning_content
# API Configuration
API_KEYS_PATH=/path/to/api_keys.yaml
API_ROLES_PATH=/path/to/api_roles.yaml
HEALTH_PROFILE_PATH=/path/to/health_profile.json
# API Endpoint
SENECHAL_API_URL=http://127.0.0.1:8000
SENECHAL_API_KEY=HandwritingRepair
# External APIs
JINAAI_API_KEY=your_jina_api_key
YOUTUBE_API_KEY=your_youtube_api_keyEnsure your API roles include the new LLM endpoints:
roles:
admin:
access:
- "/health/profile"
- "/health/rowing/submit"
- "/learning/scrape"
- "/analysis/analyze"
- "/llm/process"
- "/llm/prompts"
- "/llm/list"
- "/llm/file"
- "/llm/extract"
- "/llm/analyze"
- "/llm/custom"To pull new updates and restart:
cd /home/ubuntu/api/senechal
git pull origin main
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart senechalTest all endpoints:
python test_api_endpoints.pyStart development server:
source venv/bin/activate
uvicorn app.main:app --host 127.0.0.1 --port 8000 --reloadView interactive API docs at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc - OpenAPI Spec:
http://localhost:8000/openapi.json