Spaces:
Sleeping
Sleeping
Commit ·
60c4d25
1
Parent(s): 30532ee
feat: rename ntu img to ruby
Browse files
utils/completion_reward.py
CHANGED
|
@@ -558,11 +558,18 @@ class NTUAgent:
|
|
| 558 |
start_time = time.time()
|
| 559 |
response = requests.post(url, headers=headers, data=json.dumps(data)).json()
|
| 560 |
response_text = response["choices"][0]["message"]["content"]
|
|
|
|
| 561 |
|
| 562 |
-
|
|
|
|
| 563 |
|
|
|
|
| 564 |
self.ntu_response_time = time.time() - start_time
|
| 565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
|
| 567 |
except Exception as e:
|
| 568 |
retry_attempts += 1
|
|
|
|
| 558 |
start_time = time.time()
|
| 559 |
response = requests.post(url, headers=headers, data=json.dumps(data)).json()
|
| 560 |
response_text = response["choices"][0]["message"]["content"]
|
| 561 |
+
matched_contents = re.findall("```(.*?)```", response_text, re.DOTALL)
|
| 562 |
|
| 563 |
+
# Concatenate all extracted contents
|
| 564 |
+
extracted_content = "\n".join(matched_contents).strip()
|
| 565 |
|
| 566 |
+
chinese_converter = OpenCC("s2tw")
|
| 567 |
self.ntu_response_time = time.time() - start_time
|
| 568 |
+
logging.warning(f"NTU response time: {self.ntu_response_time}")
|
| 569 |
+
if extracted_content:
|
| 570 |
+
return chinese_converter.convert(extracted_content)
|
| 571 |
+
else:
|
| 572 |
+
return chinese_converter.convert(response_text)
|
| 573 |
|
| 574 |
except Exception as e:
|
| 575 |
retry_attempts += 1
|