-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpost_processing.py
37 lines (34 loc) · 1.23 KB
/
post_processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
class PostProcessor:
def __init__(self, prompt_type):
self.prompt_type = prompt_type
def core(self, response):
if "python" in self.prompt_type:
regex = r'output_list\.append\("([^"]+)"\)'
parsed_res = re.findall(regex, response)
if parsed_res:
return parsed_res
else:
pattern = r"output_list\s*=\s*\[\s*(.*?)\s*\]"
matches = re.search(pattern, response, re.DOTALL)
if matches:
output_content = matches.group(1)
return output_content
else:
return response
elif "C" in self.prompt_type:
regex = r'outputList\.push_back\("([^"]+)"\);'
parsed_res = re.findall(regex, response)
if parsed_res:
return parsed_res
else:
return response
elif "go" in self.prompt_type:
regex = r'outputList\s*=\s*append\(outputList,\s*"([^"]+)"\)'
parsed_res = re.findall(regex, response)
if parsed_res:
return parsed_res
else:
return response
else:
return response