Postprocess for WizardCoder Models.
(text: str)
| 71 | |
| 72 | |
| 73 | def wizardcoder_postprocess(text: str) -> str: |
| 74 | """Postprocess for WizardCoder Models.""" |
| 75 | if '```' in text: |
| 76 | blocks = re.findall(r'```(.*?)```', text, re.DOTALL) |
| 77 | if len(blocks) == 0: |
| 78 | text = text.split('```')[1] # fall back to default strategy |
| 79 | else: |
| 80 | text = blocks[0] # fetch the first code block |
| 81 | if not text.startswith('\n'): # in case starting with ```python |
| 82 | text = text[max(text.find('\n') + 1, 0):] |
| 83 | else: |
| 84 | match = re.search(r'Here(.*?)\n', text) |
| 85 | if match: |
| 86 | text = re.sub('Here(.*?)\n', '', text, count=1) |
| 87 | |
| 88 | return text |
| 89 | |
| 90 | |
| 91 | def collect_preds(filename: str): |