topai python sdk
Project description
topaisdk
setup
pip install .
Features
This SDK provides the following features for Ray Serve services:
- Latency Metrics Collection: Collects and reports request latency, request rate, and error rate.
- Consecutive Failure Health Check: Provides a decorator to add consecutive failure tracking and health check for model service methods.
Usage
Latency Metrics Collection
To collect latency metrics, you need to use the setup_metrics_to_serve function and the LatencyMiddleware.
First, import the necessary components:
from topaisdk.metrics import setup_metrics_to_serve, LatencyMiddleware
from ray import serve
from fastapi import FastAPI
Then, in your Ray Serve application setup, call setup_metrics_to_serve and add LatencyMiddleware to your FastAPI app:
app = FastAPI()
serve.init()
# Configure metrics
metrics_config = {
"service_id": "your-service-name", # Replace with your service ID
"metrics_server_url": "http://your-metrics-server:port/metrics", # Replace with your metrics server URL
"metrics_report_interval": 10 # Reporting interval in seconds
}
setup_metrics_to_serve(serve, app, metrics_config)
# Add latency middleware
app.add_middleware(LatencyMiddleware, metrics_collector=serve.metrics_collector)
# Define your Ray Serve deployment
@serve.deployment()
@serve.ingress(app)
class MyModel:
# Your model serving logic here
pass
# Deploy your model
MyModel.deploy()
Ensure you have a metrics server running at the specified metrics_server_url to receive the reported metrics.
Consecutive Failure Health Check
To use the consecutive failure health check, import the ModelService and use the consecutive_failure decorator on your model service methods.
from topaisdk.modelservice import ModelService
from ray import serve
@serve.deployment()
class MyModelService(ModelService): # Inherit from ModelService
def __init__(self):
super().__init()
# Your initialization
@ModelService.consecutive_failure(max_failures_num=5) # Apply the decorator
async def predict(self, input_data):
# Your prediction logic
# If this method raises exceptions consecutively for 5 times,
# the service health check will fail.
pass
# Ray Serve health check method
async def check_health(self):
self.check_health() # This will raise an error if the service is unhealthy
# Deploy your service
MyModelService.deploy()
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
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 topaisdk-0.1.5.tar.gz.
File metadata
- Download URL: topaisdk-0.1.5.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8924b04248745ee8109ded3b6562e797ece52a14a644f7657961b459d02bda3f
|
|
| MD5 |
b929599f9fbf1266957e5e1dff286d51
|
|
| BLAKE2b-256 |
dd06c52a45209b05512a86165a431ebe4e5a219daa8545df112dbaac46d7d67e
|
File details
Details for the file topaisdk-0.1.5-py3-none-any.whl.
File metadata
- Download URL: topaisdk-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eda9767dc844ccde31b6dc25c4a83d3cb22f6d7c6629d006664bb6ab132949f5
|
|
| MD5 |
428a7ec4b3e3442e723c9c15d8438587
|
|
| BLAKE2b-256 |
cf739b9f86d58e4b25c055d8ed7a33e3dcd8bdd1bf2705bdf3cbad5ea35cf96c
|