Skip to content

Commit

Permalink
Merge pull request #324 from imjwang/chat-history-buffer
Browse files Browse the repository at this point in the history
Adding Conversation History
  • Loading branch information
PromtEngineer committed Aug 4, 2023
2 parents d4b0f75 + bb0511a commit d85298e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion run_localGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from langchain.chains import RetrievalQA
from langchain.embeddings import HuggingFaceInstructEmbeddings
from langchain.llms import HuggingFacePipeline, LlamaCpp
from langchain.memory import ConversationBufferMemory
from langchain.prompts import PromptTemplate

# from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.vectorstores import Chroma
Expand Down Expand Up @@ -224,9 +226,27 @@ def main(device_type, show_sources):
model_id = "TheBloke/Llama-2-7B-Chat-GGML"
model_basename = "llama-2-7b-chat.ggmlv3.q4_0.bin"

template = """Use the following pieces of context to answer the question at the end. If you don't know the answer,\
just say that you don't know, don't try to make up an answer.
{context}
{history}
Question: {question}
Helpful Answer:"""

prompt = PromptTemplate(input_variables=["history", "context", "question"], template=template)
memory = ConversationBufferMemory(input_key="question", memory_key="history")

llm = load_model(device_type, model_id=model_id, model_basename=model_basename)

qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True)
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True,
chain_type_kwargs={"prompt": prompt, "memory": memory},
)
# Interactive questions and answers
while True:
query = input("\nEnter a query: ")
Expand Down

0 comments on commit d85298e

Please sign in to comment.