Skip to content

Commit

Permalink
update storage/retrieval for config edits to support HMI server
Browse files Browse the repository at this point in the history
  • Loading branch information
brandomr committed Jan 24, 2024
1 parent ab05fd5 commit 26abea3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
OPENAI_API_KEY={OPENAI_API_KEY}
DATA_SERVICE_URL=http://localhost:8001
HMI_SERVER_URL=http://localhost:3000
HMI_SERVER_USER=user
HMI_SERVER_PASSWORD=pass
JUPYTER_SERVER=http://localhost:8888
JUPYTER_TOKEN=ebcec7fcf42f28baccfab1cbc07bfb3f
ENABLE_USER_PROMPT=true
11 changes: 8 additions & 3 deletions src/askem_beaker/contexts/mira_config_edit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING, Any, Dict, Optional

import requests
from requests.auth import HTTPBasicAuth

from beaker_kernel.lib.context import BaseContext
from beaker_kernel.lib.utils import intercept
Expand Down Expand Up @@ -51,9 +52,12 @@ async def setup(self, config, parent_header):

async def set_model_config(self, item_id, agent=None, parent_header={}):
self.config_id = item_id
meta_url = f"{os.environ['DATA_SERVICE_URL']}/model_configurations/{self.config_id}"
meta_url = f"{os.environ['HMI_SERVER_URL']}/model-configurations/{self.config_id}"
logger.error(f"Meta url: {meta_url}")
self.configuration = requests.get(meta_url).json()
self.configuration = requests.get(meta_url,
auth=(os.environ['HMI_SERVER_USER'],
os.environ['HMI_SERVER_PASSWORD'])
).json()
logger.error(f"Succeeded in fetching model configuration, proceeding.")
self.amr = self.configuration.get("configuration")
self.original_amr = copy.deepcopy(self.amr)
Expand Down Expand Up @@ -106,7 +110,8 @@ async def save_model_config_request(self, message):
model_config["configuration"] = new_model

create_req = requests.put(
f"{os.environ['DATA_SERVICE_URL']}/model_configurations/{self.config_id}", json=model_config
f"{os.environ['HMI_SERVER_URL']}/model-configurations/{self.config_id}", json=model_config,
auth =(os.environ['HMI_SERVER_USER'], os.environ['HMI_SERVER_PASSWORD'])
)

if create_req.status_code == 200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ def get_params(model_config):
params = ""
for kk, vv in model_config.parameters.items():
if vv.display_name:
display_name = f"({vv.display_name})"
display_name = f" ({vv.display_name})"
else:
display_name = ""
if vv.units:
units = f"({vv.units})"
units = f" ({vv.units})"
else:
units = ""
params += f"{kk} {vv.display_name}: {vv.value} {units}\n"
params += f"{kk}{display_name}: {vv.value}{units}\n"
return params

print(get_params({{ var_name|default("model_config") }}))

0 comments on commit 26abea3

Please sign in to comment.