rishisim commited on
Commit
5fcd144
1 Parent(s): 75aa6ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -46,7 +46,9 @@ def chatresponse(message, history):
46
  # vectorstore = data_vectorstore + history_vectorstore
47
  vectorstore = data_vectorstore
48
  retriever = vectorstore.as_retriever()
49
-
 
 
50
  # from langchain.prompts import PromptTemplate
51
 
52
  from langchain_core.prompts import ChatPromptTemplate
@@ -57,13 +59,15 @@ def chatresponse(message, history):
57
  If somebody asks "Who are you?" or a similar phrase, state "I am Rishi's assistant built using a Large Language Model!"
58
  If the answer is not found in the context, kindly state "I don't know. Please ask Rishi on Discord. Discord Invite Link: https://discord.gg/6ezpZGeCcM. Or email at rishi@aiotsmartlabs.com" Don't try to make up an answer.
59
 
 
 
60
  CONTEXT: {context}
61
 
62
  QUESTION: {question}""")
63
 
64
  from langchain_core.runnables import RunnablePassthrough
65
  rag_chain = (
66
- {"context": history, "question": RunnablePassthrough()}
67
  | prompt
68
  | llm
69
  | StrOutputParser()
 
46
  # vectorstore = data_vectorstore + history_vectorstore
47
  vectorstore = data_vectorstore
48
  retriever = vectorstore.as_retriever()
49
+
50
+ history_str = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
51
+
52
  # from langchain.prompts import PromptTemplate
53
 
54
  from langchain_core.prompts import ChatPromptTemplate
 
59
  If somebody asks "Who are you?" or a similar phrase, state "I am Rishi's assistant built using a Large Language Model!"
60
  If the answer is not found in the context, kindly state "I don't know. Please ask Rishi on Discord. Discord Invite Link: https://discord.gg/6ezpZGeCcM. Or email at rishi@aiotsmartlabs.com" Don't try to make up an answer.
61
 
62
+ HISTORY: {history}
63
+
64
  CONTEXT: {context}
65
 
66
  QUESTION: {question}""")
67
 
68
  from langchain_core.runnables import RunnablePassthrough
69
  rag_chain = (
70
+ {"history": history_str, "context": retriever, "question": RunnablePassthrough()}
71
  | prompt
72
  | llm
73
  | StrOutputParser()