mayankchugh-learning commited on
Commit
2374d5d
·
verified ·
1 Parent(s): 43cdbc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -33,6 +33,19 @@ retriever = vectorstore_persisted.as_retriever(
33
  search_kwargs={'k': 5}
34
  )
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  qna_system_message = """
37
  You are an assistant to a financial services firm who answers user queries on annual reports.
38
  Users will ask questions delimited by triple backticks, that is, ```.
@@ -83,6 +96,17 @@ def predict(user_input):
83
  # While the prediction is made, log both the inputs and outputs to a local log file
84
  # While writing to the log file, ensure that the commit scheduler is locked to avoid parallel
85
  # access
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  return prediction
88
 
 
33
  search_kwargs={'k': 5}
34
  )
35
 
36
+ # Prepare the logging functionality
37
+
38
+ log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
39
+ log_folder = log_file.parent
40
+
41
+ scheduler = CommitScheduler(
42
+ repo_id="document-qna-chroma-anyscale-logs",
43
+ repo_type="dataset",
44
+ folder_path=log_folder,
45
+ path_in_repo="data",
46
+ every=2
47
+ )
48
+
49
  qna_system_message = """
50
  You are an assistant to a financial services firm who answers user queries on annual reports.
51
  Users will ask questions delimited by triple backticks, that is, ```.
 
96
  # While the prediction is made, log both the inputs and outputs to a local log file
97
  # While writing to the log file, ensure that the commit scheduler is locked to avoid parallel
98
  # access
99
+
100
+ with scheduler.lock:
101
+ with log_file.open("a") as f:
102
+ f.write(json.dumps(
103
+ {
104
+ 'user_input': user_input,
105
+ 'retrieved_context': context_for_query,
106
+ 'model_response': prediction
107
+ }
108
+ ))
109
+ f.write("\n")
110
 
111
  return prediction
112