mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-14 17:03:29 +03:00
fix(prompts): can now be removed (#2154)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
b6571d6ea9
commit
11f76f4e75
@ -137,17 +137,21 @@ async def update_existing_brain(
|
||||
if existing_brain is None:
|
||||
raise HTTPException(status_code=404, detail="Brain not found")
|
||||
|
||||
brain_service.update_brain_by_id(brain_id, brain_update_data)
|
||||
|
||||
if brain_update_data.prompt_id is None and existing_brain.prompt_id:
|
||||
prompt = prompt_service.get_prompt_by_id(existing_brain.prompt_id)
|
||||
if prompt and prompt.status == "private":
|
||||
prompt_service.delete_prompt_by_id(existing_brain.prompt_id)
|
||||
|
||||
if brain_update_data.status == "private" and existing_brain.status == "public":
|
||||
brain_user_service.delete_brain_users(brain_id)
|
||||
return {"message": f"Prompt {brain_id} has been updated."}
|
||||
|
||||
return {"message": f"Brain {brain_id} has been updated."}
|
||||
elif brain_update_data.status == "private" and existing_brain.status == "public":
|
||||
brain_user_service.delete_brain_users(brain_id)
|
||||
return {"message": f"Brain {brain_id} has been deleted."}
|
||||
|
||||
else:
|
||||
brain_service.update_brain_by_id(brain_id, brain_update_data)
|
||||
|
||||
return {"message": f"Brain {brain_id} has been updated."}
|
||||
|
||||
|
||||
@brain_router.put(
|
||||
|
@ -268,7 +268,6 @@ class BrainService:
|
||||
status_code=404,
|
||||
detail=f"Brain with id {brain_id} not found",
|
||||
)
|
||||
|
||||
brain_update_answer = self.brain_repository.update_brain_by_id(
|
||||
brain_id,
|
||||
brain=BrainUpdatableProperties(
|
||||
|
@ -1,10 +1,10 @@
|
||||
from fastapi import HTTPException
|
||||
from models.settings import get_supabase_client
|
||||
from modules.prompt.entity.prompt import Prompt
|
||||
from modules.prompt.repository.prompts_interface import (
|
||||
DeletePromptResponse,
|
||||
PromptsInterface,
|
||||
)
|
||||
from models.settings import get_supabase_client
|
||||
|
||||
|
||||
class Prompts(PromptsInterface):
|
||||
@ -30,6 +30,18 @@ class Prompts(PromptsInterface):
|
||||
Returns:
|
||||
A dictionary containing the status of the delete and prompt_id of the deleted prompt
|
||||
"""
|
||||
|
||||
# Update brains where prompt_id is equal to the value to NULL
|
||||
self.db.from_("brains").update({"prompt_id": None}).filter(
|
||||
"prompt_id", "eq", prompt_id
|
||||
).execute()
|
||||
|
||||
# Update chat_history where prompt_id is equal to the value to NULL
|
||||
self.db.from_("chat_history").update({"prompt_id": None}).filter(
|
||||
"prompt_id", "eq", prompt_id
|
||||
).execute()
|
||||
|
||||
# Delete the prompt
|
||||
response = (
|
||||
self.db.from_("prompts")
|
||||
.delete()
|
||||
|
Loading…
Reference in New Issue
Block a user