|
10 | 10 | from fastapi import FastAPI, HTTPException, Request, Response, status |
11 | 11 | from fastapi.logger import logger |
12 | 12 | from fastapi.params import Depends |
13 | | -from google.protobuf.json_format import MessageToDict, Parse |
| 13 | +from google.protobuf.json_format import MessageToDict |
14 | 14 | from pydantic import BaseModel |
15 | 15 |
|
16 | 16 | import feast |
17 | 17 | from feast import proto_json, utils |
18 | 18 | from feast.constants import DEFAULT_FEATURE_SERVER_REGISTRY_TTL |
19 | 19 | from feast.data_source import PushMode |
20 | 20 | from feast.errors import PushSourceNotFoundException |
21 | | -from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesRequest |
22 | 21 |
|
23 | 22 |
|
24 | 23 | # TODO: deprecate this in favor of push features |
@@ -83,34 +82,25 @@ def shutdown_event(): |
83 | 82 | @app.post("/get-online-features") |
84 | 83 | def get_online_features(body=Depends(get_body)): |
85 | 84 | try: |
86 | | - # Validate and parse the request data into GetOnlineFeaturesRequest Protobuf object |
87 | | - request_proto = GetOnlineFeaturesRequest() |
88 | | - Parse(body, request_proto) |
89 | | - |
| 85 | + body = json.loads(body) |
90 | 86 | # Initialize parameters for FeatureStore.get_online_features(...) call |
91 | | - if request_proto.HasField("feature_service"): |
| 87 | + if "feature_service" in body: |
92 | 88 | features = store.get_feature_service( |
93 | | - request_proto.feature_service, allow_cache=True |
| 89 | + body["feature_service"], allow_cache=True |
94 | 90 | ) |
95 | 91 | else: |
96 | | - features = list(request_proto.features.val) |
97 | | - |
98 | | - full_feature_names = request_proto.full_feature_names |
| 92 | + features = body["features"] |
99 | 93 |
|
100 | | - batch_sizes = [len(v.val) for v in request_proto.entities.values()] |
101 | | - num_entities = batch_sizes[0] |
102 | | - if any(batch_size != num_entities for batch_size in batch_sizes): |
103 | | - raise HTTPException(status_code=500, detail="Uneven number of columns") |
| 94 | + full_feature_names = body.get("full_feature_names", False) |
104 | 95 |
|
105 | 96 | response_proto = store._get_online_features( |
106 | 97 | features=features, |
107 | | - entity_values=request_proto.entities, |
| 98 | + entity_values=body["entities"], |
108 | 99 | full_feature_names=full_feature_names, |
109 | | - native_entity_values=False, |
110 | 100 | ).proto |
111 | 101 |
|
112 | 102 | # Convert the Protobuf object to JSON and return it |
113 | | - return MessageToDict( # type: ignore |
| 103 | + return MessageToDict( |
114 | 104 | response_proto, preserving_proto_field_name=True, float_precision=18 |
115 | 105 | ) |
116 | 106 | except Exception as e: |
|
0 commit comments