Skip to content

Commit 550f50c

Browse files
committed
wrap lookup endpoint
1 parent 62798f0 commit 550f50c

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

dataikuapi/apinode_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,44 @@ def apply_on_record(self, endpoint_id, features):
7474
:param str endpoint_id: Identifier of the endpoint to query
7575
:param features: Python dictionary of features of the record
7676
77-
:return: a Python dict of the API answer. The answer contains a "result" key (itself a dict)
77+
:return: a Python dict of the API answer. The answer is the result
7878
"""
7979
return self._perform_json("POST", "%s/run" % endpoint_id, body = features)
8080

81+
def lookup_record(self, endpoint_id, record, context=None):
82+
"""
83+
Lookup a single record on a DSS API node endpoint
84+
85+
:param str endpoint_id: Identifier of the endpoint to query
86+
:param record: Python dictionary of features of the record
87+
:param context: Optional, Python dictionary of additional context information. The context information is logged, but not directly used.
88+
89+
:return: a Python dict of the API answer. The answer contains a "data" key (itself a dict)
90+
"""
91+
obj = {
92+
"data" :record
93+
}
94+
if context is not None:
95+
obj["context"] = context
96+
97+
return self._perform_json("POST", "%s/lookup" % endpoint_id, body = obj).get("results", [])[0]
98+
99+
def lookup_records(self, endpoint_id, records, context=None):
100+
"""
101+
Lookup a single record on a DSS API node endpoint
102+
103+
:param str endpoint_id: Identifier of the endpoint to query
104+
:param records: Python list of records. Each record must be a Python dict. Each record must contain a "data" dict (see predict_record) and optionally a "context" dict.
105+
106+
:return: a Python dict of the API answer. The answer contains a "results" key (which is an array of result objects)
107+
"""
108+
for record in records:
109+
if not "data" in record:
110+
raise ValueError("Each record must contain a 'data' dict")
111+
112+
obj = {
113+
"items" : records
114+
}
115+
116+
return self._perform_json("POST", "%s/lookup-multi" % endpoint_id, body = obj)
117+

0 commit comments

Comments
 (0)