Hivetrace SDK for monitoring LLM applications
Project description
Hivetrace SDK
Description Hivetrace SDK is designed for integration with the Hivetrace service, providing monitoring of user prompts and LLM responses.
Installation Install the SDK via pip:
pip install hivetrace
Usage
from hivetrace.hivetrace import HivetraceSDK
Synchronous and Asynchronous Modes
Hivetrace SDK supports both synchronous and asynchronous execution modes.
Initialization with Sync/Async Mode
By default, the SDK operates in asynchronous mode. You can explicitly specify the mode during initialization:
# Async mode (default)
hivetrace = HivetraceSDK(async_mode=True)
# Sync mode
hivetrace = HivetraceSDK(async_mode=False)
Send a user prompt
# Async mode
response = hivetrace.input_async(
application_id="your-application-id", # get after registering the application in the UI
message="User prompt here"
)
# Sync mode
response = hivetrace.input(
application_id="your-application-id", # get after registering the application in the UI
message="User prompt here"
)
Send a response from your LLM
# Async mode
response = hivetrace.output_async(
application_id="your-application-id", # get after registering the application in the UI
message="LLM response here"
)
# Sync mode
response = hivetrace.output(
application_id="your-application-id", # get after registering the application in the UI
message="LLM response here"
)
Example with additional parameters
response = hivetrace.input(
application_id="your-application-id",
message="User prompt here",
additional_parameters={
"session_id": "your-session-id",
"user_id": "your-user-id",
"agents": {
"agent-1-id": {"name": "Agent 1", "description": "Agent description"},
"agent-2-id": {"name": "Agent 2"},
"agent-3-id": {}
}
}
)
session_id, user_id, agent_id - must be a valid UUID
API
input(application_id: str, message: str, additional_parameters: dict = None) -> dict
Sends a user prompt to Hivetrace.
application_id- Application identifier (must be a valid UUID, created in the UI)message- User promptadditional_parameters- Dictionary of additional parameters (optional)
Response Example:
{
"status": "processed",
"monitoring_result": {
"is_toxic": false,
"type_of_violation": "benign",
"token_count": 9,
"token_usage_warning": false,
"token_usage_unbounded": false
}
}
output(application_id: str, message: str, additional_parameters: dict = None) -> dict
Sends an LLM response to Hivetrace.
application_id- Application identifier (must be a valid UUID, created in the UI)message- LLM responseadditional_parameters- Dictionary of additional parameters (optional)
Response Example:
{
"status": "processed",
"monitoring_result": {
"is_toxic": false,
"type_of_violation": "safe",
"token_count": 21,
"token_usage_warning": false,
"token_usage_unbounded": false
}
}
Sending Requests in Async Mode
When using async mode, you can send requests asynchronously:
import asyncio
async def main():
hivetrace = HivetraceSDK(async_mode=True)
response = await hivetrace.input_async(
application_id="your-application-id", # get after registering the application in the UI
message="User prompt here"
)
await hivetrace.close()
asyncio.run(main())
Sending Requests in Sync Mode
If you prefer synchronous execution, you can send requests normally:
def main():
hivetrace = HivetraceSDK(async_mode=False)
response = hivetrace.input(
application_id="your-application-id", # get after registering the application in the UI
message="User prompt here"
)
main()
Closing the Async Client
When using async mode, remember to close the session when done:
await hivetrace.close()
Configuration
The SDK loads configuration from environment variables. The allowed domain (HIVETRACE_URL) and API token (HIVETRACE_ACCESS_TOKEN) are automatically retrieved from the environment.
Configuration Sources
Hivetrace SDK can retrieve the configuration from the following sources:
.env File:
HIVETRACE_URL=https://your-hivetrace-instance.com
HIVETRACE_ACCESS_TOKEN=your-access-token # get in the UI (API Tokens page)
The SDK will automatically load this.
License
This project is licensed under the Apache License 2.0.
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 hivetrace-1.2.6.tar.gz.
File metadata
- Download URL: hivetrace-1.2.6.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a38eb6a3cce53509a618438d6f4014b09c5b95febbc5c80526e7d0304072e35
|
|
| MD5 |
521e29582b34edb20f4f9aab3f8365d9
|
|
| BLAKE2b-256 |
5b950a1098d1ae890328d78295e648c5cdae04e415125592ecdc1803a51c32d0
|
File details
Details for the file hivetrace-1.2.6-py3-none-any.whl.
File metadata
- Download URL: hivetrace-1.2.6-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.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9ffcfb628b791a3f9e4f175212514acbfc6295e64bcd59038ecf421bde0c94f
|
|
| MD5 |
323dadae7a0a49fb4d0bc70a51621e9d
|
|
| BLAKE2b-256 |
fa25ffa8712e0131e6267ec77becfd0b831e759148ba146943de8f856cbb31b4
|