mdevora commited on
Commit
e00e24d
·
1 Parent(s): 8c5d1ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -120,20 +120,20 @@ model_kwargs = {"max_length": max_length, "pad_token_id": 50256, "pad_token": "[
120
  # "padding": 'longest' #for open end generation
121
  # })
122
  llm = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], model_name=model_name, temperature=0.9)
123
- prompt_template = """I will ask about tools, techniques and discoveries about the exoplanets field. You are going to
124
- receive a context with information about related works, papers and tools for the PhD of Martín Dévora Pajares,
125
- also appearing as M. Dévora-Pajares.
126
- You can only answer things based on the context and will receive a memory section to remember previous interactions
127
  with the user.
128
  Context: {context}
129
  Question: {question}
130
- Memory: {memory}"""
131
 
132
  PROMPT = PromptTemplate(
133
- template=prompt_template, input_variables=["context", "question", "memory"]
134
  )
135
  chain_type_kwargs = {"prompt": PROMPT}
136
- memory = ConversationBufferWindowMemory(k=4, memory_key="memory", input_key="human_input")
137
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=vector_store.as_retriever(),
138
  chain_type_kwargs=chain_type_kwargs, return_source_documents=True,
139
  memory=memory)
@@ -146,14 +146,15 @@ qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=vector_s
146
  # print(f"Sources: {response['source_documents']}")
147
 
148
  def chat(message, history):
149
- yield qa({"query": message})['result']
 
150
  # print(f"Answer: {response['result']}")
151
  # print(f"Sources: {response['source_documents']}")
152
 
153
- gr.ChatInterface(chat, chatbot=gr.Chatbot(height=300),
154
- textbox=gr.Textbox(placeholder="Ask me about Voutique!", container=False, scale=7),
155
- title="Ask",
156
- description="Ask",
157
  theme="soft",
158
  examples=["What is SHERLOCK?", "What is MATRIX?", "What are the foundational papers of SHERLOCK?"],
159
  cache_examples=True,
 
120
  # "padding": 'longest' #for open end generation
121
  # })
122
  llm = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], model_name=model_name, temperature=0.9)
123
+ prompt_template = """You are going to
124
+ receive a context with information about related works, papers and tools for the PhD of Martín Dévora Pajares
125
+ (exoplanets field), also appearing as M. Dévora-Pajares.
126
+ You can only answer things based on the question, context and a memory section to remember previous interactions
127
  with the user.
128
  Context: {context}
129
  Question: {question}
130
+ Memory: {chat_history}"""
131
 
132
  PROMPT = PromptTemplate(
133
+ template=prompt_template, input_variables=["context", "question", "chat_history"]
134
  )
135
  chain_type_kwargs = {"prompt": PROMPT}
136
+ memory = ConversationBufferWindowMemory(k=2, memory_key="chat_history", question_key="question")
137
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=vector_store.as_retriever(),
138
  chain_type_kwargs=chain_type_kwargs, return_source_documents=True,
139
  memory=memory)
 
146
  # print(f"Sources: {response['source_documents']}")
147
 
148
  def chat(message, history):
149
+ result = qa({"query": message})
150
+ yield result['result'] + '\n\n' + result['source_documents']
151
  # print(f"Answer: {response['result']}")
152
  # print(f"Sources: {response['source_documents']}")
153
 
154
+ gr.ChatInterface(chat, chatbot=gr.Chatbot(),
155
+ textbox=gr.Textbox(placeholder="Ask me about SHERLOCK, MATRIX or WATSON!", container=False, scale=7),
156
+ title="PlanetHunters informative chatbot",
157
+ description="Ask anything related to SHERLOCK, MATRIX, WATSON and their related papers!",
158
  theme="soft",
159
  examples=["What is SHERLOCK?", "What is MATRIX?", "What are the foundational papers of SHERLOCK?"],
160
  cache_examples=True,