-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_output.py
40 lines (32 loc) · 1.2 KB
/
parse_output.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
"""
creatng a dict out of the response
very brittle for now, need to fix
"""
import re
import json
# def parsed_response_str(response):
# delims = ['CLUES:', '\nREASONING:', '\nCLASSIFICATION:']
# delims_clean = ['CLUES', 'REASONING', 'CLASSIFICATION']
# pattern = '|'.join(delims)
# result = re.split(pattern, response)
# result_list = list(filter(None, result)) # filter out the initial empty string
# # print(result_list)
# # print(delims)
# if len(result_list) != len(delims):
# print(len(result_list), len(delims))
# exit('something went wrong')
# else:
# split_dict = {}
# for delim, value in zip(delims_clean, result_list):
# split_dict[delim] = value
# return split_dict
def extract_classification(response):
response_array = response.split('\n')
return json.loads(response_array[2])['classification']
if __name__ == "__main__":
response = """
CLUES: Future focused: "coming up today"
REASONING: The response contains a future focused statement "coming up today" and is assertive, both are indicators of truthfulness
CLASSIFICATION: truthful"""
print(type(response))
print(parsed_response_str(response))