Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,7 @@ def load_chat_history(session_id):
|
|
| 40 |
def chat_history(session_id):
|
| 41 |
return SQLChatMessageHistory(
|
| 42 |
session_id=session_id,
|
| 43 |
-
connection=
|
| 44 |
)
|
| 45 |
|
| 46 |
# Generate unique session ID for each user
|
|
@@ -50,7 +50,7 @@ if "session_id" not in st.session_state:
|
|
| 50 |
session_id = st.session_state.session_id
|
| 51 |
chat_history_instance = chat_history(session_id)
|
| 52 |
|
| 53 |
-
# Define Chat Prompt Template
|
| 54 |
chat_prompt = ChatPromptTemplate(
|
| 55 |
messages=[
|
| 56 |
('system', """You are an AI assistant specialized in Data Science tutoring.
|
|
@@ -71,7 +71,7 @@ chain = chat_prompt | llm | out_parser
|
|
| 71 |
# Define Runnable with message history
|
| 72 |
chat = RunnableWithMessageHistory(
|
| 73 |
chain,
|
| 74 |
-
lambda session: SQLChatMessageHistory(session,
|
| 75 |
input_messages_key="prompt",
|
| 76 |
history_messages_key="history"
|
| 77 |
)
|
|
|
|
| 40 |
def chat_history(session_id):
|
| 41 |
return SQLChatMessageHistory(
|
| 42 |
session_id=session_id,
|
| 43 |
+
connection="sqlite:///chat_history.db" # ✅ FIXED: Use a connection string
|
| 44 |
)
|
| 45 |
|
| 46 |
# Generate unique session ID for each user
|
|
|
|
| 50 |
session_id = st.session_state.session_id
|
| 51 |
chat_history_instance = chat_history(session_id)
|
| 52 |
|
| 53 |
+
# Define Chat Prompt Template
|
| 54 |
chat_prompt = ChatPromptTemplate(
|
| 55 |
messages=[
|
| 56 |
('system', """You are an AI assistant specialized in Data Science tutoring.
|
|
|
|
| 71 |
# Define Runnable with message history
|
| 72 |
chat = RunnableWithMessageHistory(
|
| 73 |
chain,
|
| 74 |
+
lambda session: SQLChatMessageHistory(session, "sqlite:///chat_history.db"),
|
| 75 |
input_messages_key="prompt",
|
| 76 |
history_messages_key="history"
|
| 77 |
)
|