girishwangikar commited on
Commit
b9fe0c7
Β·
verified Β·
1 Parent(s): 4f15ef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -52,6 +52,7 @@ def clear_knowledge_base():
52
  vectors = None # Reset the vector store
53
  return "Knowledge base cleared."
54
 
 
55
  # Function to process questions
56
  def process_question(question):
57
  global vectors
@@ -60,7 +61,9 @@ def process_question(question):
60
 
61
  # Create document retrieval chain
62
  retriever = vectors.as_retriever(search_type="similarity", search_kwargs={"k": 5})
63
- documents = retriever.get_relevant_documents(question)
 
 
64
 
65
  if not documents:
66
  return "No relevant context found.", "", 0
@@ -68,14 +71,15 @@ def process_question(question):
68
  # Create context from retrieved documents
69
  context = "\n\n".join([doc.page_content for doc in documents])
70
 
71
- # Use the LLM to answer the question
72
- response = llm({"context": context, "input": question})
73
 
74
  # Confidence score as average relevance
75
  confidence_score = sum([doc.metadata.get('score', 0) for doc in documents]) / len(documents)
76
 
77
  return response, context, round(confidence_score, 2)
78
 
 
79
  # CSS styling
80
  CSS = """
81
  .duplicate-button { margin: auto !important; color: white !important; background: black !important; border-radius: 100vh !important;}
 
52
  vectors = None # Reset the vector store
53
  return "Knowledge base cleared."
54
 
55
+ # Function to process questions
56
  # Function to process questions
57
  def process_question(question):
58
  global vectors
 
61
 
62
  # Create document retrieval chain
63
  retriever = vectors.as_retriever(search_type="similarity", search_kwargs={"k": 5})
64
+
65
+ # Use the invoke method instead of get_relevant_documents
66
+ documents = retriever.invoke(question)
67
 
68
  if not documents:
69
  return "No relevant context found.", "", 0
 
71
  # Create context from retrieved documents
72
  context = "\n\n".join([doc.page_content for doc in documents])
73
 
74
+ # Use the invoke method for the LLM
75
+ response = llm.invoke({"context": context, "input": question})
76
 
77
  # Confidence score as average relevance
78
  confidence_score = sum([doc.metadata.get('score', 0) for doc in documents]) / len(documents)
79
 
80
  return response, context, round(confidence_score, 2)
81
 
82
+
83
  # CSS styling
84
  CSS = """
85
  .duplicate-button { margin: auto !important; color: white !important; background: black !important; border-radius: 100vh !important;}