Skip to main content

Requests hooks for tracking inference activities on Heroku AI

Project description

Inference Activity Requests

A Python package that provides request/response hooks for tracking inference activities on Heroku AI using the requests library. This package is the Python equivalent of inference-activity-axios.

Installation

pip install inference-activity-requests

Usage

First, set up your environment variables:

export INFERENCE_ACTIVITY_URL="your-activity-logging-endpoint"
export INFERENCE_ACTIVITY_KEY="your-api-key"

Then use the package in your code:

from inference_activity_requests import create_session

# Create a session with inference activity tracking
session = create_session()

# Use the session for your API calls
response = session.post(
    "https://api.heroku.ai/v1/chat/completions",
    json={
        "messages": [{"role": "user", "content": "Hello"}],
        "model": "gpt-3.5-turbo"
    }
)

Features

  • Automatically tracks inference activities for Heroku AI endpoints
  • Redacts sensitive information from requests and responses
  • Tracks response times and logs activity data
  • Handles the following endpoints:
    • /v1/chat/completions
    • /v1/embeddings
    • /v1/images/generations

Environment Variables

  • INFERENCE_ACTIVITY_URL: The endpoint where activity logs will be sent
  • INFERENCE_ACTIVITY_KEY: The API key for authentication when sending activity logs

Activity Data Format

The package sends the following data structure to your activity logging endpoint:

{
    "timestamp": 1234567890123,  # Unix timestamp in milliseconds
    "response_time": 500,        # Response time in milliseconds
    "status_code": 200,          # HTTP status code
    "status_message": "OK",      # HTTP status message
    "request": {
        "method": "POST",
        "url": "https://api.heroku.ai/v1/chat/completions",
        "params": None,
        "body": {
            "messages": "[REDACTED]",
            "model": "gpt-3.5-turbo"
        }
    },
    "response": {
        "headers": {
            "content-type": "application/json",
            ...
        },
        "data": {
            "choices": [{
                "message": {
                    "content": "[REDACTED]",
                    "role": "assistant"
                }
            }],
            ...
        }
    }
}

License

MIT

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

inference_activity_requests-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

inference_activity_requests-1.0.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file inference_activity_requests-1.0.2.tar.gz.

File metadata

File hashes

Hashes for inference_activity_requests-1.0.2.tar.gz
Algorithm Hash digest
SHA256 10e5029f0205e50e9d4fadf0fd9ca922f14fa26658c7adbfdc0a44f49f59acd9
MD5 05885eda3e9ebfe070657051fcacec4a
BLAKE2b-256 bc5bd2ef9092a7ccec51f71d3ad78be064e0579e80b12b040263f7c6b7d1be7f

See more details on using hashes here.

File details

Details for the file inference_activity_requests-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for inference_activity_requests-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f94f9629200af4d11b2f56ad14654f5b9c00ba58c2fb7782e57740580bc7661e
MD5 26366ecd13ab2a9cdfedec1f9ca64333
BLAKE2b-256 c629ccd08c167e400e31a802ebcdb13247bd8d31dcaf71c96fbd9e95709707ae

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