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

Code docs #409

Merged
merged 25 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f157bed
gpt-3.5 16k support
luciferlinx101 Jun 15, 2023
a479e06
Merge pull request #385 from TransformerOptimus/new-open-ai-16k-model…
Jun 15, 2023
c83794f
Adding Comments in code
luciferlinx101 Jun 17, 2023
948a8f3
docs for auth.py
Fluder-Paradyne Jun 17, 2023
f47ef4a
docs for encrption_helper.py
Fluder-Paradyne Jun 17, 2023
1b18189
Updated Comments in APIs
luciferlinx101 Jun 17, 2023
86eea8b
Merge branch 'code-docs' of github.com:TransformerOptimus/SuperAGI in…
luciferlinx101 Jun 17, 2023
c04e5f1
docs for github_helper.py
Fluder-Paradyne Jun 17, 2023
ffeddbc
Merge remote-tracking branch 'origin/code-docs' into code-docs
Fluder-Paradyne Jun 17, 2023
78208d3
docs for helper
Fluder-Paradyne Jun 17, 2023
cd7a9ff
removed unused imports and comments
Fluder-Paradyne Jun 17, 2023
b60e9a8
docs openai llm
Fluder-Paradyne Jun 17, 2023
c2daf93
Added more comments
luciferlinx101 Jun 17, 2023
a083a98
Merge branch 'code-docs' of github.com:TransformerOptimus/SuperAGI in…
luciferlinx101 Jun 17, 2023
a6deca2
docs on tools
Fluder-Paradyne Jun 17, 2023
4534fa8
docs on tools
Fluder-Paradyne Jun 17, 2023
b176f39
Updated documentation for APIs and Models
luciferlinx101 Jun 17, 2023
0f77a82
Merge branch 'code-docs' of github.com:TransformerOptimus/SuperAGI in…
luciferlinx101 Jun 17, 2023
fffbbac
Added more models
luciferlinx101 Jun 17, 2023
462b859
Updated some more model docs
luciferlinx101 Jun 17, 2023
302e43f
Added Docs to all APIs and Models
luciferlinx101 Jun 17, 2023
15f6df3
docs on tools
Fluder-Paradyne Jun 17, 2023
70d3529
Merge remote-tracking branch 'origin/code-docs' into code-docs
Fluder-Paradyne Jun 17, 2023
d45c4d9
dev merge
Fluder-Paradyne Jun 17, 2023
8512bec
vector store
Fluder-Paradyne Jun 17, 2023
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
2 changes: 1 addition & 1 deletion gui/pages/Content/Agents/AgentCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function AgentCreate({sendAgentData, selectedProjectId, fetchAgen

const [goals, setGoals] = useState(['Describe the agent goals here']);

const models = ['gpt-4', 'gpt-3.5-turbo']
const models = ['gpt-4', 'gpt-3.5-turbo','gpt-3.5-turbo-16k']
const [model, setModel] = useState(models[1]);
const modelRef = useRef(null);
const [modelDropdown, setModelDropdown] = useState(false);
Expand Down
113 changes: 102 additions & 11 deletions superagi/controllers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@
@router.post("/add", response_model=sqlalchemy_to_pydantic(Agent), status_code=201)
def create_agent(agent: sqlalchemy_to_pydantic(Agent, exclude=["id"]),
Authorize: AuthJWT = Depends(check_auth)):
"""Create agent new agent"""
"""
Creates a new Agent

Args:
agent (Agent): An object representing the Agent to be created.
Contains the following attributes:
- name (str): Name of the Agent
- project_id (int): Identifier of the associated project
- description (str): Description of the Agent
- agent_workflow_id (int): Identifier of the Agent Workflow in use

Returns:
Agent: An object of Agent representing the created Agent.

Raises:
HTTPException (Status Code=404): If the associated project is not found.
"""

project = db.session.query(Project).get(agent.project_id)

Expand All @@ -44,7 +60,18 @@ def create_agent(agent: sqlalchemy_to_pydantic(Agent, exclude=["id"]),
@router.get("/get/{agent_id}", response_model=sqlalchemy_to_pydantic(Agent))
def get_agent(agent_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get particular agent by agent_id"""
"""
Get an Agent by ID

Args:
agent_id (int): Identifier of the Agent to retrieve

Returns:
Agent: An object of Agent representing the retrieved Agent.

Raises:
HTTPException (Status Code=404): If the Agent is not found.
"""

db_agent = db.session.query(Agent).filter(Agent.id == agent_id).first()
if not db_agent:
Expand All @@ -55,7 +82,24 @@ def get_agent(agent_id: int,
@router.put("/update/{agent_id}", response_model=sqlalchemy_to_pydantic(Agent))
def update_agent(agent_id: int, agent: sqlalchemy_to_pydantic(Agent, exclude=["id"]),
Authorize: AuthJWT = Depends(check_auth)):
"""Update agent by agent_id"""
"""
Update an existing Agent

Args:
agent_id (int): Identifier of the Agent to update
agent (Agent): Updated Agent data
Contains the following attributes:
- name (str): Name of the Agent
- project_id (int): Identifier of the associated project
- description (str): Description of the Agent
- agent_workflow_id (int): Identifier of the Agent Workflow in use

Returns:
Agent: An object of Agent representing the updated Agent.

Raises:
HTTPException (Status Code=404): If the Agent or associated Project is not found.
"""

db_agent = db.session.query(Agent).filter(Agent.id == agent_id).first()
if not db_agent:
Expand All @@ -76,7 +120,32 @@ def update_agent(agent_id: int, agent: sqlalchemy_to_pydantic(Agent, exclude=["i
@router.post("/create", status_code=201)
def create_agent_with_config(agent_with_config: AgentWithConfig,
Authorize: AuthJWT = Depends(check_auth)):
"""Create new agent with configurations"""
"""
Create a new agent with configurations.

Args:
agent_with_config (AgentWithConfig): Data for creating a new agent with configurations.
- name (str): Name of the agent.
- project_id (int): Identifier of the associated project.
- description (str): Description of the agent.
- goal (List[str]): List of goals for the agent.
- agent_type (str): Type of the agent.
- constraints (List[str]): List of constraints for the agent.
- tools (List[int]): List of tool identifiers associated with the agent.
- exit (str): Exit condition for the agent.
- iteration_interval (int): Interval between iterations for the agent.
- model (str): Model information for the agent.
- permission_type (str): Permission type for the agent.
- LTM_DB (str): LTM database for the agent.
- memory_window (int): Memory window size for the agent.
- max_iterations (int): Maximum number of iterations for the agent.

Returns:
dict: Dictionary containing the created agent's ID, execution ID, name, and content type.

Raises:
HTTPException (status_code=404): If the associated project or any of the tools is not found.
"""

# Checking for project
project = db.session.query(Project).get(agent_with_config.project_id)
Expand Down Expand Up @@ -105,10 +174,23 @@ def create_agent_with_config(agent_with_config: AgentWithConfig,
"contentType": "Agents"
}


@router.get("/get/project/{project_id}")
def get_agents_by_project_id(project_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get all agents by project_id"""
"""
Get all agents by project ID.

Args:
project_id (int): Identifier of the project.
Authorize (AuthJWT, optional): Authorization dependency. Defaults to Depends(check_auth).

Returns:
list: List of agents associated with the project, including their status.

Raises:
HTTPException (status_code=404): If the project is not found.
"""

# Checking for project
project = db.session.query(Project).get(project_id)
Expand Down Expand Up @@ -140,14 +222,26 @@ def get_agents_by_project_id(project_id: int,
@router.get("/get/details/{agent_id}")
def get_agent_configuration(agent_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get agent using agent_id with all its configuration"""
"""
Get the agent configuration using the agent ID.

Args:
agent_id (int): Identifier of the agent.
Authorize (AuthJWT, optional): Authorization dependency. Defaults to Depends(check_auth).

Returns:
dict: Agent configuration including its details.

Raises:
HTTPException (status_code=404): If the agent is not found.
"""

# Define the agent_config keys to fetch
keys_to_fetch = AgentTemplate.main_keys()
agent = db.session.query(Agent).filter(agent_id == Agent.id).first()

if not agent:
raise HTTPException(status_code=400, detail="Agent not found")
raise HTTPException(status_code=404, detail="Agent not found")

# Query the AgentConfiguration table for the specified keys
results = db.session.query(AgentConfiguration).filter(AgentConfiguration.key.in_(keys_to_fetch),
Expand All @@ -166,12 +260,9 @@ def get_agent_configuration(agent_id: int,
"constraints": eval(response["constraints"]),
"tools": [int(x) for x in json.loads(response["tools"])]})
tools = db.session.query(Tool).filter(Tool.id.in_(response["tools"])).all()
# print(tools)
response["tools"] = tools
# executions = db.session.query(AgentExecution).filter(AgentExecution.agent_id == agent_id).all()
# response["executions"] = executions

# Close the session
db.session.close()

return response
return response
71 changes: 56 additions & 15 deletions superagi/controllers/agent_config.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
from fastapi_sqlalchemy import db
from fastapi import HTTPException, Depends, Request
from fastapi_jwt_auth import AuthJWT
from superagi.models.agent import Agent
from superagi.models.types.agent_config import AgentConfig
from superagi.models.agent_config import AgentConfiguration
from fastapi import APIRouter
from fastapi import HTTPException, Depends
from fastapi_jwt_auth import AuthJWT
from fastapi_sqlalchemy import db
from pydantic_sqlalchemy import sqlalchemy_to_pydantic
from superagi.helper.auth import check_auth
from fastapi_jwt_auth import AuthJWT


from superagi.models.agent import Agent
from superagi.models.agent_config import AgentConfiguration
from superagi.models.types.agent_config import AgentConfig

router = APIRouter()


# CRUD Operations
@router.post("/add", response_model=sqlalchemy_to_pydantic(AgentConfiguration), status_code=201)
def create_agent_config(agent_config: sqlalchemy_to_pydantic(AgentConfiguration, exclude=["id"],),
Authorize: AuthJWT = Depends(check_auth)):
"""Create new agent configuration by setting new key and value related to agent"""
def create_agent_config(agent_config: sqlalchemy_to_pydantic(AgentConfiguration, exclude=["id"], ),
Authorize: AuthJWT = Depends(check_auth)):
"""
Create a new agent configuration by setting a new key and value related to the agent.

Args:
agent_config (AgentConfiguration): The agent configuration data.

Returns:
AgentConfiguration: The created agent configuration.

Raises:
HTTPException (Status Code=404): If the associated agent is not found.
"""

agent = db.session.query(Agent).get(agent_config.agent_id)

Expand All @@ -34,7 +42,18 @@ def create_agent_config(agent_config: sqlalchemy_to_pydantic(AgentConfiguration,
@router.get("/get/{agent_config_id}", response_model=sqlalchemy_to_pydantic(AgentConfiguration))
def get_agent(agent_config_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get a particular agent configuration by agent_config_id"""
"""
Get a particular agent configuration by agent_config_id.

Args:
agent_config_id (int): The identifier of the agent configuration.

Returns:
AgentConfiguration: The retrieved agent configuration.

Raises:
HTTPException (Status Code=404): If the agent configuration is not found.
"""

db_agent_config = db.session.query(AgentConfiguration).filter(AgentConfiguration.id == agent_config_id).first()
if not db_agent_config:
Expand All @@ -45,7 +64,18 @@ def get_agent(agent_config_id: int,
@router.put("/update", response_model=sqlalchemy_to_pydantic(AgentConfiguration))
def update_agent(agent_config: AgentConfig,
Authorize: AuthJWT = Depends(check_auth)):
"""Update a particular agent configuration value for given agent_id and agent_config key"""
"""
Update a particular agent configuration value for the given agent_id and agent_config key.

Args:
agent_config (AgentConfig): The updated agent configuration data.

Returns:
AgentConfiguration: The updated agent configuration.

Raises:
HTTPException (Status Code=404): If the agent configuration is not found.
"""

db_agent_config = db.session.query(AgentConfiguration).filter(AgentConfiguration.key == agent_config.key,
AgentConfiguration.agent_id == agent_config.agent_id).first()
Expand All @@ -66,7 +96,18 @@ def update_agent(agent_config: AgentConfig,
@router.get("/get/agent/{agent_id}")
def get_agent_configurations(agent_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get all agent configurations for a given agent_id"""
"""
Get all agent configurations for a given agent_id.

Args:
agent_id (int): The identifier of the agent.

Returns:
dict: The parsed response containing agent configurations.

Raises:
HTTPException (Status Code=404): If the agent or agent configurations are not found.
"""

agent = db.session.query(Agent).filter(Agent.id == agent_id).first()
if not agent:
Expand Down
26 changes: 24 additions & 2 deletions superagi/controllers/agent_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@
@router.post("/add", response_model=sqlalchemy_to_pydantic(AgentExecution), status_code=201)
def create_agent_execution(agent_execution: sqlalchemy_to_pydantic(AgentExecution, exclude=["id"]),
Authorize: AuthJWT = Depends(check_auth)):
"""Create a new agent execution/run"""
"""
Create a new agent execution/run.

Args:
agent_execution (AgentExecution): The agent execution data.

Returns:
AgentExecution: The created agent execution.

Raises:
HTTPException (Status Code=404): If the agent is not found.
"""

agent = db.session.query(Agent).get(agent_execution.agent_id)

Expand All @@ -41,7 +52,18 @@ def create_agent_execution(agent_execution: sqlalchemy_to_pydantic(AgentExecutio
@router.get("/get/{agent_execution_id}", response_model=sqlalchemy_to_pydantic(AgentExecution))
def get_agent_execution(agent_execution_id: int,
Authorize: AuthJWT = Depends(check_auth)):
"""Get a agent execution by agent_execution_id"""
"""
Get an agent execution by agent_execution_id.

Args:
agent_execution_id (int): The ID of the agent execution.

Returns:
AgentExecution: The requested agent execution.

Raises:
HTTPException (Status Code=404): If the agent execution is not found.
"""

db_agent_execution = db.session.query(AgentExecution).filter(AgentExecution.id == agent_execution_id).first()
if not db_agent_execution:
Expand Down
Loading