-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics_collector.py
51 lines (38 loc) · 2.2 KB
/
statistics_collector.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
import logging
import csv
class ChatHistoryCollector:
def __init__(self):
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
def collect(self, interactor):
self.logger.info("Collecting Chat History Statistics...")
with open(f'/opt/project/statistics/ChatHistory-{interactor.get_model_name()}.csv', 'w') as f:
header = ['role', 'content']
writer = csv.DictWriter(f, fieldnames=header)
writer.writeheader()
for row in interactor.get_chat_history():
writer.writerow(row)
class LLMStatisticsCollector:
def __init__(self):
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
def collect(self, interactor):
self.logger.info("Collecting LLM Statistics...")
with open(f'/opt/project/statistics/LLMStatistics-{interactor.get_model_name()}.csv', 'w') as f:
header = list(interactor.get_response_statistics()[1].keys())
writer = csv.DictWriter(f, fieldnames=header)
writer.writeheader()
for row in interactor.get_response_statistics():
writer.writerow(row)
class FeedbackStatisticsCollector:
def __init__(self):
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
def collect(self, interactor):
self.logger.info("Collecting Feedback Statistics...")
collected_list = [interactor.iterations_to_solve_the_task, interactor.json_format_re_requested, interactor.json_format_provided, interactor.json_parsed_via_llama3, interactor.llama3_helped, interactor.final_answer]
row_names = ['iterations_to_solve_the_task', 'json_format_re_requested', 'json_format_provided', 'json_parsed_via_llama3', 'llama3_helped', 'final_answer']
with open(f'/opt/project/statistics/FeedbackStatistics-{interactor.get_model_name()}.csv', 'w') as f:
header = ['name'] + list(interactor.iterations_to_solve_the_task.keys())
writer = csv.writer(f)
writer.writerow(header)
for idx, d in enumerate(collected_list):
row = [row_names[idx]] + [value for key, value in d.items()]
writer.writerow(row)