forked from cohere-ai/cohere-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] adding tools for agents, filter tools by agent_id (cohere-a…
…i#204) * changes * lint * filter tools by agent * lint * update tests * lint and squash migrations * fix alembic migration err * lint
- Loading branch information
1 parent
1bd58fe
commit 53f587a
Showing
10 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""empty message | ||
Revision ID: 922e874930bf | ||
Revises: 28763d200b29 | ||
Create Date: 2024-06-12 21:19:12.204875 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "922e874930bf" | ||
down_revision: Union[str, None] = "28763d200b29" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"agents", | ||
sa.Column( | ||
"tools", | ||
postgresql.ARRAY( | ||
sa.Enum( | ||
"Wiki_Retriever_LangChain", | ||
"Search_File", | ||
"Read_File", | ||
"Python_Interpreter", | ||
"Calculator", | ||
"Tavily_Internet_Search", | ||
name="toolname", | ||
native_enum=False, | ||
) | ||
), | ||
nullable=False, | ||
), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("agents", "tools") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
from fastapi import APIRouter | ||
from typing import Optional | ||
|
||
from fastapi import APIRouter, HTTPException | ||
|
||
from backend.config.routers import RouterName | ||
from backend.config.tools import AVAILABLE_TOOLS | ||
from backend.crud import agent as agent_crud | ||
from backend.database_models.database import DBSessionDep | ||
from backend.schemas.tool import ManagedTool | ||
|
||
router = APIRouter(prefix="/v1/tools") | ||
router.name = RouterName.TOOL | ||
|
||
|
||
@router.get("", response_model=list[ManagedTool]) | ||
def list_tools() -> list[ManagedTool]: | ||
def list_tools(session: DBSessionDep, agent_id: str | None = None) -> list[ManagedTool]: | ||
""" | ||
List all available tools. | ||
Returns: | ||
list[ManagedTool]: List of available tools. | ||
""" | ||
if agent_id: | ||
agent_tools = [] | ||
agent = agent_crud.get_agent(session, agent_id) | ||
|
||
if not agent: | ||
raise HTTPException( | ||
status_code=404, | ||
detail=f"Agent with ID: {agent_id} not found.", | ||
) | ||
|
||
for tool in agent.tools: | ||
agent_tools.append(AVAILABLE_TOOLS[tool]) | ||
return agent_tools | ||
|
||
return AVAILABLE_TOOLS.values() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters