Skip to content

Commit

Permalink
fix (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihiragarwal24 committed Aug 18, 2023
1 parent 10abe9e commit 303a65b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions superagi/controllers/api/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_agent_with_config(agent_with_config: AgentConfigExtInput,
api_key: str = Security(validate_api_key), organisation:Organisation = Depends(get_organisation_from_api_key)):
project=Project.find_by_org_id(db.session, organisation.id)
try:
tools_arr=Toolkit.get_tool_and_toolkit_arr(db.session,agent_with_config.tools)
tools_arr=Toolkit.get_tool_and_toolkit_arr(db.session,organisation.id,agent_with_config.tools)
except Exception as e:
raise HTTPException(status_code=404, detail=str(e))

Expand Down Expand Up @@ -177,7 +177,7 @@ def update_agent(agent_id: int, agent_with_config: AgentConfigUpdateExtInput,api
raise HTTPException(status_code=409, detail="Agent is already scheduled,cannot update")

try:
tools_arr=Toolkit.get_tool_and_toolkit_arr(db.session,agent_with_config.tools)
tools_arr=Toolkit.get_tool_and_toolkit_arr(db.session,organisation.id,agent_with_config.tools)
except Exception as e:
raise HTTPException(status_code=404,detail=str(e))

Expand Down
4 changes: 2 additions & 2 deletions superagi/models/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ def fetch_tool_ids_from_toolkit(cls, session, toolkit_ids):
return agent_toolkit_tools

@classmethod
def get_tool_and_toolkit_arr(cls, session, agent_config_tools_arr: list):
def get_tool_and_toolkit_arr(cls, session, organisation_id :int,agent_config_tools_arr: list):
from superagi.models.tool import Tool
toolkits_arr= set()
tools_arr= set()
for tool_obj in agent_config_tools_arr:
toolkit=session.query(Toolkit).filter(Toolkit.name == tool_obj["name"].strip()).first()
toolkit=session.query(Toolkit).filter(Toolkit.name == tool_obj["name"].strip(), Toolkit.organisation_id == organisation_id).first()
if toolkit is None:
raise Exception("One or more of the Tool(s)/Toolkit(s) does not exist.")
toolkits_arr.add(toolkit.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/models/test_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_get_tool_and_toolkit_arr_with_nonexistent_toolkit():

# Use a context manager to capture the raised exception and its message
with pytest.raises(Exception) as exc_info:
Toolkit.get_tool_and_toolkit_arr(session, agent_config_tools_arr)
Toolkit.get_tool_and_toolkit_arr(session,1, agent_config_tools_arr)

# Assert that the expected error message is contained within the raised exception message
expected_error_message = "One or more of the Tool(s)/Toolkit(s) does not exist."
Expand Down

0 comments on commit 303a65b

Please sign in to comment.