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 sentINFERENCE_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
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 inference_activity_requests-1.0.1.tar.gz.
File metadata
- Download URL: inference_activity_requests-1.0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4391e2a0df24fc57618a4d1292f9ca6793af8bc26a1f84e4edbb68929c95bb1a
|
|
| MD5 |
db7286e6099cdadca38ebb0107f49807
|
|
| BLAKE2b-256 |
963b2413074b0d85ff8ed331c670a692695067158b4091e42d0f2fb0833738f0
|
File details
Details for the file inference_activity_requests-1.0.1-py3-none-any.whl.
File metadata
- Download URL: inference_activity_requests-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7209b5178c7ff010b95f2e7054fc9d895b35993e9e662689578e625cdf0abd07
|
|
| MD5 |
59f1a0e3d6f038d6ea3ef3a9d20a86d6
|
|
| BLAKE2b-256 |
03cccfa2b8636fed8b5cf64516b372255cf69f6fcbdd7117449bd9f6d95aa04d
|