huangjunxin commited on
Commit
c22ee41
·
1 Parent(s): 1206cdb

Fixed function extract_json_from_response

Browse files
Files changed (1) hide show
  1. utils/utils/other_utils.py +3 -0
utils/utils/other_utils.py CHANGED
@@ -146,7 +146,10 @@ def get_language_code(language_name):
146
 
147
  # Extract the rationale and translation from the response (json)
148
  def extract_json_from_response(target_language, response):
 
149
  response = response.replace("```", "")
 
 
150
  response_data = json.loads(response)
151
  rationale = response_data["rationale"]
152
  translation = response_data[f"{target_language} translation (proofread)"]
 
146
 
147
  # Extract the rationale and translation from the response (json)
148
  def extract_json_from_response(target_language, response):
149
+ # Remove the "```" from the response
150
  response = response.replace("```", "")
151
+ # Remove the initial text before the json
152
+ response = re.sub(r".*\s*{", '{', response, count=1)
153
  response_data = json.loads(response)
154
  rationale = response_data["rationale"]
155
  translation = response_data[f"{target_language} translation (proofread)"]