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.1.tar.gz (3.8 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.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for inference_activity_requests-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4391e2a0df24fc57618a4d1292f9ca6793af8bc26a1f84e4edbb68929c95bb1a
MD5 db7286e6099cdadca38ebb0107f49807
BLAKE2b-256 963b2413074b0d85ff8ed331c670a692695067158b4091e42d0f2fb0833738f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for inference_activity_requests-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7209b5178c7ff010b95f2e7054fc9d895b35993e9e662689578e625cdf0abd07
MD5 59f1a0e3d6f038d6ea3ef3a9d20a86d6
BLAKE2b-256 03cccfa2b8636fed8b5cf64516b372255cf69f6fcbdd7117449bd9f6d95aa04d

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