Skip to content

Commit

Permalink
set puid in case it is received in request
Browse files Browse the repository at this point in the history
  • Loading branch information
klalit committed Aug 7, 2019
1 parent 9138b99 commit 0e6cb5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/seldon_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ def construct_response(user_model: SeldonComponent, is_request: bool, client_req
metrics = client_custom_metrics(user_model)
if metrics:
meta_json["metrics"] = metrics
if client_request.meta:
if client_request.meta.puid:
meta_json["puid"] = client_request.meta.puid
json_format.ParseDict(meta_json, meta)
if isinstance(client_raw_response, np.ndarray) or isinstance(client_raw_response, list):
client_raw_response = np.array(client_raw_response)
Expand Down
15 changes: 15 additions & 0 deletions python/tests/test_model_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ def test_model_ok():
assert j["data"]["names"] == ["t:0", "t:1"]
assert j["data"]["ndarray"] == [[1.0, 2.0]]

def test_model_puid_ok():
user_object = UserObject()
app = get_rest_microservice(user_object)
client = app.test_client()
rv = client.get('/predict?json={"meta":{"puid":"123"},"data":{"names":["a","b"],"ndarray":[[1,2]]}}')
j = json.loads(rv.data)
print(j)
assert rv.status_code == 200
assert j["meta"]["tags"] == {"mytag": 1}
assert j["meta"]["metrics"][0]["key"] == user_object.metrics()[0]["key"]
assert j["meta"]["metrics"][0]["value"] == user_object.metrics()[0]["value"]
assert j["data"]["names"] == ["t:0", "t:1"]
assert j["data"]["ndarray"] == [[1.0, 2.0]]
assert j["meta"]["puid"] == '123'

def test_model_lowlevel_ok():
user_object = UserObjectLowLevel()
app = get_rest_microservice(user_object)
Expand Down

0 comments on commit 0e6cb5d

Please sign in to comment.