From 26abea3a6bd99ef2de27dc9016039ce949e1710c Mon Sep 17 00:00:00 2001 From: Brandon Rose Date: Wed, 24 Jan 2024 16:22:05 -0600 Subject: [PATCH] update storage/retrieval for config edits to support HMI server --- env.example | 3 +++ src/askem_beaker/contexts/mira_config_edit/context.py | 11 ++++++++--- .../mira_config_edit/procedures/python3/get_params.py | 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/env.example b/env.example index 92072c6..49119fc 100644 --- a/env.example +++ b/env.example @@ -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 diff --git a/src/askem_beaker/contexts/mira_config_edit/context.py b/src/askem_beaker/contexts/mira_config_edit/context.py index fd3f695..aaa5113 100644 --- a/src/askem_beaker/contexts/mira_config_edit/context.py +++ b/src/askem_beaker/contexts/mira_config_edit/context.py @@ -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 @@ -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) @@ -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: diff --git a/src/askem_beaker/contexts/mira_config_edit/procedures/python3/get_params.py b/src/askem_beaker/contexts/mira_config_edit/procedures/python3/get_params.py index c0afd14..1beff78 100644 --- a/src/askem_beaker/contexts/mira_config_edit/procedures/python3/get_params.py +++ b/src/askem_beaker/contexts/mira_config_edit/procedures/python3/get_params.py @@ -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") }})) \ No newline at end of file