File size: 638 Bytes
9017a28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()