Spaces:
No application file
No application file
import sqlite3 | |
import datetime | |
conn = sqlite3.connect("memory.db", check_same_thread=False) | |
cursor = conn.cursor() | |
cursor.execute(""" | |
CREATE TABLE IF NOT EXISTS memory ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
query TEXT, | |
response TEXT, | |
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP | |
) | |
""") | |
conn.commit() | |
def store_query(query, response): | |
cursor.execute("INSERT INTO memory (query, response) VALUES (?, ?)", (query, response)) | |
conn.commit() | |
def get_previous_queries(): | |
cursor.execute("SELECT query, response, timestamp FROM memory ORDER BY id DESC LIMIT 5") | |
return cursor.fetchall() | |