Manel commited on
Commit
b3dda81
Β·
verified Β·
1 Parent(s): 3a863e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -99,7 +99,7 @@ def wrap_model(model, tokenizer):
99
 
100
 
101
 
102
- def fetch_context(db, model, query, logger, template, use_compressor=True):
103
  """
104
  Perform similarity search and retrieve related context to query.
105
  I have stored large documents in db so I can apply compressor on the set of retrived documents to
@@ -140,7 +140,7 @@ def format_context(docs):
140
 
141
 
142
 
143
- def llm_chain_with_context(model, model_name, query, context, template, logger):
144
  """
145
  Run simple chain with formatted prompt including query and retrieved context and the underlying model to generate a response.
146
  """
@@ -158,11 +158,11 @@ def llm_chain_with_context(model, model_name, query, context, template, logger):
158
  return output
159
 
160
 
161
- def generate_response(query, model, template, logger):
162
  start_time = time.time()
163
  progress_text = "Loading model. Please wait."
164
  my_bar = st.progress(0, text=progress_text)
165
- context = fetch_context(db, model, model_name, query, template, logger)
166
  # fill those as appropriate
167
  my_bar.progress(0.1, "Loading Database. Please wait.")
168
 
@@ -171,7 +171,7 @@ def generate_response(query, model, template, logger):
171
  my_bar.progress(0.5, "Running RAG. Please wait.")
172
 
173
  my_bar.progress(0.7, "Generating Answer. Please wait.")
174
- response = llm_chain_with_context(model, model_name, query, context, template, logger)
175
 
176
  logger.info(f"Total Execution Time: {time.time() - start_time}")
177
 
@@ -286,7 +286,7 @@ if __name__=="__main__":
286
  if user_question is not None and user_question!="":
287
  with st.chat_message("Human", avatar="πŸ§”πŸ»"):
288
  st.write(user_question)
289
- response = generate_response(user_question, model, all_templates, logger)
290
  with st.chat_message("AI", avatar="πŸ›οΈ"):
291
  st.write(response)
292
 
 
99
 
100
 
101
 
102
+ def fetch_context(db, model, query, template, use_compressor=True):
103
  """
104
  Perform similarity search and retrieve related context to query.
105
  I have stored large documents in db so I can apply compressor on the set of retrived documents to
 
140
 
141
 
142
 
143
+ def llm_chain_with_context(model, model_name, query, context, template):
144
  """
145
  Run simple chain with formatted prompt including query and retrieved context and the underlying model to generate a response.
146
  """
 
158
  return output
159
 
160
 
161
+ def generate_response(query, model, template):
162
  start_time = time.time()
163
  progress_text = "Loading model. Please wait."
164
  my_bar = st.progress(0, text=progress_text)
165
+ context = fetch_context(db, model, model_name, query, template)
166
  # fill those as appropriate
167
  my_bar.progress(0.1, "Loading Database. Please wait.")
168
 
 
171
  my_bar.progress(0.5, "Running RAG. Please wait.")
172
 
173
  my_bar.progress(0.7, "Generating Answer. Please wait.")
174
+ response = llm_chain_with_context(model, model_name, query, context, template)
175
 
176
  logger.info(f"Total Execution Time: {time.time() - start_time}")
177
 
 
286
  if user_question is not None and user_question!="":
287
  with st.chat_message("Human", avatar="πŸ§”πŸ»"):
288
  st.write(user_question)
289
+ response = generate_response(user_question, model, all_templates)
290
  with st.chat_message("AI", avatar="πŸ›οΈ"):
291
  st.write(response)
292