Skip to content

Commit 32027a1

Browse files
committed
Merge branch 'main' of github.com:SmartAPI/smartAPI
2 parents 1844e95 + 07f6f0d commit 32027a1

File tree

6 files changed

+74
-27
lines changed

6 files changed

+74
-27
lines changed

src/controller/smartapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def edge_consolidation_build(cls):
204204
"subject": edge["_source"]["subject"],
205205
"object": edge["_source"]["object"],
206206
"predicate": edge["_source"]["predicate"],
207-
"api": [edge_api]
207+
"api": [edge_api],
208+
**{k: edge["_source"][k] for k in ["subject_prefix", "object_prefix"] if k in edge["_source"]}
208209
}
209210

210211
processed_edges += 1

src/handlers/api.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,22 @@ async def get(self, *args, **kwargs):
464464
def get_filtered_api(self, api_dict):
465465
"""Extract and return filtered API information."""
466466
api_info = api_dict
467-
468467
if not self.args.bte and not self.args.api_details: # no bte and no api details
469468
filtered_api= {
470-
'name': api_info.get('name', 'Default Name'),
471-
'smartapi': {
472-
'id': api_info.get('smartapi', {}).get('id', 'Default ID')
473-
}
469+
**({"name": api_info["name"]} if "name" in api_info else {}),
470+
**({"smartapi": {"id": api_info["smartapi"]["id"]}} if "smartapi" in api_info and "id" in api_info["smartapi"] else {})
474471
}
475472
elif self.args.bte and not self.args.api_details : # bte and no api details
476473
filtered_api= {
477-
'name': api_info.get('name', 'Default Name'),
478-
'smartapi': {
479-
'id': api_info.get('smartapi', {}).get('id', 'Default ID')
480-
},
474+
**({"name": api_info["name"]} if "name" in api_info else {}),
475+
**({"smartapi": {"id": api_info["smartapi"]["id"]}} if "smartapi" in api_info and "id" in api_info["smartapi"] else {}),
481476
'bte': api_info.get('bte', {})
482477
}
483478
elif not self.args.bte and self.args.api_details: # no bte and api details
484479
api_info.pop('bte', None)
485-
filtered_api= api_info
480+
filtered_api = api_info
481+
else:
482+
filtered_api = api_info
486483
return filtered_api
487484

488485
def process_apis(self, apis):

src/model/metakg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"mapping": {"type": "object", "enabled": False},
3737
}
3838
},
39+
{
40+
"ignore_testExamples_field": {
41+
"path_match": "*bte.query_operation.testExamples",
42+
"mapping": {"type": "object", "enabled": False},
43+
}
44+
},
3945
{
4046
"ignore_response_mapping_field": {
4147
"path_match": "*bte.response_mapping",

src/utils/metakg/endpoint.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def construct_query_operation(self, data):
3434
query_operation.server = server
3535
query_operation.path = self.path
3636
query_operation.tags = self.api_meta_data["tags"]
37+
38+
if "agent_type" in op:
39+
query_operation.agent_type = op["agent_type"]
40+
if "knowledge_level" in op:
41+
query_operation.knowledge_level = op["knowledge_level"]
42+
if "testExamples" in op:
43+
query_operation.testExamples = op["testExamples"]
44+
if "useTemplating" in op:
45+
query_operation.useTemplating = op["useTemplating"]
46+
3747
return query_operation
3848

3949
def remove_bio_link_prefix(self, _input):
@@ -66,7 +76,6 @@ def construct_association(self, input, output, op):
6676
def construct_response_mapping(self, op):
6777
if "responseMapping" in op:
6878
op["response_mapping"] = op["responseMapping"]
69-
7079
return {f"{op['predicate']}": self.resolve_ref_if_provided(op.get("response_mapping"))}
7180

7281
def parse_individual_operation(self, op, method, path_params):
@@ -81,18 +90,11 @@ def parse_individual_operation(self, op, method, path_params):
8190
"association": association,
8291
"response_mapping": response_mapping,
8392
"tags": query_operation.tags,
93+
"agent_type": query_operation.agent_type,
94+
"knowledge_level": query_operation.knowledge_level,
95+
"testExamples": query_operation.testExamples,
96+
"useTemplating": query_operation.useTemplating,
8497
}
85-
86-
# Add additional fields to update_info if they exist in the operation
87-
if "agent_type" in op:
88-
update_info["agent_type"] = op["agent_type"]
89-
if "knowledge_level" in op:
90-
update_info["knowledge_level"] = op["knowledge_level"]
91-
if "testExamples" in op:
92-
update_info["testExamples"] = op["testExamples"]
93-
if "useTemplating" in op:
94-
update_info["useTemplating"] = op["useTemplating"]
95-
9698
res.append(update_info)
9799
return res
98100

src/utils/metakg/parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,14 @@ def get_ops_from_metakg_endpoint(self, metadata, extra_log_msg=""):
141141

142142
def extract_metakgedges(self, ops, extra_data=None):
143143
extra_data = extra_data or {}
144-
145144
metakg_edges = []
146145
for op in ops:
147146
smartapi_data = op["association"]["smartapi"]
148147
url = (smartapi_data.get("meta") or {}).get("url") or extra_data.get("url")
149148
_id = smartapi_data.get("id") or extra_data.get("id")
150-
151149
edge = {
152150
"subject": op["association"]["input_type"],
153151
"object": op["association"]["output_type"],
154-
"subject_prefix": op["association"]["input_id"],
155-
"object_prefix": op["association"]["output_id"],
156152
"predicate": op["association"]["predicate"],
157153
"api": {
158154
"name": op["association"]["api_name"],
@@ -169,6 +165,11 @@ def extract_metakgedges(self, ops, extra_data=None):
169165
# "username": (smartapi_data.get("meta") or {}).get("username"),
170166
},
171167
}
168+
# Conditionally add subject_prefix and object_prefix if they exist
169+
if "input_id" in op["association"]:
170+
edge["subject_prefix"] = op["association"]["input_id"]
171+
if "output_id" in op["association"]:
172+
edge["object_prefix"] = op["association"]["output_id"]
172173
# include bte-specific edge metadata
173174
bte = {}
174175
for attr in ["query_operation", "response_mapping"]:

src/utils/metakg/query_operation.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class QueryOperationObject:
88
_server = ""
99
_tags = []
1010
_path_params = []
11+
_agent_type = None
12+
_knowledge_level = None
13+
_testExamples = []
14+
_useTemplating = None
1115

1216
@property
1317
def xBTEKGSOperation(self):
@@ -26,6 +30,38 @@ def xBTEKGSOperation(self, new_op):
2630
self._support_batch = new_op.get("supportBatch")
2731
self._input_separator = new_op.get("inputSeparator")
2832

33+
@property
34+
def agent_type(self):
35+
return self._agent_type
36+
37+
@agent_type.setter
38+
def agent_type(self, new_agent_type):
39+
self._agent_type = new_agent_type
40+
41+
@property
42+
def knowledge_level(self):
43+
return self._knowledge_level
44+
45+
@knowledge_level.setter
46+
def knowledge_level(self, new_knowledge_level):
47+
self._knowledge_level = new_knowledge_level
48+
49+
@property
50+
def testExamples(self):
51+
return self._testExamples
52+
53+
@testExamples.setter
54+
def testExamples(self, new_testExamples):
55+
self._testExamples = new_testExamples
56+
57+
@property
58+
def useTemplating(self):
59+
return self._useTemplating
60+
61+
@useTemplating.setter
62+
def useTemplating(self, new_useTemplating):
63+
self._useTemplating = new_useTemplating
64+
2965
@property
3066
def params(self):
3167
return self._params
@@ -94,6 +130,10 @@ def to_dict(self):
94130
"tags",
95131
"support_batch",
96132
"input_separator",
133+
"agent_type",
134+
"knowledge_level",
135+
"testExamples",
136+
"useTemplating",
97137
]:
98138
val = getattr(self, attr, None)
99139
if val:

0 commit comments

Comments
 (0)