fallback to try_fix_yaml

This commit is contained in:
tmokmss
2023-11-29 17:57:54 +09:00
parent f8f57419c4
commit 5e642c10fa

View File

@ -290,7 +290,6 @@ def _fix_key_value(key: str, value: str):
def load_yaml(response_text: str) -> dict:
response_text = response_text.removeprefix('```yaml').rstrip('`')
response_text = response_text.strip().rstrip().removeprefix('{').removesuffix('}')
try:
data = yaml.safe_load(response_text)
except Exception as e:
@ -326,7 +325,15 @@ def try_fix_yaml(response_text: str) -> dict:
break
except:
pass
return data
# thrid fallback - try to remove leading and trailing curly brackets
response_text_copy = response_text.strip().rstrip().removeprefix('{').removesuffix('}')
try:
data = yaml.safe_load(response_text_copy,)
get_logger().info(f"Successfully parsed AI prediction after removing curly brackets")
return data
except:
pass
def set_custom_labels(variables):