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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for inference_activity_requests-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5815fc4eed3f5875571422ca5a82c3a631cbc270f39dfc35b33d4a94f443cfb0
MD5 74c6f916cd20b92adcfd52d12b90c04f
BLAKE2b-256 bd7f46d0b9756c3529adcc8b16fd5ae91741b15a94719db6a18954bd946c1fe5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for inference_activity_requests-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa64b593776a4ecb05def2cf3ec86a0a5bd8a4cbf44fc83a7866579b28feffa8
MD5 3798b901135209b0a1341565e2a93952
BLAKE2b-256 c718622ad18489e76c57b3c2b99b986386973192fa6bf74b5866ca205c233735

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