Update app.py
Browse files
app.py
CHANGED
|
@@ -62,19 +62,21 @@ def get_vectorstore(text_chunks):
|
|
| 62 |
|
| 63 |
|
| 64 |
def get_conversation_chain(vectorstore):
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
return st.session_state.conversation
|
| 79 |
|
| 80 |
# μ¬μ©μ μ
λ ₯μ μ²λ¦¬νλ ν¨μμ
λλ€.
|
|
@@ -99,9 +101,8 @@ def main():
|
|
| 99 |
page_icon=":books:")
|
| 100 |
st.write(css, unsafe_allow_html=True)
|
| 101 |
|
| 102 |
-
if "conversation" not in st.session_state:
|
| 103 |
st.session_state.conversation = None
|
| 104 |
-
if "chat_history" not in st.session_state:
|
| 105 |
st.session_state.chat_history = None
|
| 106 |
|
| 107 |
st.header("Chat with multiple Files :")
|
|
@@ -123,7 +124,6 @@ def main():
|
|
| 123 |
doc_list = []
|
| 124 |
|
| 125 |
for file in docs:
|
| 126 |
-
print('file - type : ', file.type)
|
| 127 |
if file.type == 'text/plain':
|
| 128 |
# file is .txt
|
| 129 |
doc_list.extend(get_text_file(file))
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def get_conversation_chain(vectorstore):
|
| 65 |
+
if st.session_state.conversation is None:
|
| 66 |
+
gpt_model_name = 'gpt-3.5-turbo'
|
| 67 |
+
llm = ChatOpenAI(model_name=gpt_model_name) # gpt-3.5 λͺ¨λΈ λ‘λ
|
| 68 |
+
|
| 69 |
+
# λν κΈ°λ‘μ μ μ₯νκΈ° μν λ©λͺ¨λ¦¬λ₯Ό μμ±ν©λλ€.
|
| 70 |
+
memory = ConversationBufferMemory(
|
| 71 |
+
memory_key='chat_history', return_messages=True)
|
| 72 |
+
# λν κ²μ 체μΈμ μμ±ν©λλ€.
|
| 73 |
+
conversation_chain = ConversationalRetrievalChain.from_llm(
|
| 74 |
+
llm=llm,
|
| 75 |
+
retriever=vectorstore.as_retriever(),
|
| 76 |
+
memory=memory
|
| 77 |
+
)
|
| 78 |
+
st.session_state.conversation = conversation_chain
|
| 79 |
+
|
| 80 |
return st.session_state.conversation
|
| 81 |
|
| 82 |
# μ¬μ©μ μ
λ ₯μ μ²λ¦¬νλ ν¨μμ
λλ€.
|
|
|
|
| 101 |
page_icon=":books:")
|
| 102 |
st.write(css, unsafe_allow_html=True)
|
| 103 |
|
| 104 |
+
if "conversation" not in st.session_state or st.session_state.conversation is None:
|
| 105 |
st.session_state.conversation = None
|
|
|
|
| 106 |
st.session_state.chat_history = None
|
| 107 |
|
| 108 |
st.header("Chat with multiple Files :")
|
|
|
|
| 124 |
doc_list = []
|
| 125 |
|
| 126 |
for file in docs:
|
|
|
|
| 127 |
if file.type == 'text/plain':
|
| 128 |
# file is .txt
|
| 129 |
doc_list.extend(get_text_file(file))
|