Spaces:
Sleeping
Sleeping
| import sqlite3 | |
| DB_PATH = "database/chat_memory.db" | |
| conn = sqlite3.connect(DB_PATH, check_same_thread=False) | |
| cursor = conn.cursor() | |
| cursor.execute( | |
| """ | |
| CREATE TABLE IF NOT EXISTS chats ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| user_message TEXT, | |
| ai_response TEXT | |
| ) | |
| """ | |
| ) | |
| conn.commit() | |
| def save_chat(user_message, ai_response): | |
| cursor.execute( | |
| "INSERT INTO chats(user_message, ai_response) VALUES (?, ?)", | |
| (user_message, ai_response) | |
| ) | |
| conn.commit() | |
| def get_chat_history(): | |
| cursor.execute("SELECT * FROM chats") | |
| return cursor.fetchall() |