Closed LuciAkirami closed 2 weeks ago
I have noticed another bug. This is when let's say, I click on the Edit Prompt
and do not edit anything and click on Save Prompt
. Then even though the user prompt and system prompt is the same, the version gets updated. For this I made changes to the code as follows
Existing Code: storage/sqlite_backend.py - line 116
def update_prompt(self, prompt: Prompt):
"""Update an existing prompt in the database by id.
Args:
prompt (Prompt): The prompt to update.
"""
session = self.Session()
try:
existing_prompt = session.execute(
select(PromptModel).where(PromptModel.id == prompt.id)
).scalar_one_or_none()
if not existing_prompt:
raise PromptNotFoundException(
f"Prompt with name {prompt.name} not found."
)
existing_prompt.system = prompt.system
existing_prompt.user = prompt.user
existing_prompt.active = prompt.active
session.commit()
Update I suggested above (to sovlve the "[BUG] Prompt Version not Updating in DB and UI"):
def update_prompt(self, prompt: Prompt):
"""Update an existing prompt in the database by id.
Args:
prompt (Prompt): The prompt to update.
"""
session = self.Session()
try:
existing_prompt = session.execute(
select(PromptModel).where(PromptModel.id == prompt.id)
).scalar_one_or_none()
if not existing_prompt:
raise PromptNotFoundException(
f"Prompt with name {prompt.name} not found."
)
existing_prompt.system = prompt.system
existing_prompt.user = prompt.user
existing_prompt.active = prompt.active
# updating the version
existing_prompt.version += 1
# updating the version
session.commit()
Updating it again to fix the new bug (that is do not change the version if no changes are made to the user and system prompt)
def update_prompt(self, prompt: Prompt):
"""Update an existing prompt in the database by id.
Args:
prompt (Prompt): The prompt to update.
"""
session = self.Session()
try:
existing_prompt = session.execute(
select(PromptModel).where(PromptModel.id == prompt.id)
).scalar_one_or_none()
if not existing_prompt:
raise PromptNotFoundException(
f"Prompt with name {prompt.name} not found."
)
# Code Change
# If changes are made to user prompt and system prompt
if (existing_prompt.system != prompt.system or existing_prompt.user != prompt.user):
existing_prompt.system = prompt.system
existing_prompt.user = prompt.user
existing_prompt.active = prompt.active
existing_prompt.version += 1
# If no changes made to user prompt and system prompt
else:
# This case happens when we click on the Activate Prompt, which inturn calls the update_prompt
existing_prompt.active = prompt.active
# Code Change
session.commit()
So when we click on the Activate Prompt
in the UI, it inturn calls the update_prompt
of the SQLiteBackend
. As there are no changes made in the user prompt and system prompt, we just update the active
variable
Fixed with the latest release 0.1.2.
Here are the results from the database when I changed the prompt (user) three times
I have checked the
sqlite_backend.py
'supdate_prompt()
function ofSQLiteBackend
class. Here's the codestorage/sqlite_backend.py - line 116
Here, we are updating from the previous system and user prompt to the new system and user prompt. But nowhere we are increasing the version number by 1 (which was present in the previous code)
Here's the solution (just add a single line)
After doing this, here's the result from the database when a prompt update is performed in the UI
Opening a PR for the same