Skip to content

Commit

Permalink
update to query op and mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkiBytes committed Oct 31, 2024
1 parent 2dfc3dd commit 2f82910
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/model/metakg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
"mapping": {"type": "object", "enabled": False},
}
},
{
"ignore_testExamples_field": {
"path_match": "*bte.query_operation.testExamples",
"mapping": {"type": "object", "enabled": False},
}
},
{
"ignore_response_mapping_field": {
"path_match": "*bte.response_mapping",
Expand Down
26 changes: 14 additions & 12 deletions src/utils/metakg/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def construct_query_operation(self, data):
query_operation.server = server
query_operation.path = self.path
query_operation.tags = self.api_meta_data["tags"]

if "agent_type" in op:
query_operation.agent_type = op["agent_type"]
if "knowledge_level" in op:
query_operation.knowledge_level = op["knowledge_level"]
if "testExamples" in op:
query_operation.testExamples = op["testExamples"]
if "useTemplating" in op:
query_operation.useTemplating = op["useTemplating"]

return query_operation

def remove_bio_link_prefix(self, _input):
Expand Down Expand Up @@ -66,7 +76,6 @@ def construct_association(self, input, output, op):
def construct_response_mapping(self, op):
if "responseMapping" in op:
op["response_mapping"] = op["responseMapping"]

return {f"{op['predicate']}": self.resolve_ref_if_provided(op.get("response_mapping"))}

def parse_individual_operation(self, op, method, path_params):
Expand All @@ -81,18 +90,11 @@ def parse_individual_operation(self, op, method, path_params):
"association": association,
"response_mapping": response_mapping,
"tags": query_operation.tags,
"agent_type": query_operation.agent_type,
"knowledge_level": query_operation.knowledge_level,
"testExamples": query_operation.testExamples,
"useTemplating": query_operation.useTemplating,
}

# Add additional fields to update_info if they exist in the operation
if "agent_type" in op:
update_info["agent_type"] = op["agent_type"]
if "knowledge_level" in op:
update_info["knowledge_level"] = op["knowledge_level"]
if "testExamples" in op:
update_info["testExamples"] = op["testExamples"]
if "useTemplating" in op:
update_info["useTemplating"] = op["useTemplating"]

res.append(update_info)
return res

Expand Down
6 changes: 3 additions & 3 deletions src/utils/metakg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def get_ops_from_metakg_endpoint(self, metadata, extra_log_msg=""):

def extract_metakgedges(self, ops, extra_data=None):
extra_data = extra_data or {}

metakg_edges = []
for op in ops:
smartapi_data = op["association"]["smartapi"]
Expand All @@ -151,8 +150,9 @@ def extract_metakgedges(self, ops, extra_data=None):
edge = {
"subject": op["association"]["input_type"],
"object": op["association"]["output_type"],
"subject_prefix": op["association"]["input_id"],
"object_prefix": op["association"]["output_id"],
# check if required, apply logic accordingly
# "subject_prefix": op["association"]["input_id"],
# "object_prefix": op["association"]["output_id"],
"predicate": op["association"]["predicate"],
"api": {
"name": op["association"]["api_name"],
Expand Down
40 changes: 40 additions & 0 deletions src/utils/metakg/query_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class QueryOperationObject:
_server = ""
_tags = []
_path_params = []
_agent_type = None
_knowledge_level = None
_testExamples = []
_useTemplating = None

@property
def xBTEKGSOperation(self):
Expand All @@ -26,6 +30,38 @@ def xBTEKGSOperation(self, new_op):
self._support_batch = new_op.get("supportBatch")
self._input_separator = new_op.get("inputSeparator")

@property
def agent_type(self):
return self._agent_type

@agent_type.setter
def agent_type(self, new_agent_type):
self._agent_type = new_agent_type

@property
def knowledge_level(self):
return self._knowledge_level

@knowledge_level.setter
def knowledge_level(self, new_knowledge_level):
self._knowledge_level = new_knowledge_level

@property
def testExamples(self):
return self._testExamples

@testExamples.setter
def testExamples(self, new_testExamples):
self._testExamples = new_testExamples

@property
def useTemplating(self):
return self._useTemplating

@useTemplating.setter
def useTemplating(self, new_useTemplating):
self._useTemplating = new_useTemplating

@property
def params(self):
return self._params
Expand Down Expand Up @@ -94,6 +130,10 @@ def to_dict(self):
"tags",
"support_batch",
"input_separator",
"agent_type",
"knowledge_level",
"testExamples",
"useTemplating",
]:
val = getattr(self, attr, None)
if val:
Expand Down

0 comments on commit 2f82910

Please sign in to comment.