MCPcopy Create free account
hub / github.com/InternScience/SciReason / _process_answer

Method _process_answer

opencompass/datasets/LCBench.py:144–178  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

142 return result
143
144 def _process_answer(self, text):
145 try:
146 # for chatGLM related text
147 eval_text = eval(text)
148 except Exception:
149 pass
150 else:
151 if isinstance(eval_text, str):
152 text = eval_text
153 # deal with code block
154 if '```' in text:
155 blocks = re.findall(r'```(.*?)```', text, re.DOTALL)
156 if len(blocks) == 0:
157 text = text.split('```')[1] # fall back to default strategy
158 else:
159 text = blocks[0] # fetch the first code block
160 if not text.startswith('\n'): # in case starting with ```xxx
161 text = text[max(text.find('\n') + 1, 0):]
162 text = text.strip()
163 match = re.search(r"('\s*|)(\[DONE\]|DONE)", text)
164 if match:
165 text = text[:match.start()]
166 match = re.search(r"(\[BEGIN\]|BEGIN)('\s*|)", text)
167 if match:
168 text = text[match.end():]
169 text = text.strip()
170 if text.startswith("'"):
171 text = text[1:]
172 if text.endswith("'"):
173 text = text[:-1]
174 text = text.replace('\\', '')
175 match = re.search(r'```python(.*)```', text, re.DOTALL)
176 if match:
177 text = match.group(1).strip().split('```')[0].strip()
178 return text
179
180 def _process_test(self, test_case, pred):
181 formatted = pred + '\n'

Callers 2

scoreMethod · 0.95
scoreMethod · 0.45

Calls 2

replaceMethod · 0.80
groupMethod · 0.80

Tested by

no test coverage detected