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

fix #1085

Merged
merged 1 commit into from
Aug 18, 2023
Merged

fix #1085

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
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