Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

create model/pipeline tools from AgentFactory #214

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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
23 changes: 23 additions & 0 deletions aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import json
import logging

from aixplain.enums.function import Function
from aixplain.enums.supplier import Supplier
from aixplain.modules.agent import Agent, Tool
from aixplain.modules.agent.tool.model_tool import ModelTool
from aixplain.modules.agent.tool.pipeline_tool import PipelineTool
from aixplain.modules.pipeline import Pipeline
from aixplain.utils import config
from typing import Dict, List, Optional, Text, Union

Expand Down Expand Up @@ -113,6 +115,27 @@ def create(
raise Exception(e)
return agent

@classmethod
def create_model_tool(cls, function: Union[Function, Text], supplier: Optional[Union[Supplier, Text]] = None) -> ModelTool:
"""Create a new model tool."""
if isinstance(function, str):
function = Function(function)

if supplier is not None:
if isinstance(supplier, str):
for supplier_ in Supplier:
if supplier.lower() in [supplier.value["code"].lower(), supplier.value["name"].lower()]:
supplier = supplier_
break
if isinstance(supplier, str):
supplier = None
return ModelTool(function=function, supplier=supplier)

@classmethod
def create_pipeline_tool(cls, description: Text, pipeline: Union[Pipeline, Text]) -> PipelineTool:
"""Create a new pipeline tool."""
return PipelineTool(description=description, pipeline=pipeline)

@classmethod
def list(cls) -> Dict:
"""List all agents available in the platform."""
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/agent/agent_functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

load_dotenv()
from aixplain.factories import AgentFactory
from aixplain.modules.agent import ModelTool, PipelineTool
from aixplain.enums.supplier import Supplier

import pytest
Expand Down Expand Up @@ -48,10 +47,10 @@ def test_end2end(run_input_map):
]:
tool["supplier"] = supplier
break
tools.append(ModelTool(function=tool["function"], supplier=tool["supplier"]))
tools.append(AgentFactory.create_model_tool(function=tool["function"], supplier=tool["supplier"]))
if "pipeline_tools" in run_input_map:
for tool in run_input_map["pipeline_tools"]:
tools.append(PipelineTool(description=tool["description"], pipeline=tool["pipeline_id"]))
tools.append(AgentFactory.create_pipeline_tool(pipeline=tool["pipeline_id"], description=tool["description"]))
print(f"Creating agent with tools: {tools}")
agent = AgentFactory.create(name=run_input_map["agent_name"], llm_id=run_input_map["llm_id"], tools=tools)
print(f"Agent created: {agent.__dict__}")
Expand Down