kaikaidai commited on
Commit
44387c3
·
verified ·
1 Parent(s): 23f2441

Improve JSON parsing

Browse files
Files changed (1) hide show
  1. 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"Failed to parse response: {response}"
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