-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCal_path_rate.py
62 lines (50 loc) · 1.72 KB
/
Cal_path_rate.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
53
54
55
56
57
58
59
60
61
62
import json
import re
def change_name(name):
change_list = ["from", "class", "return", "false", "true", "id", "and", "", "ID"]
if name in change_list:
name = "is_" + name.lower()
return name
def standardize(string):
res = re.compile("[^\\u4e00-\\u9fa5^a-z^A-Z^0-9^_]")
string = res.sub("_", string)
string = re.sub(r"(_)\1+", "_", string).lower()
while True:
if len(string) == 0:
return string
if string[0] == "_":
string = string[1:]
else:
break
while True:
if len(string) == 0:
return string
if string[-1] == "_":
string = string[:-1]
else:
break
if string[0].isdigit():
string = "get_" + string
return string
def process_name(name):
return change_name(standardize(name))
with open('ToolBench_G3_DFS_gpt-4o-2024-08-06_DRAFT.jsonl', 'r') as file:
data1 = json.load(file)
with open('dataset/ToolBench/test_data/G3.json', 'r') as file:
data2 = json.load(file)
matching_count = 0
total_count = len(data1)
for i in range(total_count):
api_results = data1[i]['execute_log']['api_result_ls']
relevant_apis = data2[i]['relevant APIs']
api_names_in_results = set()
for api_call in api_results:
for api in api_call:
tool_name = process_name(api['tool_name'])
api_name = process_name(api['api_name'])
api_names_in_results.add((tool_name, api_name))
all_apis_present = all((process_name(tool), process_name(api)) in api_names_in_results for tool, api in relevant_apis)
if all_apis_present:
matching_count += 1
path_rate = matching_count / total_count
print(f"path rate: {path_rate}")