Skip to content

Commit

Permalink
Create AMR request (#16)
Browse files Browse the repository at this point in the history
* Create AMR request

* Update contexts/toolsets/decapode_creation_toolset.py

Co-authored-by: Matthew Printz <[email protected]>

---------

Co-authored-by: Matthew Printz <[email protected]>
  • Loading branch information
fivegrant and mattprintz authored Nov 2, 2023
1 parent 0124af9 commit d42e1b3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions contexts/toolsets/decapode_creation_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, context, *args, **kwargs):
super().__init__(context=context, *args, **kwargs)
self.intercepts = {
"save_amr_request": (self.save_amr_request, "shell"),
"construct_amr_request": (self.construct_amr, "shell"),
"compile_expr_request": (self.compile_expr, "shell"),
}
self.reset()
Expand Down Expand Up @@ -214,6 +215,37 @@ async def compile_expr(self, server, target_stream, data):
)
await self.send_decapodes_preview_message(parent_header=message.header)


async def construct_amr(self, server, target_stream, data):
message = JupyterMessage.parse(data)
content = message.content

header = {
"description": content.get("description", None),
"name": content.get("name", None),
"_type": "Header",
"model_version": "v1.0",
"schema": "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/decapodes-intertypes/decapodes/decapodes_schema.json",
"schema_name": "decapode"
}
id_value = content.get("id", None)
if id_value:
header['id'] = id_value

preview = await self.context.evaluate(self.get_code("expr_to_info", {"var_name": self.var_name}))
model = preview["return"]["application/json"]

amr = {
"header": header,
"model": model,
"_type": "ASKEMDecaExpr",
"annotations": [],
}

self.context.kernel.send_response(
"iopub", "save_model_response", amr, parent_header=message.header
)

async def save_amr_request(self, server, target_stream, data):
message = JupyterMessage.parse(data)
content = message.content
Expand Down

0 comments on commit d42e1b3

Please sign in to comment.