1MR commited on
Commit
a7fd28b
·
verified ·
1 Parent(s): d624eba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -31
app.py CHANGED
@@ -103,46 +103,17 @@ def load_llm(api_key):
103
  model_kwargs={"temperature": 0.5, "max_length": 100}
104
  )
105
 
106
- # def ask_question(question, retriever, llm):
107
- # """Uses a QA chain to retrieve and answer a question."""
108
- # qa_chain = RetrievalQA.from_chain_type(
109
- # retriever=retriever,
110
- # chain_type="stuff",
111
- # llm=llm,
112
- # return_source_documents=False
113
- # )
114
- # response = qa_chain.invoke({"query": question})
115
- # return response["result"]
116
-
117
- from langchain.prompts import PromptTemplate
118
-
119
  def ask_question(question, retriever, llm):
120
  """Uses a QA chain to retrieve and answer a question."""
121
- # Define the custom prompt template
122
- prompt_template = PromptTemplate(
123
- input_variables=["context", "query"],
124
- template="You are an assistant. Answer the user's question based on the context below. "
125
- "Do not reference the dataset or provide unnecessary details.\n\n"
126
- "Context: {context}\n\n"
127
- "Question: {query}\n\n"
128
- "Answer:"
129
- )
130
-
131
- # Create the QA chain
132
  qa_chain = RetrievalQA.from_chain_type(
133
  retriever=retriever,
134
  chain_type="stuff",
135
  llm=llm,
136
- return_source_documents=False,
137
- chain_type_kwargs={"prompt": prompt_template}
138
  )
139
-
140
- # Pass the question in a dictionary to match the required input keys
141
  response = qa_chain.invoke({"query": question})
142
  return response["result"]
143
-
144
-
145
-
146
  # Streamlit App
147
  def upload_data():
148
  st.title("Upload Dataset")
 
103
  model_kwargs={"temperature": 0.5, "max_length": 100}
104
  )
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  def ask_question(question, retriever, llm):
107
  """Uses a QA chain to retrieve and answer a question."""
 
 
 
 
 
 
 
 
 
 
 
108
  qa_chain = RetrievalQA.from_chain_type(
109
  retriever=retriever,
110
  chain_type="stuff",
111
  llm=llm,
112
+ return_source_documents=False
 
113
  )
 
 
114
  response = qa_chain.invoke({"query": question})
115
  return response["result"]
116
+
 
 
117
  # Streamlit App
118
  def upload_data():
119
  st.title("Upload Dataset")