Spaces:
Runtime error
Runtime error
Download database/memory_manager.py from khubchand/ai-assistant-engine: direct link, hf CLI and curl.
- Browser
- Download file 621 Bytes
-
https://huggingface.co/spaces/khubchand/ai-assistant-engine/resolve/main/database/memory_manager.py
- Command line
-
hf download hf://spaces/khubchand/ai-assistant-engine/database/memory_manager.py
-
curl -L -o memory_manager.py https://huggingface.co/spaces/khubchand/ai-assistant-engine/resolve/main/database/memory_manager.py
621 Bytes
| 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() |