anasmkh commited on
Commit
0cb23e9
·
verified ·
1 Parent(s): b6f8d6f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +25 -2
main.py CHANGED
@@ -49,8 +49,31 @@ qa_chain = RetrievalQA.from_llm(llm=local_llm, retriever=retriever)
49
 
50
 
51
  def gradinterface(query,history):
52
- result = qa_chain({'query': query})
53
- return result.split(' : ').strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56
  demo = gr.ChatInterface(fn=gradinterface, title='OUR_OWN_BOT')
 
49
 
50
 
51
  def gradinterface(query,history):
52
+ while True:
53
+ query = input("\nQuery: ")
54
+ if query == "exit":
55
+ break
56
+ if query.strip() == "":
57
+ continue
58
+
59
+ template = """Use the following pieces of context to answer the question at the end.
60
+ If you don't know the answer, just say that you don't know, don't try to make up an answer.
61
+ Use three sentences maximum and keep the answer as concise as possible.
62
+ {context}
63
+ Question: {question}
64
+ Helpful Answer:"""
65
+
66
+ QA_CHAIN_PROMPT = PromptTemplate(
67
+ input_variables=["context", "question"],
68
+ template=template,
69
+ )
70
+ qa_chain = RetrievalQA.from_chain_type(
71
+ local_llm,
72
+ retriever=vector.as_retriever(),
73
+ chain_type_kwargs={"prompt": QA_CHAIN_PROMPT},
74
+ )
75
+ result = qa_chain({"query": query})
76
+ return result['result'].split(':')[-1].strip()
77
 
78
 
79
  demo = gr.ChatInterface(fn=gradinterface, title='OUR_OWN_BOT')