From 9e52ba88b0d3763cd8c935fdbd056192c9c64c8e Mon Sep 17 00:00:00 2001 From: David Gauldie Date: Mon, 21 Oct 2024 11:13:57 -0400 Subject: [PATCH] 5149 bug enrichment of model from document in create model from equations misses all parameters and variables of the form x i (#5213) --- packages/gollm/gollm_openai/tool_utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/gollm/gollm_openai/tool_utils.py b/packages/gollm/gollm_openai/tool_utils.py index 7d73b5e731..af7e53567f 100644 --- a/packages/gollm/gollm_openai/tool_utils.py +++ b/packages/gollm/gollm_openai/tool_utils.py @@ -38,6 +38,18 @@ def escape_curly_braces(text: str): return text.replace("{", "{{").replace("}", "}}") +def unescape_curly_braces(json_obj: dict) -> dict: + if isinstance(json_obj, dict): + for key, value in json_obj.items(): + json_obj[key] = unescape_curly_braces(value) + elif isinstance(json_obj, list): + for i in range(len(json_obj)): + json_obj[i] = unescape_curly_braces(json_obj[i]) + elif isinstance(json_obj, str): + json_obj = json_obj.replace('{{', '{').replace('}}', '}') + return json_obj + + def get_image_format_string(image_format: str) -> str: if not image_format: raise ValueError("Invalid image format.") @@ -286,7 +298,7 @@ def amr_enrichment_chain(amr: str, research_paper: str) -> dict: print("Received response from OpenAI API. Formatting response to work with HMI...") output_json = json.loads(output.choices[0].message.content) - return output_json + return unescape_curly_braces(output_json) def model_card_chain(amr: str, research_paper: str = None) -> dict: