hsaest commited on
Commit
4b07d40
1 Parent(s): 2024176

Delete utils/parse_plan.py

Browse files
Files changed (1) hide show
  1. utils/parse_plan.py +0 -49
utils/parse_plan.py DELETED
@@ -1,49 +0,0 @@
1
- from tqdm import tqdm
2
- import json
3
- import os
4
-
5
- def load_line_json_data(filename):
6
- data = []
7
- with open(filename, 'r', encoding='utf-8') as f:
8
- for line in f.read().strip().split('\n'):
9
- unit = json.loads(line)
10
- data.append(unit)
11
- return data
12
-
13
-
14
- if __name__ == '__main__':
15
-
16
- model_name = ['gpt-3.5-turbo-1106','gpt-4-1106-preview2','greedy_search','mistral-7B-32K','gemini2','mixtral','gpt-3.5-turbo-11062'][-3]
17
- method = ['direct','cot','react','reflexion','tool-use'][-1]
18
- set_type = ['dev','test'][0]
19
- results = open(f'/home/xj/toolAugEnv/code/toolConstraint/data/api_request/{set_type}_{model_name}_{method}.txt','r').read().strip().split('\n')
20
- directory = f'/home/xj/toolAugEnv/code/toolConstraint/data/final_data/{set_type}'
21
- query_data_list = load_line_json_data(os.path.join(directory, 'query/query.jsonl'))
22
- idx_number_list = [i for i in range(1,len(query_data_list)+1)]
23
- for idx in tqdm(idx_number_list):
24
- generated_plan = json.load(open(f'/home/xj/toolAugEnv/code/toolConstraint/results/{set_type}/plan_{idx}.json'))
25
- # print(results[idx-1].split('```json')[1].split('```')[0])
26
- suffix = None
27
- if method == 'tool-use':
28
- suffix = ''
29
- else:
30
- suffix = '_collected'
31
- if generated_plan[-1][f'{model_name}_{method}{suffix}_info_results'] not in ["","Max Token Length Exceeded."] :
32
- result = results[idx-1].split('```json')[1].split('```')[0]
33
- # print(result)
34
- try:
35
- if method == 'tool-use':
36
- generated_plan[-1][f'{model_name}_{method}_results_parsed'] = eval(result)
37
- else:
38
- generated_plan[-1][f'{model_name}_{method}_with_human_info_results_parsed'] = eval(result)
39
- except:
40
- print(result)
41
- break
42
- else:
43
- if method == 'tool-use':
44
- generated_plan[-1][f'{model_name}_{method}_results_parsed'] = None
45
- else:
46
- generated_plan[-1][f'{model_name}_{method}_with_human_info_results_parsed'] = None
47
- # print(generated_plan[-1]['chatgpt_human_collected_info_results_parsed'])
48
- with open(f'/home/xj/toolAugEnv/code/toolConstraint/results/{set_type}/plan_{idx}.json','w') as f:
49
- json.dump(generated_plan,f)