-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (27 loc) · 800 Bytes
/
utils.py
File metadata and controls
34 lines (27 loc) · 800 Bytes
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
import re
def get_n_items(obj):
total_length = 0
if isinstance(obj, list):
for item in obj:
if isinstance(item, list) or isinstance(item, dict):
total_length += get_n_items(item)
else:
total_length += 1
elif isinstance(obj, dict):
for key, value in obj.items():
if isinstance(value, list) or isinstance(value, dict):
total_length += get_n_items(value)
else:
total_length += 1
return total_length
def try_parse_llm_score(score):
try:
pattern = r"(\d+)"
match = re.search(pattern, score)
if match:
score = float(match.group(1))
else:
score = 0
except:
score = 0
return score