PCFISH commited on
Commit
1138359
β€’
1 Parent(s): ba021ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -70,20 +70,28 @@ def get_vectorstore(text_chunks):
70
 
71
 
72
  def get_conversation_chain(vectorstore):
73
- if st.session_state.conversation is None:
74
- gpt_model_name = 'gpt-3.5-turbo'
75
- llm = ChatOpenAI(model_name=gpt_model_name) # gpt-3.5 λͺ¨λΈ λ‘œλ“œ
76
-
77
- # λŒ€ν™” 기둝을 μ €μž₯ν•˜κΈ° μœ„ν•œ λ©”λͺ¨λ¦¬λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
78
- memory = ConversationBufferMemory(
79
- memory_key='chat_history', return_messages=True)
80
- # λŒ€ν™” 검색 체인을 μƒμ„±ν•©λ‹ˆλ‹€.
81
- conversation_chain = ConversationalRetrievalChain.from_llm(
82
- llm=llm,
83
- retriever=vectorstore.as_retriever(),
84
- memory=memory
85
- )
86
- st.session_state.conversation = conversation_chain
 
 
 
 
 
 
 
 
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