Spaces:
Runtime error
Runtime error
Commit
β’
a320e58
1
Parent(s):
e67fa80
Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
@@ -34,13 +34,17 @@ Only return the helpful OFFERS below as a list.
|
|
34 |
OFFERS:
|
35 |
"""
|
36 |
|
|
|
37 |
def set_custom_prompt():
|
38 |
"""
|
39 |
Prompt template for QA retrieval for each vectorstore
|
40 |
"""
|
41 |
-
prompt = PromptTemplate(
|
|
|
|
|
42 |
return prompt
|
43 |
|
|
|
44 |
def similar_offer(llm, prompt, db):
|
45 |
"""
|
46 |
Create a RetrievalQA chain for similarity-based offer retrieval
|
@@ -48,12 +52,13 @@ def similar_offer(llm, prompt, db):
|
|
48 |
qa_chain = RetrievalQA.from_chain_type(
|
49 |
llm=llm,
|
50 |
chain_type="stuff",
|
51 |
-
retriever=db.as_retriever(search_kwargs={"k":
|
52 |
return_source_documents=True,
|
53 |
chain_type_kwargs={"prompt": prompt},
|
54 |
)
|
55 |
return qa_chain
|
56 |
|
|
|
57 |
def generate_response(query):
|
58 |
"""
|
59 |
Generate a response based on the user query
|
@@ -63,18 +68,18 @@ def generate_response(query):
|
|
63 |
response = qa_result({"query": query}) # Pass the query in a dictionary
|
64 |
return response
|
65 |
|
|
|
66 |
def main():
|
67 |
st.title("π¦π Fetch Reward Search ChatBot")
|
68 |
query = st.text_input("Find offers you love!")
|
69 |
|
70 |
-
|
71 |
if st.button("Enter"):
|
72 |
-
|
73 |
if query:
|
74 |
response = generate_response(query)
|
75 |
st.text("Answer:")
|
76 |
st.write(response["result"])
|
77 |
-
|
78 |
sources = response["source_documents"]
|
79 |
if sources:
|
80 |
st.text("Sources:")
|
@@ -82,5 +87,6 @@ def main():
|
|
82 |
else:
|
83 |
st.text("No sources found")
|
84 |
|
|
|
85 |
if __name__ == "__main__":
|
86 |
main()
|
|
|
34 |
OFFERS:
|
35 |
"""
|
36 |
|
37 |
+
|
38 |
def set_custom_prompt():
|
39 |
"""
|
40 |
Prompt template for QA retrieval for each vectorstore
|
41 |
"""
|
42 |
+
prompt = PromptTemplate(
|
43 |
+
template=custom_prompt_template, input_variables=["context", "question"]
|
44 |
+
)
|
45 |
return prompt
|
46 |
|
47 |
+
|
48 |
def similar_offer(llm, prompt, db):
|
49 |
"""
|
50 |
Create a RetrievalQA chain for similarity-based offer retrieval
|
|
|
52 |
qa_chain = RetrievalQA.from_chain_type(
|
53 |
llm=llm,
|
54 |
chain_type="stuff",
|
55 |
+
retriever=db.as_retriever(search_kwargs={"k": 20}),
|
56 |
return_source_documents=True,
|
57 |
chain_type_kwargs={"prompt": prompt},
|
58 |
)
|
59 |
return qa_chain
|
60 |
|
61 |
+
|
62 |
def generate_response(query):
|
63 |
"""
|
64 |
Generate a response based on the user query
|
|
|
68 |
response = qa_result({"query": query}) # Pass the query in a dictionary
|
69 |
return response
|
70 |
|
71 |
+
|
72 |
def main():
|
73 |
st.title("π¦π Fetch Reward Search ChatBot")
|
74 |
query = st.text_input("Find offers you love!")
|
75 |
|
76 |
+
# "Enter" button
|
77 |
if st.button("Enter"):
|
|
|
78 |
if query:
|
79 |
response = generate_response(query)
|
80 |
st.text("Answer:")
|
81 |
st.write(response["result"])
|
82 |
+
|
83 |
sources = response["source_documents"]
|
84 |
if sources:
|
85 |
st.text("Sources:")
|
|
|
87 |
else:
|
88 |
st.text("No sources found")
|
89 |
|
90 |
+
|
91 |
if __name__ == "__main__":
|
92 |
main()
|