featurebyte.Deployment.get_online_serving_code¶
get_online_serving_code(
language: Literal["python", "sh"]="python"
) -> strDescription¶
Retrieves either Python or shell script template for serving online features from a deployed featurelist, defaulted to python.
Parameters¶
- language: Literal["python", "sh"]
default: "python"
Language for which to get code template
Returns¶
- str
Raises¶
- FeatureListNotOnlineEnabledError
Feature list not deployed - NotImplementedError
Serving code not available - RecordRetrievalException
Failed to retrieve serving code
Examples¶
Retrieve python code template when "language" is set to "python"
>>> feature_list = catalog.get_feature_list("invoice_feature_list")
>>> deployment = feature_list.deploy()
>>> deployment.enable()
>>> deployment.get_online_serving_code(language="python")
from typing import Any, Dict
import pandas as pd
import requests
def request_features(entity_serving_names: Dict[str, Any]) -> pd.DataFrame:
"
Send POST request to online serving endpoint
Parameters
----------
entity_serving_names: Dict[str, Any]
Entity serving name values to used for serving request
Returns
-------
pd.DataFrame
"
response = requests.post(
url="http://localhost:8080/deployment/{deployment.id}/online_features",
headers={{"Content-Type": "application/json", "active-catalog-id": "{catalog.id}"}},
json={{"entity_serving_names": entity_serving_names}},
)
assert response.status_code == 200, response.json()
return pd.DataFrame.from_dict(response.json()["features"])
request_features([{{"cust_id": "sample_cust_id"}}])
>>> feature_list = catalog.get_feature_list("invoice_feature_list")
>>> deployment = feature_list.deploy()
>>> deployment.enable()
>>> deployment.get_online_serving_code(language="sh")
#!/bin/sh
curl -X POST
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer token' \
-H 'active-catalog-id: {catalog.id}' \
-d '{{"entity_serving_names": [{{"cust_id": "sample_cust_id"}}]}}' \
http://localhost:8080/deployment/{deployment.id}/online_features