AI-powered automatic link classification for LinkAce using Ollama
Automatically classify links from a LinkAce input list into appropriate classification lists using AI-powered content analysis. The classifier uses Ollama for intelligent link classification with confidence scoring to ensure accurate categorization.
- ๐ค AI-Powered Classification: Uses Ollama server for intelligent link analysis
- ๐ฏ Confidence Scoring: Only moves links with high confidence scores (configurable threshold)
- ๐ LinkAce Integration: Seamlessly integrates with LinkAce API v2.1+
- ๐งช Dry Run Mode: Test classifications without making actual changes
- โ๏ธ Flexible Configuration: CLI arguments, config files, and environment variables
- ๐ Comprehensive Logging: Detailed progress tracking and classification reporting
- ๐พ Export Results: Save classification results to CSV or JSON formats
- ๐ก๏ธ Error Handling: Robust error handling with automatic retry and rate limiting
- Python 3.8+
- LinkAce instance with API access
- Ollama server running locally or remotely
-
Clone the repository:
git clone https://github.com/alx/linkace-classifier.git cd linkace-classifier -
Install the package:
pip install .
git clone https://github.com/alx/linkace-classifier.git
cd linkace-classifier
pip install -e .- Set up Ollama:
# Install Ollama (see https://ollama.ai/) curl -fsSL https://ollama.ai/install.sh | sh # Pull a model ollama pull llama3.2 # Start the server ollama serve
linkace-classifier \
--api-url https://your-linkace.com/api/v2 \
--token YOUR_API_TOKEN \
--input-list 12 \
--classify-lists 1,2,3,4,5linkace-classifier \
--api-url https://your-linkace.com/api/v2 \
--token YOUR_API_TOKEN \
--input-list 12 \
--classify-lists 1,2,3,4,5 \
--dry-run- ๐ฅ Load Input List: Fetches all links from the specified input list
- ๐ Load Classification Context: Retrieves links from classification lists for AI context
- ๐ค AI Classification: For each input link:
- Analyzes link content, title, and metadata
- Compares against existing links in classification lists
- Generates confidence scores for each potential classification
- ๐ฏ Threshold Filtering: Only processes classifications above confidence threshold (default: 0.8)
- ๐ Link Movement: Removes links from input list and adds to appropriate classification lists
- ๐ Results: Provides detailed summary of classifications and movements
| Argument | Description | Required |
|---|---|---|
--api-url |
LinkAce API base URL | Yes |
--token |
LinkAce API token | Yes |
--input-list |
Input list ID to classify links from | Yes |
--classify-lists |
Comma-separated classification list IDs | Yes |
--config |
Configuration file path | No |
--ollama-url |
Ollama server URL (default: http://localhost:11434) | No |
--ollama-model |
Ollama model to use (default: llama3.2) | No |
--confidence-threshold |
Confidence threshold (default: 0.8) | No |
--dry-run |
Run in dry-run mode | No |
--verbose |
Enable verbose output | No |
--output-file |
Output file for results (CSV or JSON) | No |
Create a configs/config.json file:
{
"linkace_api_url": "https://your-linkace.com/api/v2",
"linkace_api_token": "your-api-token",
"input_list_id": 12,
"classify_list_ids": [1, 2, 3, 4, 5],
"ollama_url": "http://localhost:11434",
"ollama_model": "llama3.2",
"confidence_threshold": 0.8,
"dry_run": false,
"verbose": false
}Generate a sample configuration:
python src/linkace_classifier/core/config.pyexport LINKACE_API_URL="https://your-linkace.com/api/v2"
export LINKACE_API_TOKEN="your-api-token"
export INPUT_LIST_ID=12
export CLASSIFY_LIST_IDS="1,2,3,4,5"
export OLLAMA_URL="http://localhost:11434"
export CONFIDENCE_THRESHOLD=0.8The classifier uses these LinkAce API v2.1+ endpoints:
GET /lists/{id}/links- Retrieve all links from a specific listGET /links/{id}- Get detailed information about individual linksPUT /links/{id}- Update link list assignments
- Log into your LinkAce instance
- Go to User Settings โ API Tokens
- Create a new token with appropriate permissions
- Use the token in your configuration
Run the comprehensive test suite:
python tests/test_core.pyRun the demo with existing CSV data:
python scripts/demo_classifier.py[2024-01-15 10:30:00] INFO: Starting LinkAce Link Classifier
โ
LinkAce API connection successful
โ
Ollama server connection successful
[2024-01-15 10:30:01] INFO: Loaded 25 links from input list
[2024-01-15 10:30:02] INFO: Loaded 150 total links from 5 classification lists
Progress: |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 100.0% (25/25)
============================================================
๐ CLASSIFICATION SUMMARY
============================================================
Total links processed: 25
Links classified: 18
Links not classified: 7
Classification rate: 72.0%
Classifications by list:
List 1: 8 links
List 2: 5 links
List 3: 3 links
List 4: 2 links
Confidence statistics:
Average: 0.847
Range: 0.801 - 0.923
============================================================
linkace-classifier \
--ollama-model llama3.1:70b \
--ollama-url http://localhost:11434 \
[other options]linkace-classifier \
--confidence-threshold 0.7 \
--output-file results.csv \
--verbose \
[other options]linkace-classifier --config configs/config.jsonStart the HTTP API server:
linkace-classifier-server --config configs/config.json --host 0.0.0.0 --port 8080Make classification requests:
curl -X POST http://localhost:8080/classify \
-H "Content-Type: application/json" \
-d '{"url": "https://github.com/user/repo"}'- API Token Security: Tokens are never logged or exposed in output
- Input Validation: All inputs are validated and sanitized
- Rate Limiting: Built-in rate limiting prevents API abuse
- Safe Defaults: Conservative defaults for all operations
- Dry Run Testing: Always test with
--dry-runbefore production use
- Batch Processing: Efficiently handles large link collections
- Pagination Support: Automatically handles paginated API responses
- Memory Efficient: Processes links in batches to manage memory usage
- Rate Limiting: Configurable delays between API calls
- Progress Tracking: Real-time progress indicators for long-running operations
- Resumable Operations: Graceful handling of interruptions
The classifier works with any Ollama model, but these are recommended:
| Model | Speed | Accuracy | Use Case |
|---|---|---|---|
llama3.2 |
Fast | Good | Default choice |
llama3.1:70b |
Slow | Excellent | High-accuracy needs |
codellama:13b |
Medium | Good | Technical links |
mistral:7b |
Very Fast | Fair | Quick processing |
โ LinkAce API Connection Failed
โ LinkAce API connection failed: 404 Client Error- Verify your LinkAce URL and API token
- Ensure API token has necessary permissions
- Check LinkAce instance is running and accessible
โ Ollama Connection Failed
โ Ollama server connection failed- Start Ollama server:
ollama serve - Verify server URL and port
- Check model availability:
ollama list
โ ๏ธ No classifications above threshold- Lower confidence threshold:
--confidence-threshold 0.7 - Ensure classification lists have sufficient context links
- Verify input links are accessible and have content
๐ Rate Limiting Issues
429 Too Many Requests- Increase rate limit delay in configuration
- Use smaller batch sizes
- Check LinkAce instance rate limits
Enable detailed logging:
linkace-classifier --verbose [other options]linkace-classifier/
โโโ README.md # Project documentation
โโโ LICENSE # License file
โโโ requirements.txt # Python dependencies
โโโ setup.py # Package setup
โโโ pyproject.toml # Modern Python packaging
โโโ Dockerfile # Container setup
โโโ docker-compose.yml # Container orchestration
โโโ src/
โ โโโ linkace_classifier/ # Main package
โ โโโ __init__.py # Package initialization
โ โโโ core/ # Configuration, utilities, classifier
โ โโโ api/ # LinkAce & Ollama clients
โ โโโ http/ # Flask server
โ โโโ cli/ # Command-line interfaces
โ โโโ services/ # Classification service
โ โโโ validation/ # URL validation
โโโ tests/ # Test files
โโโ configs/ # Configuration files
โโโ scripts/ # Demo and legacy scripts
โโโ docs/ # Documentation
โโโ examples/ # Usage examples
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Add tests for new functionality
- Ensure all tests pass:
python tests/test_core.py - Submit a pull request
Please use the GitHub Issues to report bugs or request features.
This project is licensed under the MIT License - see the LICENSE file for details.
- LinkAce - The excellent bookmark manager this tool integrates with
- Ollama - The AI inference engine powering intelligent classification
- Documentation: Check this README and inline code documentation
- Issues: Report bugs via GitHub Issues
- Discussions: Join conversations in GitHub Discussions
Made with โค๏ธ for the LinkAce community