-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (34 loc) · 1.29 KB
/
utils.py
File metadata and controls
39 lines (34 loc) · 1.29 KB
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
import os
import json
def load_model_api_config(model_api_config, model_name):
with open(model_api_config, "r") as f:
model_api_config = json.load(f)
for model_name in model_api_config:
actural_max_workers = model_api_config[model_name]["max_workers_per_model"] * len(model_api_config[model_name]["model_list"])
model_api_config[model_name]["max_workers"] = actural_max_workers
return model_api_config
def write_to_jsonl(lock, file_name, data):
with lock:
with open(file_name, 'a') as f:
json.dump(data, f)
f.write('\n')
def read_valid_jsonl(file_name):
all_data = []
with open(file_name, "r") as f:
tmp = f.readlines()
for line in tmp:
try:
all_data.append(json.loads(line))
except Exception as e:
print(line)
print(f"{e}")
return all_data
def reserve_unprocessed_queries(output_path, test_dataset):
processed_queries = set()
if os.path.exists(output_path):
with open(output_path, "r") as f:
for line in f:
infered_sample = json.loads(line)
processed_queries.add(infered_sample["query"])
test_dataset = [sample for sample in test_dataset if sample["query"] not in processed_queries]
return test_dataset