Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -66,7 +66,7 @@ llm = HuggingFacePipeline(pipeline=pipe)
|
|
| 66 |
# --- Step 7: Setup memory and QA chain ---
|
| 67 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 68 |
|
| 69 |
-
|
| 70 |
You are a helpful assistant at the University of Hertfordshire. Use the context below to answer the question clearly and factually.
|
| 71 |
If the answer is not in the context, say you don't know.
|
| 72 |
|
|
@@ -76,15 +76,15 @@ Context:
|
|
| 76 |
Question:
|
| 77 |
{question}
|
| 78 |
|
| 79 |
-
|
| 80 |
""")
|
| 81 |
|
| 82 |
qa_chain = ConversationalRetrievalChain.from_llm(
|
| 83 |
llm=llm,
|
| 84 |
retriever=vectordb.as_retriever(search_kwargs={"k": 3}),
|
| 85 |
memory=memory,
|
| 86 |
-
chain_type="
|
| 87 |
-
combine_docs_chain_kwargs={"
|
| 88 |
)
|
| 89 |
|
| 90 |
# --- Step 8: Define chatbot logic ---
|
|
|
|
| 66 |
# --- Step 7: Setup memory and QA chain ---
|
| 67 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 68 |
|
| 69 |
+
custom_prompt = PromptTemplate.from_template("""
|
| 70 |
You are a helpful assistant at the University of Hertfordshire. Use the context below to answer the question clearly and factually.
|
| 71 |
If the answer is not in the context, say you don't know.
|
| 72 |
|
|
|
|
| 76 |
Question:
|
| 77 |
{question}
|
| 78 |
|
| 79 |
+
Answer:
|
| 80 |
""")
|
| 81 |
|
| 82 |
qa_chain = ConversationalRetrievalChain.from_llm(
|
| 83 |
llm=llm,
|
| 84 |
retriever=vectordb.as_retriever(search_kwargs={"k": 3}),
|
| 85 |
memory=memory,
|
| 86 |
+
chain_type="stuff",
|
| 87 |
+
combine_docs_chain_kwargs={"prompt": custom_prompt}
|
| 88 |
)
|
| 89 |
|
| 90 |
# --- Step 8: Define chatbot logic ---
|