INNER CODE UNIT · Python
predict
GoogleCloudPlatform/vertex-ai-samples · community-content/tf_agents_bandits_movie_recommendation_with_kfp_and_vertex_sdk/step_by_step_sdk_tf_agents_bandits_movie_recommendation/src/prediction/main.py:40
async def predict(request: Request):
"""Handles prediction requests.
Unpacks observations in prediction requests and queries the trained policy for
predicted actions.
Args:
request: Incoming prediction requests that contain observations.
Returns:
A dict with the key `predictions` mapping to a list of predicted actions
corresponding to each observation in the prediction request.
"""
body = await request.json()
instances = body["instances"]
predictions = []
for index, instance in enumerate(instances):