-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp.py
48 lines (37 loc) · 1.51 KB
/
sp.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
from gpt_inf import sp_inference
import json
from tqdm import tqdm
import time
from prompt import sp1, sp2, sim, sl, reas, inte
def main():
name='java_cn'
total_inference_time = 0.0
with open(f"data/{name}.json", "r") as file:
data = json.load(file)
code_explanation_expert = {
"role": "system",
"content": "You are an expert in code clone detection"
}
for i in tqdm(range(len(data)), desc="data processing"):
inference_start_time = time.time()
success = False
while not success:
try:
codeA = data[i]['codeA']
codeB = data[i]['codeB']
data[i]['result'] = sp_inference(query=sp2, codeA=codeA, codeB=codeB, context=code_explanation_expert)
with open(f"tmp/tp_taghere_java_cn.json", 'w') as tp_file:
json.dump(data, tp_file, indent=4)
success = True
inference_time = time.time() - inference_start_time
total_inference_time += inference_time
except Exception as e:
time.sleep(30)
print(f"Error processing index {i}: {e}")
with open(f'error/e{i}.json', 'w') as err:
json.dump(data, err, indent=4)
with open(f'results/sp2_{name}.json', 'w') as fichier_sortie:
json.dump(data, fichier_sortie, indent=4)
print(f"Average Inference Time: {total_inference_time} seconds")
if __name__ == "__main__":
main()