Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete flow permissions #633

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions llm-server/models/repository/flow_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ def add_or_update_variable_in_flow(
session.add(variable)
session.commit()
return variable


def delete_flow(flow_id: str) -> bool:
"""
Deletes a flow record from the database.
Args:
flow_id: The ID of the flow to delete.
Returns:
True if the flow was deleted, False otherwise.
"""
with Session() as session:
flow = session.query(Flow).filter(Flow.id == flow_id).first()
if flow:
session.delete(flow)
session.commit()
return True
return False
2 changes: 1 addition & 1 deletion llm-server/routes/copilot/copilot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def delete_bot(copilot_id):
# Find the bot
bot = find_or_fail_by_bot_id(copilot_id)

# Delete the bot using the session
# This should be soft delete but for now, we are doing hard delete
session.delete(bot)
session.commit()
return jsonify({"success": "chatbot_deleted"}), 200
Expand Down
30 changes: 30 additions & 0 deletions llm-server/routes/flow/flow_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
get_variables_for_flow,
add_or_update_variable_in_flow,
update_flow,
delete_flow as delete_flow_from_db,
)
from presenters.flow_presenters import flow_to_dict, flow_variable_to_dict
from routes.flow import flow_vector_service
from routes.flow.utils.dynamic_flow_builder import build_dynamic_flow
from utils.get_logger import CustomLogger
from routes.flow.flow_vector_service import delete_flow as delete_flow_from_vector_store

logger = CustomLogger("flow")
flow = Blueprint("flow", __name__)
Expand Down Expand Up @@ -249,3 +251,31 @@ def add_variables_to_flow_api(flow_id: str):
),
500,
)


@flow.route("/<flow_id>", methods=["DELETE"])
def delete_flow_api(flow_id: str):
try:
# Attempt to delete the flow from the database
if delete_flow_from_db(flow_id):
# Attempt to delete the flow from the vector store
point_id = flow_vector_service.get_flow_point_id_by_flow_id(flow_id)
if point_id:
delete_flow_from_vector_store(point_id)
return (
jsonify({"success": True, "message": "Flow deleted successfully."}),
200,
)
else:
return (
jsonify({"success": False, "message": "Flow vector not found."}),
404,
)
else:
return (
jsonify({"success": False, "message": "Flow not found in database."}),
404,
)
except Exception as e:
logger.error("Failed to delete flow", payload=e)
return jsonify({"error": "Failed to delete flow."}), 500
12 changes: 7 additions & 5 deletions llm-server/routes/flow/flow_vector_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def create_flow(flow: FlowDTO):
documents: List[Document] = []

document = Document(page_content=flow.description + " " + flow.name)
document.metadata.update({
"bot_id": str(flow.bot_id),
"flow_id": str(flow.id),
"operation_id": flow.operation_id
})
document.metadata.update(
{
"bot_id": str(flow.bot_id),
"flow_id": str(flow.id),
"operation_id": flow.operation_id,
}
)

documents.append(document)

Expand Down
Loading