mtyrrell commited on
Commit
5f9af61
·
1 Parent(s): 15565f4
Files changed (1) hide show
  1. auditqa/utils.py +13 -21
auditqa/utils.py CHANGED
@@ -12,36 +12,28 @@ from uuid import uuid4
12
 
13
 
14
 
15
- # def save_logs(scheduler, JSON_DATASET_PATH, logs, feedback=None) -> None:
16
- # """ Every interaction with app saves the log of question and answer,
17
- # this is to get the usage statistics of app and evaluate model performances.
18
- # Also saves user feedback (when provided).
19
- # """
20
- # if feedback:
21
- # logs["feedback"] = feedback #optional
22
-
23
- # with scheduler.lock:
24
- # with JSON_DATASET_PATH.open("a") as f:
25
- # json.dump(logs, f)
26
- # f.write("\n")
27
- # print("logging done")
28
-
29
  def save_logs(scheduler, JSON_DATASET_PATH, logs, feedback=None) -> None:
 
 
 
 
30
  try:
31
- # Create directory if it doesn't exist
32
- JSON_DATASET_PATH.parent.mkdir(parents=True, exist_ok=True)
33
-
34
- # Your existing code
35
  if feedback:
36
- logs["feedback"] = feedback
 
 
 
37
 
38
  with scheduler.lock:
39
  with JSON_DATASET_PATH.open("a") as f:
40
  json.dump(logs, f)
41
  f.write("\n")
42
- print("logging done")
43
  except Exception as e:
44
- print(f"Error saving logs: {str(e)}") # Add error logging
 
 
 
45
 
46
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):
47
  if type == 'NVIDIA':
 
12
 
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def save_logs(scheduler, JSON_DATASET_PATH, logs, feedback=None) -> None:
16
+ """ Every interaction with app saves the log of question and answer,
17
+ this is to get the usage statistics of app and evaluate model performances.
18
+ Also saves user feedback (when provided).
19
+ """
20
  try:
 
 
 
 
21
  if feedback:
22
+ logs["feedback"] = feedback #optional
23
+
24
+ # Ensure the parent directory exists
25
+ JSON_DATASET_PATH.parent.mkdir(parents=True, exist_ok=True)
26
 
27
  with scheduler.lock:
28
  with JSON_DATASET_PATH.open("a") as f:
29
  json.dump(logs, f)
30
  f.write("\n")
31
+ logging.info("Logging completed successfully")
32
  except Exception as e:
33
+ logging.error(f"Failed to save logs: {str(e)}")
34
+ print(f"Error saving logs: {str(e)}")
35
+
36
+
37
 
38
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):
39
  if type == 'NVIDIA':