Update app.py
Browse files
app.py
CHANGED
|
@@ -70,20 +70,28 @@ def get_vectorstore(text_chunks):
|
|
| 70 |
|
| 71 |
|
| 72 |
def get_conversation_chain(vectorstore):
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
return st.session_state.conversation if st.session_state.conversation else ConversationalRetrievalChain()
|
| 89 |
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
def get_conversation_chain(vectorstore):
|
| 73 |
+
print(f"DEBUG: session_state.conversation before initialization: {st.session_state.conversation}")
|
| 74 |
+
|
| 75 |
+
try:
|
| 76 |
+
if st.session_state.conversation is None:
|
| 77 |
+
gpt_model_name = 'gpt-3.5-turbo'
|
| 78 |
+
llm = ChatOpenAI(model_name=gpt_model_name)
|
| 79 |
+
|
| 80 |
+
# ๋ํ ๊ธฐ๋ก์ ์ ์ฅํ๊ธฐ ์ํ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
| 81 |
+
memory = ConversationBufferMemory(
|
| 82 |
+
memory_key='chat_history', return_messages=True)
|
| 83 |
+
# ๋ํ ๊ฒ์ ์ฒด์ธ์ ์์ฑํฉ๋๋ค.
|
| 84 |
+
conversation_chain = ConversationalRetrievalChain.from_llm(
|
| 85 |
+
llm=llm,
|
| 86 |
+
retriever=vectorstore.as_retriever(),
|
| 87 |
+
memory=memory
|
| 88 |
+
)
|
| 89 |
+
st.session_state.conversation = conversation_chain
|
| 90 |
+
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print(f"Error during conversation initialization: {e}")
|
| 93 |
+
|
| 94 |
+
print(f"DEBUG: session_state.conversation after initialization: {st.session_state.conversation}")
|
| 95 |
|
| 96 |
return st.session_state.conversation if st.session_state.conversation else ConversationalRetrievalChain()
|
| 97 |
|