Spaces:
Sleeping
Sleeping
File size: 1,649 Bytes
a7228f9 |
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 |
import csv
import datetime
import uuid
from pathlib import Path
def cts_logger(scheduler, log_filename, log_data, response) -> None:
with scheduler.lock:
logger(log_filename, log_data, response)
def logger(log_filename, log_data, response):
with open(log_filename, mode='a', newline='') as log_file:
log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
# Get the current date and time
current_datetime = datetime.datetime.now()
date_str = current_datetime.strftime("%Y-%m-%d")
time_str = current_datetime.strftime("%H:%M:%S")
log_data.append(date_str)
log_data.append(time_str)
log_data.append(response)
# Write the log data to the CSV file
log_writer.writerow(log_data)
def cts_log_file_create(folder_name):
file_path = Path(folder_name + "/") / f"CTS_user_log{uuid.uuid4()}.csv"
with open(file_path, mode='a', newline='') as log_file:
log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
headers = [
"user_query",
"ref_question",
"query_score",
"code_executed",
"ref_question_2",
"query_score_2",
"ref_question_3",
"query_score_3",
"similarity_metric",
"model_used_for_embeddings",
"lower_threshold",
"upper_threshold",
"date",
"time",
"response",
]
# Write headers to the CSV file
log_writer.writerow(headers)
return file_path
|