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

Function gpt_python_postprocess

tools/collect_code_preds.py:46–70  ·  view source on GitHub ↗

Better answer postprocessor for better instruction-aligned models like GPT.

(ori_prompt: str, text: str)

Source from the content-addressed store, hash-verified

44
45
46def gpt_python_postprocess(ori_prompt: str, text: str) -> str:
47 """Better answer postprocessor for better instruction-aligned models like
48 GPT."""
49 if '```' in text:
50 blocks = re.findall(r'```(.*?)```', text, re.DOTALL)
51 if len(blocks) == 0:
52 text = text.split('```')[1] # fall back to default strategy
53 else:
54 text = blocks[0] # fetch the first code block
55 if not text.startswith('\n'): # in case starting with ```python
56 text = text[max(text.find('\n') + 1, 0):]
57
58 match_ori = re.search(r'def(.*?)\(', ori_prompt)
59 match = re.search(r'def(.*?)\(', text)
60 if match:
61 if match.group() == match_ori.group():
62 text = re.sub('def(.*?)\n', '', text, count=1)
63
64 for c_index, c in enumerate(text[:5]):
65 if c != ' ':
66 text = ' ' * (4 - c_index) + text
67 break
68
69 text = text.split('\n\n\n')[0]
70 return text
71
72
73def wizardcoder_postprocess(text: str) -> str:

Callers 1

mainFunction · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected