mtyrrell commited on
Commit
8aba5e3
·
1 Parent(s): 41235aa

fixed save logs

Browse files
Files changed (2) hide show
  1. app.py +4 -2
  2. auditqa/utils.py +20 -6
app.py CHANGED
@@ -126,7 +126,8 @@ def submit_feedback(feedback, logs_data):
126
  logger.error("No logs data available for feedback")
127
  return gr.update(visible=False), gr.update(visible=True)
128
 
129
- save_logs(scheduler, JSON_DATASET_PATH, logs_data, feedback)
 
130
  return gr.update(visible=False), gr.update(visible=True)
131
  except Exception as e:
132
  logger.error(f"Error saving feedback: {e}")
@@ -324,7 +325,8 @@ async def chat(query, history, sources, reports, subtype, year, client_ip=None,
324
 
325
  try:
326
  # Save log after streaming is complete
327
- save_logs(scheduler, JSON_DATASET_PATH, logs_data)
 
328
  except Exception as e:
329
  logging.error(e)
330
 
 
126
  logger.error("No logs data available for feedback")
127
  return gr.update(visible=False), gr.update(visible=True)
128
 
129
+ # save_logs(scheduler, JSON_DATASET_PATH, logs_data, feedback)
130
+ save_logs(JSON_DATASET_PATH, logs_data, feedback)
131
  return gr.update(visible=False), gr.update(visible=True)
132
  except Exception as e:
133
  logger.error(f"Error saving feedback: {e}")
 
325
 
326
  try:
327
  # Save log after streaming is complete
328
+ # save_logs(scheduler, JSON_DATASET_PATH, logs_data)
329
+ save_logs(JSON_DATASET_PATH, logs_data)
330
  except Exception as e:
331
  logging.error(e)
332
 
auditqa/utils.py CHANGED
@@ -12,18 +12,32 @@ 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 open(JSON_DATASET_PATH, 'a') as f:
25
- json.dump(logs, f)
26
- f.write("\n")
27
  print("logging done")
28
 
29
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):
 
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 open(JSON_DATASET_PATH, 'a') as f:
25
+ # json.dump(logs, f)
26
+ # f.write("\n")
27
+ # print("logging done")
28
+
29
+
30
+ def save_logs(JSON_DATASET_PATH: str, logs: dict, feedback: str = None) -> None:
31
  """ Every interaction with app saves the log of question and answer,
32
  this is to get the usage statistics of app and evaluate model performances.
33
  Also saves user feedback (when provided).
34
  """
35
  if feedback:
36
+ logs["feedback"] = feedback
37
 
38
+ with open(JSON_DATASET_PATH, 'a') as f:
39
+ json.dump(logs, f)
40
+ f.write("\n")
 
41
  print("logging done")
42
 
43
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):