A Python library that provides core functionality to send AI metering data to Revenium.
Project description
🔄 Revenium Core Middleware
A foundational library that provides core metering functionality shared across all Revenium AI provider-specific middleware implementations (OpenAI, Anthropic, Ollama, etc). 🐍✨
✨ Features
- 🧠 Shared Core Functionality: Provides the essential metering infrastructure used by all Revenium middleware implementations
- 🔄 Asynchronous Processing: Background thread management for non-blocking metering operations
- 🛑 Graceful Shutdown: Ensures all metering data is properly sent even during application shutdown
- 🔌 Provider Agnostic: Designed to work with any AI provider through specific middleware implementations
📥 Installation
pip install revenium-middleware-core
🔧 Usage
🔄 Direct Usage
While this package is primarily intended as a dependency for provider-specific middleware, you can use it directly:
from revenium_middleware_core import client, run_async_in_thread, shutdown_event
# Record usage directly
client.record_usage(
model="gpt-4",
prompt_tokens=500,
completion_tokens=200,
user_id="user123",
session_id="session456"
)
# Run async metering tasks in background threads
async def async_metering_task():
await client.async_record_usage(
model="gpt-3.5-turbo",
prompt_tokens=300,
completion_tokens=150,
user_id="user789"
)
thread = run_async_in_thread(async_metering_task())
# Application continues while metering happens in background
🏗️ Building Provider-Specific Middleware
This library is designed to be extended by provider-specific middleware implementations:
from revenium_middleware_core import client, run_async_in_thread
# Example of how a provider-specific middleware might use the core
def record_provider_usage(response_data, metadata):
# Extract token counts from provider-specific response format
prompt_tokens = response_data.usage.prompt_tokens
completion_tokens = response_data.usage.completion_tokens
# Use the core client to record the usage
run_async_in_thread(
client.async_record_usage(
model=response_data.model,
prompt_tokens=prompt_tokens,
completion_tokens=completion_tokens,
**metadata
)
)
🔄 Compatibility
- 🐍 Python 3.8+
- 🤝 Compatible with all Revenium provider-specific middleware implementations
📚 Documentation
For more detailed documentation, please refer to the docstrings in the code or visit our GitHub repository.
👥 Contributing
Contributions are welcome! Please check out our contributing guidelines for details.
- 🍴 Fork the repository
- 🌿 Create your feature branch (
git checkout -b feature/amazing-feature) - 💾 Commit your changes (
git commit -m 'Add some amazing feature') - 🚀 Push to the branch (
git push origin feature/amazing-feature) - 🔍 Open a Pull Request
📄 License
This project is licensed under the Apache Software License - see the LICENSE file for details.
🙏 Acknowledgments
- 💖 Built with ❤️ by the Revenium team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file revenium_middleware-0.2.2.tar.gz.
File metadata
- Download URL: revenium_middleware-0.2.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36520a80660e661a80a4538c14b2e8257d6ff5e59d395ed979c88eb5c3ba66d5
|
|
| MD5 |
fe5350c172a6588f1d8ddb01d4dc2b8b
|
|
| BLAKE2b-256 |
46fc6d901d4cfabefe89727d40efd845bd4ff53f02d954327417c0589ae85ae8
|
File details
Details for the file revenium_middleware-0.2.2-py3-none-any.whl.
File metadata
- Download URL: revenium_middleware-0.2.2-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ec0279a2177efc012719de721bea0fa7b894338fc7fab712423cdccd4683ab2
|
|
| MD5 |
f82238f002ad245d517574b6d7cf3156
|
|
| BLAKE2b-256 |
9514c9febf5540a89b56a98483466f456c294307379a801896a7535a3ffe2e41
|