Convert response string to JSON, with error handling and fallback to non-standard JSON extraction.
(response: str)
| 100 | |
| 101 | |
| 102 | def convert_response_to_json(response: str) -> dict: |
| 103 | """Convert response string to JSON, with error handling and fallback to non-standard JSON extraction.""" |
| 104 | prediction_json = extract_first_complete_json(response) |
| 105 | |
| 106 | if prediction_json is None: |
| 107 | logger.info("Attempting to extract values from a non-standard JSON string...") |
| 108 | prediction_json = extract_values_from_json(response, allow_no_quotes=True) |
| 109 | |
| 110 | if not prediction_json: |
| 111 | logger.error("Unable to extract meaningful data from the response.") |
| 112 | else: |
| 113 | logger.info("JSON data successfully extracted.") |
| 114 | |
| 115 | return prediction_json |
| 116 | |
| 117 | |
| 118 |
nothing calls this directly
no test coverage detected