Skip to content

Commit

Permalink
Merge pull request #510 from openchatai/feat/delete-global-var
Browse files Browse the repository at this point in the history
Handle Delete Global variable by name
  • Loading branch information
codebanesr authored Jan 9, 2024
2 parents 74fc64e + 6a12577 commit 53c078b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions llm-server/models/repository/copilot_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import uuid
from typing import Iterable, List, Optional, Any
from flask import jsonify

from sqlalchemy import exc
from sqlalchemy.orm import sessionmaker, Session
Expand Down Expand Up @@ -221,6 +222,22 @@ def chatbot_to_dict(chatbot: Chatbot):
"swagger_url": chatbot.swagger_url,
}

def delete_copilot_global_key(copilot_id: str, variable_key: str):
with SessionLocal() as session:
try:
copilot = find_one_or_fail_by_id(copilot_id)
vars_dict = deepcopy(dict(copilot.global_variables))

if (variable_key in vars_dict):
del vars_dict[variable_key]
copilot.global_variables = vars_dict
session.add(copilot)
session.commit()
session.refresh(copilot)
except Exception:
session.rollback()
raise ValueError(f"No Chatbot found with id: {copilot_id}")
return jsonify({"message": "JSON data stored successfully"})

def store_copilot_global_variables(copilot_id: str, new_variables: dict):
with SessionLocal() as session:
Expand Down
5 changes: 5 additions & 0 deletions llm-server/routes/copilot/copilot_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
import os
from http import HTTPStatus

Expand All @@ -6,6 +7,7 @@

from enums.initial_prompt import ChatBotInitialPromptEnum
from models.repository.copilot_repo import (
delete_copilot_global_key,
list_all_with_filter,
find_or_fail_by_bot_id,
find_one_or_fail_by_id,
Expand Down Expand Up @@ -141,6 +143,9 @@ def update_global_variables(copilot_id):
# Handle other exceptions
return jsonify({"error": "An error occurred", "details": str(e)}), 500

@copilot.route("/<string:copilot_id>/variable/<string:variable_key>", methods=["DELETE"])
def delete_global_variable(copilot_id:str, variable_key:str):
return delete_copilot_global_key(copilot_id=copilot_id, variable_key=variable_key)

@copilot.route("/<string:copilot_id>/variables", methods=["GET"])
def get_global_variables(copilot_id):
Expand Down

0 comments on commit 53c078b

Please sign in to comment.