Metadata-Version: 2.4
Name: ollama-token-monitor
Version: 0.2.0
Summary: Production-ready Ollama token usage monitoring with auto-conversation splitting at configurable thresholds
Home-page: https://github.com/yourusername/ollama-token-monitor
Author: Your Name
Author-email: Your Name <your.email@example.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/ollama-token-monitor
Project-URL: Bug Tracker, https://github.com/yourusername/ollama-token-monitor/issues
Project-URL: Documentation, https://ollama-token-monitor.readthedocs.io
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml>=6.0
Requires-Dist: jsonschema>=4.0
Requires-Dist: aiohttp>=3.8
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: flake8>=5.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# Ollama Token Monitor 🚀

Production-ready Ollama token usage monitoring with automatic conversation splitting at configurable thresholds.

## 🌟 Features

- **Real-time token tracking** - Monitor usage from Ollama API responses
- **Auto-conversation splitting** - Split at 95% threshold to avoid truncation
- **Context preservation** - Preserve system prompts and state across splits
- **State persistence** - Save/load from JSON files
- **Exponential backoff** - Robust retry logic with jitter
- **Comprehensive logging** - Structured logging with configurable levels
- **Thread-safe** - RLock protection for all shared state
- **Multiple models** - Support for multiple Ollama models
- **Config-driven** - YAML/JSON configuration files
- **Performance profiling** - Sliding window metrics and percentiles

## 📦 Installation

```bash
pip install ollama-token-monitor
```

Or from source:

```bash
pip install -e .
```

## 🚀 Quick Start

```python
from ollama_token_monitor import OllamaTokenMonitor, TokenMonitorConfig

# Configure
config = TokenMonitorConfig(
    ollama_host="http://localhost:11434",
    threshold_percent=95.0,
    check_interval_ms=500,
    max_retries=5,
    log_level="DEBUG",
)

# Create monitor
monitor = OllamaTokenMonitor(config)

# Start monitoring
monitor._start_monitoring()

# Get usage
print(f"Token usage: {monitor.get_percent_used():.2f}%")

# Stop
monitor.stop()
```

## 📋 Configuration

### YAML

```yaml
models:
  - name: "DeepSeek-V4-Pro"
    model: "hf.co/mradermacher/DeepSeek-V4-Pro-Qwen3.5-9B-UNCENSORED-heretic-i1-GGUF:Q4_K_M"
    ollama_host: "http://localhost:11434"
    threshold_percent: 95.0
    context_window: 8192
    check_interval_ms: 500
    max_retries: 5
    base_delay_ms: 100
    smart_preservation: true
    enable_profiling: true
    cache_enabled: true
```

### JSON

```json
{
  "models": [
    {
      "name": "DeepSeek-V4-Pro",
      "model": "hf.co/mradermacher/DeepSeek-V4-Pro-Qwen3.5-9B-UNCENSORED-heretic-i1-GGUF:Q4_K_M",
      "ollama_host": "http://localhost:11434",
      "threshold_percent": 95.0
    }
  ]
}
```

## 📁 Project Structure

```
ollama_token_monitor/
├── __init__.py
├── monitor.py
├── integration.py
├── cache.py
├── profiler.py
├── config.py
├── models.py
├── setup.py
├── pyproject.toml
├── README.md
├── CHANGELOG.md
├── LICENSE
└── tests/
    ├── test_monitor.py
    ├── test_integration.py
    ├── test_cache.py
    └── test_config.py
```

## 🧪 Testing

```bash
pytest tests/ -v --cov=ollama_token_monitor
```

## 📚 Documentation

- [Configuration Guide](https://github.com/yourusername/ollama-token-monitor/blob/main/OLLAMA_TOKEN_MONITOR_CONFIG.md)
- [Error Handling](https://github.com/yourusername/ollama-token-monitor/blob/main/OLLAMA_TOKEN_MONITOR_ERROR_HANDLING.md)
- [API Reference](https://github.com/yourusername/ollama-token-monitor/blob/main/docs/api.rst)

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Open a Pull Request

## 📜 License

MIT License - see [LICENSE](https://github.com/yourusername/ollama-token-monitor/blob/main/LICENSE) for details.

## 🌐 Support

- [GitHub Issues](https://github.com/yourusername/ollama-token-monitor/issues)
- [GitHub Discussions](https://github.com/yourusername/ollama-token-monitor/discussions)
