Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,8 +41,8 @@ def get_text_chunks(text):
|
|
41 |
|
42 |
|
43 |
def get_vectorstore(text_chunks):
|
44 |
-
|
45 |
-
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
|
46 |
# embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-multilingual-mpnet-base-v2")
|
47 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
48 |
|
@@ -50,25 +50,25 @@ def get_vectorstore(text_chunks):
|
|
50 |
|
51 |
|
52 |
def get_conversation_chain(vectorstore, model_name):
|
53 |
-
llm = LlamaCpp(model_path=model_name,
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
memory = ConversationBufferMemory(memory_key='chat_history',
|
66 |
|
67 |
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm,
|
68 |
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
69 |
retriever=vectorstore.as_retriever(),
|
70 |
memory=memory,
|
71 |
-
return_source_documents=True
|
72 |
)
|
73 |
|
74 |
return conversation_chain
|
@@ -79,15 +79,15 @@ def handle_userinput(user_question):
|
|
79 |
|
80 |
st.session_state.chat_history = response['chat_history']
|
81 |
|
82 |
-
st.session_state.retrieved_text = response['source_documents'][0]
|
83 |
|
84 |
-
for i,
|
85 |
if i % 2 == 0:
|
86 |
st.write(user_template.replace(
|
87 |
-
"{{MSG}}", message.content
|
88 |
else:
|
89 |
st.write(bot_template.replace(
|
90 |
-
"{{MSG}}", message.content
|
91 |
|
92 |
|
93 |
|
|
|
41 |
|
42 |
|
43 |
def get_vectorstore(text_chunks):
|
44 |
+
embeddings = OpenAIEmbeddings()
|
45 |
+
# embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
|
46 |
# embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-multilingual-mpnet-base-v2")
|
47 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
48 |
|
|
|
50 |
|
51 |
|
52 |
def get_conversation_chain(vectorstore, model_name):
|
53 |
+
#llm = LlamaCpp(model_path=model_name,
|
54 |
+
# temperature=0.1,
|
55 |
+
# top_k=30,
|
56 |
+
# top_p=0.9,
|
57 |
+
# streaming=True,
|
58 |
+
# n_ctx=2048,
|
59 |
+
# n_parts=1,
|
60 |
+
# echo=True
|
61 |
+
# )
|
62 |
+
|
63 |
+
llm = ChatOpenAI()
|
64 |
|
65 |
+
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
66 |
|
67 |
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm,
|
68 |
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
69 |
retriever=vectorstore.as_retriever(),
|
70 |
memory=memory,
|
71 |
+
#return_source_documents=True
|
72 |
)
|
73 |
|
74 |
return conversation_chain
|
|
|
79 |
|
80 |
st.session_state.chat_history = response['chat_history']
|
81 |
|
82 |
+
#st.session_state.retrieved_text = response['source_documents'][0]
|
83 |
|
84 |
+
for i, message in enumerate(st.session_state.chat_history):
|
85 |
if i % 2 == 0:
|
86 |
st.write(user_template.replace(
|
87 |
+
"{{MSG}}", message.content), unsafe_allow_html=True)
|
88 |
else:
|
89 |
st.write(bot_template.replace(
|
90 |
+
"{{MSG}}", message.content), unsafe_allow_html=True)
|
91 |
|
92 |
|
93 |
|