Skip to content

Commit

Permalink
Merge pull request #11 from infracloudio/multitenant-chathistory
Browse files Browse the repository at this point in the history
Fix multitenant chat history
  • Loading branch information
samkulkarni20 authored Aug 21, 2024
2 parents c83e7f8 + a013fc3 commit e126345
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,16 @@ def query_docs(self, model, question, vector_store, prompt, chat_history):
retriever = vector_store.as_retriever(
search_type="similarity", search_kwargs={"k": 4}
)
pass_question = lambda input: input["question"]
rag_chain = (
{"context": retriever | format_docs, "chat_history": chat_history, "question": RunnablePassthrough()}
RunnablePassthrough.assign(
context= pass_question | retriever | format_docs
)
| prompt
| model
| StrOutputParser()
)
answer = rag_chain.invoke(question)
answer = rag_chain.invoke({"question": question, "chat_history": chat_history})
return answer

def format_docs(docs):
Expand Down
4 changes: 3 additions & 1 deletion multi_tenant_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def main():

if question := st.chat_input("Chat with your doc"):
st.chat_message("user").markdown(question)
chat_history.append({"role": "user", "content": question})
with st.spinner():
answer = rag.query_docs(model=llm,
question=question,
Expand All @@ -118,6 +117,9 @@ def main():
chat_history=chat_history)
print("####\n#### Answer received by querying docs: " + answer + "\n####")
st.chat_message("assistant").markdown(answer)
chat_history.append({"role": "user", "content": question})
chat_history.append({"role": "assistant", "content": answer})
st.session_state["chat_history"] = chat_history

if __name__ == "__main__":
authenticator = authenticate("login")
Expand Down

0 comments on commit e126345

Please sign in to comment.