-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_output_parser.py
52 lines (44 loc) · 1.8 KB
/
model_output_parser.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def parse_output_codellama_34b_instruct(model_output: str):
case1 = "```python\n"
start_expected = "```\n"
# if the case1 is not found, it will return the original string
model_output = model_output.replace(case1, start_expected)
mid = "\n```"
result = ''.join(model_output.split(start_expected)[1].split(mid)[0])
while result.endswith("\n"):
result = result.removesuffix("\n")
# also found it sometimes output such symbol
# 7: The fix
result = result.split('# The', 1)[0]
return result
def parse_output_codellama_34b_python(model_output: str):
if model_output.startswith("def") or model_output.startswith("@"):
# based on observation found these 2 words
result = model_output.split('# The', 1)[0]
result = result.split('# Explanation', 1)[0]
return result
else:
return ""
def parse_output_codellama_70b_instruct(model_output: str):
case1 = "```python\n"
start_expected = "```\n"
# if the case1 is not found, it will return the original string
model_output = model_output.replace(case1, start_expected)
mid = "\n```"
result = ''.join(model_output.split(start_expected)[1].split(mid)[0])
while result.endswith("\n"):
result = result.removesuffix("\n")
# 59: The commit
result = result.split('# The', 1)[0]
return result
def parse_output_codellama_70b_python(model_output: str):
if model_output.startswith("def") or model_output.startswith("@"):
# based on observation found these 2 words
result = model_output.split('# The', 1)[0]
result = result.split('# Explanation', 1)[0]
result = result.split('# Please', 1)[0]
return result
else:
return ""
def parse_output_infill(model_output: str):
return model_output.splitlines()[0]