Skip to content

Commit

Permalink
fix: Fixed issue which caused secrets database to not update correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jun 15, 2024
1 parent 0b852c8 commit 66b2bbe
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/biscuit/views/ai/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, master, *args, **kwargs) -> None:
self.__icon__ = "sparkle-filled"
self.name = "AI"
self.chat = None
self.api_key = ""

self.menu = AIMenu(self)
self.add_action("ellipsis", self.menu.show)
Expand All @@ -38,17 +39,16 @@ def __init__(self, master, *args, **kwargs) -> None:
self.cursor = self.db.cursor()
self.cursor.executescript(
"""
CREATE TABLE IF NOT EXISTS secrets (key TEXT NOT NULL, value TEXT);
CREATE TABLE IF NOT EXISTS secrets (key TEXT PRIMARY KEY NOT NULL, value TEXT);
"""
)

self.cursor.execute("SELECT value FROM secrets WHERE key='GEMINI_API_KEY'")
self.api_key = self.cursor.fetchone()
api_key = self.cursor.fetchone()

self.placeholder = AIPlaceholder(self)
if self.api_key:
self.api_key = self.api_key[0]
self.add_chat()
if api_key:
self.add_chat(api_key[0])
else:
self.add_placeholder()

Expand Down Expand Up @@ -81,6 +81,9 @@ def add_chat(self, api_key: str = None) -> None:
if api_key:
self.api_key = api_key

if not self.api_key:
return self.add_placeholder()

self.cursor.execute(
"INSERT OR REPLACE INTO secrets (key, value) VALUES ('GEMINI_API_KEY', ?)",
(self.api_key,),
Expand Down

0 comments on commit 66b2bbe

Please sign in to comment.