trying again cpt
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import os
|
|
3 |
from langchain_community.vectorstores import Chroma
|
4 |
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
5 |
from langchain_community.llms import Together
|
6 |
-
from langchain.chains import
|
7 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
|
@@ -96,14 +96,17 @@ def app():
|
|
96 |
ANSWER_PROMPT = ChatPromptTemplate.from_template(answer_template)
|
97 |
|
98 |
question_generator_chain = LLMChain(llm=llmc, prompt=CONDENSE_QUESTION_PROMPT)
|
99 |
-
|
100 |
|
101 |
-
|
|
|
102 |
retriever=retriever,
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
107 |
)
|
108 |
|
109 |
st.header("Ask Away!")
|
@@ -126,12 +129,12 @@ def app():
|
|
126 |
try:
|
127 |
response = conversational_qa_chain.invoke(
|
128 |
{
|
129 |
-
"
|
130 |
"chat_history": chistory,
|
131 |
}
|
132 |
)
|
133 |
-
st.write(response)
|
134 |
-
message = {"role": "assistant", "content": response}
|
135 |
st.session_state.messages.append(message)
|
136 |
break
|
137 |
except Exception as e:
|
|
|
3 |
from langchain_community.vectorstores import Chroma
|
4 |
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
5 |
from langchain_community.llms import Together
|
6 |
+
from langchain.chains import create_retrieval_chain, create_history_aware_retriever, LLMChain
|
7 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
|
|
|
96 |
ANSWER_PROMPT = ChatPromptTemplate.from_template(answer_template)
|
97 |
|
98 |
question_generator_chain = LLMChain(llm=llmc, prompt=CONDENSE_QUESTION_PROMPT)
|
99 |
+
combine_docs_chain = LLMChain(llm=llm, prompt=ANSWER_PROMPT)
|
100 |
|
101 |
+
history_aware_retriever = create_history_aware_retriever(
|
102 |
+
llm=llmc,
|
103 |
retriever=retriever,
|
104 |
+
prompt=CONDENSE_QUESTION_PROMPT
|
105 |
+
)
|
106 |
+
|
107 |
+
conversational_qa_chain = create_retrieval_chain(
|
108 |
+
history_aware_retriever,
|
109 |
+
combine_docs_chain
|
110 |
)
|
111 |
|
112 |
st.header("Ask Away!")
|
|
|
129 |
try:
|
130 |
response = conversational_qa_chain.invoke(
|
131 |
{
|
132 |
+
"input": prompts2,
|
133 |
"chat_history": chistory,
|
134 |
}
|
135 |
)
|
136 |
+
st.write(response["answer"])
|
137 |
+
message = {"role": "assistant", "content": response["answer"]}
|
138 |
st.session_state.messages.append(message)
|
139 |
break
|
140 |
except Exception as e:
|