Skip to content

Commit

Permalink
Save decapode expr (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivegrant authored Oct 31, 2023
1 parent bec3f4e commit 82e56a0
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions contexts/toolsets/decapode_creation_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,15 @@ async def generate_code(
return result

async def send_decapodes_preview_message(
self, server=None, target_stream=None, data=None, parent_header={}
self, server=None, target_stream=None, data=None, parent_header=None
):
preview = await self.context.evaluate(self.get_code("expr_to_info"))
json_str = preview["return"]["application/json"]
image = preview["return"]["image/svg"]
content = {
"data": {
"application/json": json_str,
"image/svg": image,
}
}
if parent_header is None:
parent_header = {}
result = await self.context.evaluate(self.get_code("expr_to_info"))
content = result["return"]
if content is None:
raise RuntimeError("Info not returned for preview")

self.context.kernel.send_response(
"iopub", "decapodes_preview", content, parent_header=parent_header
)
Expand All @@ -175,4 +173,27 @@ async def compile_expr(self, server, target_stream, data):
await self.send_decapodes_preview_message(parent_header=message.header)

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

header = content["header"]
header["_type"] = "Header"

preview = await self.context.evaluate(self.get_code("expr_to_info"))
model = preview["return"]["application/json"]

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

create_req = requests.post(
f"{os.environ['DATA_SERVICE_URL']}/models", json=amr
)
new_model_id = create_req.json()["id"]

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

0 comments on commit 82e56a0

Please sign in to comment.