Update app.py
Browse files
app.py
CHANGED
@@ -310,6 +310,7 @@ prompt_template = ChatPromptTemplate.from_messages([
|
|
310 |
# )
|
311 |
|
312 |
|
|
|
313 |
def process_question(question: str):
|
314 |
"""
|
315 |
Process the question and return the answer and context
|
@@ -317,26 +318,21 @@ def process_question(question: str):
|
|
317 |
# Check cache first
|
318 |
if question in question_cache:
|
319 |
return question_cache[question], "" # Retourne la réponse cachée et un statut vide
|
320 |
-
|
321 |
relevant_docs = retriever(question)
|
322 |
context = "\n".join([doc.page_content for doc in relevant_docs])
|
323 |
-
|
324 |
prompt = prompt_template.format_messages(
|
325 |
context=context,
|
326 |
question=question
|
327 |
-
|
328 |
-
|
329 |
response = ""
|
330 |
for chunk in llm.stream(prompt):
|
331 |
if isinstance(chunk, str):
|
332 |
response += chunk
|
333 |
else:
|
334 |
response += chunk.content
|
335 |
-
|
336 |
# Mettez le résultat en cache à la fin
|
337 |
question_cache[question] = (response, context)
|
338 |
-
|
339 |
-
yield response, context
|
340 |
|
341 |
# CSS personnalisé avec l'importation de Google Fonts
|
342 |
custom_css = """
|
|
|
310 |
# )
|
311 |
|
312 |
|
313 |
+
|
314 |
def process_question(question: str):
|
315 |
"""
|
316 |
Process the question and return the answer and context
|
|
|
318 |
# Check cache first
|
319 |
if question in question_cache:
|
320 |
return question_cache[question], "" # Retourne la réponse cachée et un statut vide
|
|
|
321 |
relevant_docs = retriever(question)
|
322 |
context = "\n".join([doc.page_content for doc in relevant_docs])
|
|
|
323 |
prompt = prompt_template.format_messages(
|
324 |
context=context,
|
325 |
question=question
|
326 |
+
)
|
|
|
327 |
response = ""
|
328 |
for chunk in llm.stream(prompt):
|
329 |
if isinstance(chunk, str):
|
330 |
response += chunk
|
331 |
else:
|
332 |
response += chunk.content
|
|
|
333 |
# Mettez le résultat en cache à la fin
|
334 |
question_cache[question] = (response, context)
|
335 |
+
return response, context
|
|
|
336 |
|
337 |
# CSS personnalisé avec l'importation de Google Fonts
|
338 |
custom_css = """
|