lfoppiano commited on
Commit
9e4289a
1 Parent(s): e7425e5

cleanup and update documentation

Browse files
README.md CHANGED
@@ -23,7 +23,7 @@ We target only the full-text using [Grobid](https://github.com/kermitt2/grobid)
23
 
24
  Additionally, this frontend provides the visualisation of named entities on LLM responses to extract <span stype="color:yellow">physical quantities, measurements</span> (with [grobid-quantities](https://github.com/kermitt2/grobid-quantities)) and <span stype="color:blue">materials</span> mentions (with [grobid-superconductors](https://github.com/lfoppiano/grobid-superconductors)).
25
 
26
- The conversation is backed up by a sliding window memory (top 4 more recent messages) that help refers to information previously discussed in the chat.
27
 
28
  **Demos**:
29
  - (on HuggingFace spaces): https://lfoppiano-document-qa.hf.space/
 
23
 
24
  Additionally, this frontend provides the visualisation of named entities on LLM responses to extract <span stype="color:yellow">physical quantities, measurements</span> (with [grobid-quantities](https://github.com/kermitt2/grobid-quantities)) and <span stype="color:blue">materials</span> mentions (with [grobid-superconductors](https://github.com/lfoppiano/grobid-superconductors)).
25
 
26
+ The conversation is kept in memory up by a buffered sliding window memory (top 4 more recent messages) and the messages are injected in the context as "previous messages".
27
 
28
  **Demos**:
29
  - (on HuggingFace spaces): https://lfoppiano-document-qa.hf.space/
document_qa/document_qa_engine.py CHANGED
@@ -41,10 +41,6 @@ class DocumentQAEngine:
41
  ):
42
  self.embedding_function = embedding_function
43
  self.llm = llm
44
- # if memory:
45
- # prompt = self.default_prompts[qa_chain_type].PROMPT_SELECTOR.get_prompt(llm)
46
- # self.chain = load_qa_chain(llm, chain_type=qa_chain_type, prompt=prompt, memory=memory)
47
- # else:
48
  self.memory = memory
49
  self.chain = load_qa_chain(llm, chain_type=qa_chain_type)
50
 
@@ -161,7 +157,7 @@ class DocumentQAEngine:
161
  def _run_query(self, doc_id, query, context_size=4):
162
  relevant_documents = self._get_context(doc_id, query, context_size)
163
  response = self.chain.run(input_documents=relevant_documents,
164
- question=query)
165
 
166
  if self.memory:
167
  self.memory.save_context({"input": query}, {"output": response})
@@ -172,7 +168,9 @@ class DocumentQAEngine:
172
  retriever = db.as_retriever(search_kwargs={"k": context_size})
173
  relevant_documents = retriever.get_relevant_documents(query)
174
  if self.memory and len(self.memory.buffer_as_messages) > 0:
175
- relevant_documents.append(Document(page_content="Previous conversation:\n{}\n\n".format(self.memory.buffer_as_str)))
 
 
176
  return relevant_documents
177
 
178
  def get_all_context_by_document(self, doc_id):
 
41
  ):
42
  self.embedding_function = embedding_function
43
  self.llm = llm
 
 
 
 
44
  self.memory = memory
45
  self.chain = load_qa_chain(llm, chain_type=qa_chain_type)
46
 
 
157
  def _run_query(self, doc_id, query, context_size=4):
158
  relevant_documents = self._get_context(doc_id, query, context_size)
159
  response = self.chain.run(input_documents=relevant_documents,
160
+ question=query)
161
 
162
  if self.memory:
163
  self.memory.save_context({"input": query}, {"output": response})
 
168
  retriever = db.as_retriever(search_kwargs={"k": context_size})
169
  relevant_documents = retriever.get_relevant_documents(query)
170
  if self.memory and len(self.memory.buffer_as_messages) > 0:
171
+ relevant_documents.append(
172
+ Document(page_content="Previous conversation:\n{}\n\n".format(self.memory.buffer_as_str))
173
+ )
174
  return relevant_documents
175
 
176
  def get_all_context_by_document(self, doc_id):
streamlit_app.py CHANGED
@@ -5,7 +5,6 @@ from tempfile import NamedTemporaryFile
5
 
6
  import dotenv
7
  from grobid_quantities.quantities import QuantitiesAPI
8
- from langchain.callbacks import PromptLayerCallbackHandler
9
  from langchain.llms.huggingface_hub import HuggingFaceHub
10
  from langchain.memory import ConversationBufferWindowMemory
11
 
 
5
 
6
  import dotenv
7
  from grobid_quantities.quantities import QuantitiesAPI
 
8
  from langchain.llms.huggingface_hub import HuggingFaceHub
9
  from langchain.memory import ConversationBufferWindowMemory
10