ppsingh commited on
Commit
f387224
1 Parent(s): 17cd36a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -55,6 +55,14 @@ vectorstores = load_chunks()
55
  # -------------------------------------------------------------
56
  # Functions
57
  # -------------------------------------------------------------
 
 
 
 
 
 
 
 
58
  def make_html_source(source,i):
59
  """
60
  takes the text and converts it into html format for display in "source" side tab
@@ -227,6 +235,28 @@ async def chat(query,history,sources,reports,subtype,year):
227
  history = [tuple(x) for x in history]
228
 
229
  yield history,docs_html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  #process_pdf()
231
 
232
 
 
55
  # -------------------------------------------------------------
56
  # Functions
57
  # -------------------------------------------------------------
58
+
59
+ def save_logs(logs) -> None:
60
+ with scheduler.lock:
61
+ with JSON_DATASET_PATH.open("a") as f:
62
+ json.dump(logs, f)
63
+ f.write("\n")
64
+ print("logging done")
65
+
66
  def make_html_source(source,i):
67
  """
68
  takes the text and converts it into html format for display in "source" side tab
 
235
  history = [tuple(x) for x in history]
236
 
237
  yield history,docs_html
238
+
239
+
240
+ try:
241
+ timestamp = str(datetime.now().timestamp())
242
+ #file_store = "/data/logs/" + timestamp + ".json"
243
+ logs = {
244
+ "system_prompt": SYSTEM_PROMPT,
245
+ "sources":sources,
246
+ "reports":reports,
247
+ "subtype":subtype,
248
+ "year":year,
249
+ "question":query,
250
+ "sources":sources,
251
+ "retriever":
252
+ "docs":[doc.page_content for doc in context_retrieved],
253
+ "answer": history[-1][1],
254
+ "time": timestamp,
255
+ }
256
+ save_logs(file_store,logs)
257
+ except Exception as e:
258
+ print(e)
259
+
260
  #process_pdf()
261
 
262