pvanand commited on
Commit
5c4af3f
1 Parent(s): 7630caf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -2
main.py CHANGED
@@ -106,8 +106,11 @@ async def verify_api_key(api_key: str = Security(api_key_header)):
106
  return api_key
107
 
108
  # SQLite setup
 
 
109
  def init_db():
110
- conn = sqlite3.connect('conversations.db')
 
111
  c = conn.cursor()
112
  c.execute('''CREATE TABLE IF NOT EXISTS conversations
113
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -122,7 +125,7 @@ def init_db():
122
  init_db()
123
 
124
  def update_db(user_id, conversation_id, message, response):
125
- conn = sqlite3.connect('conversations.db')
126
  c = conn.cursor()
127
  c.execute('''INSERT INTO conversations (user_id, conversation_id, message, response)
128
  VALUES (?, ?, ?, ?)''', (user_id, conversation_id, message, response))
 
106
  return api_key
107
 
108
  # SQLite setup
109
+ DB_PATH = '/app/data/conversations.db'
110
+
111
  def init_db():
112
+ os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
113
+ conn = sqlite3.connect(DB_PATH)
114
  c = conn.cursor()
115
  c.execute('''CREATE TABLE IF NOT EXISTS conversations
116
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
 
125
  init_db()
126
 
127
  def update_db(user_id, conversation_id, message, response):
128
+ conn = sqlite3.connect(DB_PATH)
129
  c = conn.cursor()
130
  c.execute('''INSERT INTO conversations (user_id, conversation_id, message, response)
131
  VALUES (?, ?, ?, ?)''', (user_id, conversation_id, message, response))