Spaces:
Running
Running
Improve JSON parsing
Browse files- gen_api_answer.py +2 -2
gen_api_answer.py
CHANGED
@@ -120,12 +120,12 @@ def parse_model_response(response):
|
|
120 |
return str(data.get("result", "N/A")), data.get("feedback", "N/A")
|
121 |
except json.JSONDecodeError:
|
122 |
# If that fails (typically for smaller models), try to find JSON within the response
|
123 |
-
json_match = re.search(r"{.*}", response)
|
124 |
if json_match:
|
125 |
data = json.loads(json_match.group(0))
|
126 |
return str(data.get("result", "N/A")), data.get("feedback", "N/A")
|
127 |
else:
|
128 |
-
return "Error", f"
|
129 |
|
130 |
except Exception as e:
|
131 |
# Debug print for error case
|
|
|
120 |
return str(data.get("result", "N/A")), data.get("feedback", "N/A")
|
121 |
except json.JSONDecodeError:
|
122 |
# If that fails (typically for smaller models), try to find JSON within the response
|
123 |
+
json_match = re.search(r"{.*}", response, re.DOTALL)
|
124 |
if json_match:
|
125 |
data = json.loads(json_match.group(0))
|
126 |
return str(data.get("result", "N/A")), data.get("feedback", "N/A")
|
127 |
else:
|
128 |
+
return "Error", f"Invalid response format returned - here is the raw model response: {response}"
|
129 |
|
130 |
except Exception as e:
|
131 |
# Debug print for error case
|