(response_text: str, keys_fix_yaml: List[str] = [])
| 131 | |
| 132 | |
| 133 | def try_fix_yaml(response_text: str, keys_fix_yaml: List[str] = []) -> dict: |
| 134 | response_text_lines = response_text.split('\n') |
| 135 | |
| 136 | keys = keys_fix_yaml |
| 137 | response_text_lines_copy = response_text_lines.copy() |
| 138 | for i in range(0, len(response_text_lines_copy)): |
| 139 | for key in keys: |
| 140 | if response_text_lines_copy[i].strip().startswith(key) and not '|' in response_text_lines_copy[i]: |
| 141 | response_text_lines_copy[i] = response_text_lines_copy[i].replace(f'{key}', |
| 142 | f'{key} |-\n ') |
| 143 | try: |
| 144 | data = yaml.safe_load('\n'.join(response_text_lines_copy)) |
| 145 | get_logger().info(f"Successfully parsed AI prediction after adding |-\n") |
| 146 | return data |
| 147 | except: |
| 148 | raise "yaml parsing error" |
no test coverage detected