After deploying a real time model, your Python client applications can use this module to get inferences from the model hosted as a real-time endpoint.
Installation
The Python inference clients is a more lightweight part of frogml-inference package which contains only the modules that are required for inference. To install, run:
pip install frog ml-inference
Inference Examples
The following example invokes the model test_model. The model accepts one feature vector which contains three fields and produces one output field named "score".
from frogml_inference import RealTimeClient
model_id = "test_model"
feature_vector = [
{
"feature_a": "feature_value",
"feature_b": 1,
"feature_c": 0.5
}]
client = RealTimeClient(model_id=model_id)
response = client.predict(feature_vector)Testing Inference for a Specific Variation
You can optionally specify a variation name when working with the RealtimeClient.
from frogml_inference import RealTimeClient
model_id = "test_model"
feature_vector = [
{
"feature_a": "feature_value",
"feature_b": 1,
"feature_c": 0.5
}]
client = RealTimeClient(model_id=model_id,
variation="variation_name")
response = client.predict(feature_vector)Running Inference for a Different FrogML Environment
When working in a multi environment account, you need to specify a environment name when sending an inference to a non-default account using the RealtimeClient.
from frogml_inference import RealTimeClient
from frogml_inference.configuration import Session
Session().set_environment("staging")
model_id = "test_model"
feature_vector = [
{
"feature_a": "feature_value",
"feature_b": 1,
"feature_c": 0.5
}]
client = RealTimeClient(model_id=model_id,
environment="staging")
response = client.predict(feature_vector)