wylum commited on
Commit
568bb66
·
verified ·
1 Parent(s): ee6e3ed

Update app-azure.py

Browse files
Files changed (1) hide show
  1. app-azure.py +11 -6
app-azure.py CHANGED
@@ -150,7 +150,7 @@ class my_app:
150
  #self.chain = None
151
  #self.chat_history: list = []
152
  #self.N: int = 0
153
- #self.count: int = 0
154
 
155
  def __call__(self, file: str) -> Any:
156
  print("call")
@@ -288,7 +288,7 @@ def build_qa_chain(collection_name, vector_db, file: str):
288
  repo_id=llm_model,
289
  task="text-generation", # Explicitly specify task
290
  # model_kwargs={"temperature": temperature, "max_new_tokens": 250, "top_k": top_k}
291
- temperature = 0.0,
292
  max_new_tokens = 250,
293
  top_k = 3,
294
  )
@@ -304,7 +304,9 @@ def build_qa_chain(collection_name, vector_db, file: str):
304
  verbose=False,
305
  )
306
  """
307
-
 
 
308
  return collection_name, vector_db, chain
309
 
310
 
@@ -325,8 +327,10 @@ def get_response(collection_name, vector_db, qa_chain, history, query, file):
325
  chat_history_tuples = []
326
  for message in formatted_chat_history:
327
  chat_history_tuples.append((message[0], message[1]))
328
-
329
- collection_name, vector_db, qa_chain = build_qa_chain(collection_name, vector_db, file)
 
 
330
  result = qa_chain.invoke(
331
  {"question": query, "chat_history": chat_history_tuples}, return_only_outputs=True
332
  #{"question": query, "chat_history": format_chat_history(query, history)}, return_only_outputs=True
@@ -360,9 +364,10 @@ def purge_chat_and_render_first(file):
360
  history = []
361
  #count = 0
362
 
363
- #vincent added
364
  #count = count + 1
365
  #app.count += 1
 
366
 
367
  # Use PyMuPDF to render the first page of the uploaded document
368
  doc = pymupdf.open(file.name)
 
150
  #self.chain = None
151
  #self.chat_history: list = []
152
  #self.N: int = 0
153
+ self.count: int = 0
154
 
155
  def __call__(self, file: str) -> Any:
156
  print("call")
 
288
  repo_id=llm_model,
289
  task="text-generation", # Explicitly specify task
290
  # model_kwargs={"temperature": temperature, "max_new_tokens": 250, "top_k": top_k}
291
+ temperature = 0.1,
292
  max_new_tokens = 250,
293
  top_k = 3,
294
  )
 
304
  verbose=False,
305
  )
306
  """
307
+
308
+ #vincent added 20250211
309
+ app.count += 1
310
  return collection_name, vector_db, chain
311
 
312
 
 
327
  chat_history_tuples = []
328
  for message in formatted_chat_history:
329
  chat_history_tuples.append((message[0], message[1]))
330
+
331
+ #vincent added 20250211
332
+ if add.count == 0:
333
+ collection_name, vector_db, qa_chain = build_qa_chain(collection_name, vector_db, file)
334
  result = qa_chain.invoke(
335
  {"question": query, "chat_history": chat_history_tuples}, return_only_outputs=True
336
  #{"question": query, "chat_history": format_chat_history(query, history)}, return_only_outputs=True
 
364
  history = []
365
  #count = 0
366
 
367
+ #vincent added 20250211
368
  #count = count + 1
369
  #app.count += 1
370
+ app.count = 0
371
 
372
  # Use PyMuPDF to render the first page of the uploaded document
373
  doc = pymupdf.open(file.name)