| | from json_repair import repair_json |
| | import json |
| |
|
| | class PostProcessor: |
| |
|
| | def process(self, response: str) -> dict: |
| | json_response = {} |
| | try: |
| | |
| | json_string = response |
| | if "```json" in response: |
| | json_string = response.split("```json")[1].split("```")[0] |
| | elif "{" in response and "}" in response: |
| | |
| | start_index = response.find("{") |
| | end_index = response.rfind("}") + 1 |
| | json_string = response[start_index:end_index] |
| |
|
| | json_response = json.loads(repair_json(json_string)) |
| | except Exception as e: |
| | print(f"Error parsing JSON: {e}") |
| | print(f"Generated text: {response}") |
| | json_response = {} |
| |
|
| | |
| | return json_response |
| |
|
| |
|