Skip to main content

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 import HivetraceSDK

Initialize the SDK

hivetrace = HivetraceSDK()

Send a user prompt

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

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": {}
        }
    }
)

Send a function call

response = hivetrace.function_call(
    application_id="your-application-id",
    tool_call_id="your-tool-call-id", # get id from LLM tool_calls/function_calls
    func_name="your_funcion",
    func_args="{'param': value}",
    func_result="{'result': values}", # nullable
    addtional_parameters=...
)

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)

Sending Requests in Async Mode

When using async mode, ensure you call the SDK methods inside an async function:

import asyncio

async def main():
    hivetrace = HivetraceSDK(async_mode=True)
    response = await hivetrace.input(
        application_id="your-application-id",
        message="User prompt here"
    )
    print(response)
    await hivetrace.close()

asyncio.run(main())

Sending Requests in Sync Mode

If you prefer synchronous execution, you can call the SDK methods normally:

hivetrace = HivetraceSDK(async_mode=False)
response = hivetrace.input(
    application_id="your-application-id",
    message="User prompt here"
)
print(response)

Closing the Async Client

If you're using async mode, remember to close the session when done:

await hivetrace.close()

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 prompt
  • additional_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 response
  • additional_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
    }
}

function_call(application_id: str, tool_call_id: str, func_name: str, func_args: str, func_result: Optional[str], additional_parameters: dict = None) -> dict

Sends a function call to Hivetrace.

  • application_id - Application identifier (must be a valid UUID, created in the UI)
  • tool_call_id - Identifier of function call returned by LLM API
  • func_name - Name of function
  • func_args - Arguments for function execution returned by LLM API
  • func_result - Result of function execution (optional)
  • additional_parameters - Dictionary of additional parameters (optional)

Response Example:

{
    "status": "processed",
    "monitoring_result": "PASS"
}

Configuration

The SDK loads configuration from environment variables. The allowed domain (HIVETRACE_URL) and access 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

The SDK will automatically load this.

License

This project is licensed under the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hivetrace-1.1.9.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hivetrace-1.1.9-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file hivetrace-1.1.9.tar.gz.

File metadata

  • Download URL: hivetrace-1.1.9.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for hivetrace-1.1.9.tar.gz
Algorithm Hash digest
SHA256 6b8df199d1ea3bd50b7d482f5a84c4a6a4cb1e7971bfc6300a47f30582df7391
MD5 8a78861b83e53da95f35160230f5e048
BLAKE2b-256 e7d18c3407f5af2851fc09668a2b2d633aec0e808a23fa9bc7759ae2d4671a03

See more details on using hashes here.

File details

Details for the file hivetrace-1.1.9-py3-none-any.whl.

File metadata

  • Download URL: hivetrace-1.1.9-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for hivetrace-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 55a7ef5b6e7c33c69bb466beb6c099b800a3258592d7bb83c0d8e7148d546fa6
MD5 644a13b99d55dc4ae84f2f0aa76a3f7c
BLAKE2b-256 288e265f600db5dc7d29b06f49761192821dc0d6220177cf7b1877a77768725e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page