Skip to content
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
12 changes: 5 additions & 7 deletions ai21/clients/common/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from ai21.models.agents.agent import ResponseLanguage
from ai21.types import NOT_GIVEN, NotGiven
from ai21.utils.typing import remove_not_given
from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs


class BaseAgents(ABC):
Expand All @@ -26,19 +26,19 @@ def _create_body(
description: str | NotGiven,
models: List[str] | NotGiven,
tools: List[Dict[str, Any]] | NotGiven,
tool_resources: Dict[str, Any] | NotGiven,
requirements: List[AgentRequirement] | NotGiven,
budget: BudgetLevel | NotGiven,
response_language: ResponseLanguage | NotGiven,
**kwargs,
) -> dict:
warn_if_tool_resources_in_kwargs(kwargs)

return remove_not_given(
{
"name": name,
"description": description,
"models": models,
"tools": tools,
"tool_resources": tool_resources,
"requirements": requirements,
"budget": budget,
"response_language": response_language,
Expand All @@ -53,20 +53,20 @@ def _modify_body(
description: str | NotGiven,
models: List[str] | NotGiven,
tools: List[Dict[str, Any]] | NotGiven,
tool_resources: Dict[str, Any] | NotGiven,
requirements: List[AgentRequirement] | NotGiven,
budget: BudgetLevel | NotGiven,
visibility: Visibility | NotGiven,
response_language: ResponseLanguage | NotGiven,
**kwargs,
) -> dict:
warn_if_tool_resources_in_kwargs(kwargs)

return remove_not_given(
{
"name": name,
"description": description,
"models": models,
"tools": tools,
"tool_resources": tool_resources,
"requirements": requirements,
"budget": budget,
"visibility": visibility,
Expand All @@ -85,7 +85,6 @@ def create(
avatar: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
response_language: ResponseLanguage | NotGiven = NOT_GIVEN,
Expand All @@ -110,7 +109,6 @@ def modify(
description: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
visibility: Visibility | NotGiven = NOT_GIVEN,
Expand Down
5 changes: 3 additions & 2 deletions ai21/clients/common/agents/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ai21.models.agents import Agent
from ai21.models.agents.agent import AgentRequirement
from ai21.models.maestro.run import Requirement
from ai21.utils.typing import remove_not_given
from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs


class BaseAgentRun(ABC):
Expand All @@ -31,11 +31,12 @@ def convert_agent_to_maestro_run_payload(
agent: Agent,
**kwargs,
):
warn_if_tool_resources_in_kwargs(kwargs)

return remove_not_given(
{
"models": agent.models,
"tools": agent.tools,
"tool_resources": agent.tool_resources,
"requirements": self._convert_requirements(agent.requirements),
"budget": agent.budget,
"response_language": agent.response_language,
Expand Down
9 changes: 3 additions & 6 deletions ai21/clients/common/maestro/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
OutputOptions,
Requirement,
RunResponse,
ToolResources,
ToolDefinition,
)
from ai21.types import NOT_GIVEN, NotGiven
from ai21.utils.typing import remove_not_given
from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs


class BaseMaestroRun(ABC):
Expand All @@ -27,19 +26,19 @@ def _create_body(
input: str | List[MaestroMessage],
models: List[str] | NotGiven,
tools: List[ToolDefinition] | NotGiven,
tool_resources: ToolResources | NotGiven,
requirements: List[Requirement] | NotGiven,
budget: Budget | NotGiven,
include: List[OutputOptions] | NotGiven,
response_language: str | NotGiven,
**kwargs,
) -> dict:
warn_if_tool_resources_in_kwargs(kwargs)

return remove_not_given(
{
"input": input,
"models": models,
"tools": tools,
"tool_resources": tool_resources,
"requirements": requirements,
"budget": budget,
"include": include,
Expand All @@ -55,7 +54,6 @@ def create(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand All @@ -79,7 +77,6 @@ def create_and_poll(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand Down
4 changes: 0 additions & 4 deletions ai21/clients/studio/resources/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def create(
description: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
response_language: ResponseLanguage | NotGiven = NOT_GIVEN,
Expand All @@ -95,7 +94,6 @@ def create(
description=description,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
response_language=response_language,
Expand All @@ -120,7 +118,6 @@ def modify(
description: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
visibility: Visibility | NotGiven = NOT_GIVEN,
Expand All @@ -134,7 +131,6 @@ def modify(
response_language=response_language,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
visibility=visibility,
Expand Down
4 changes: 0 additions & 4 deletions ai21/clients/studio/resources/agents/async_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async def create(
avatar: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
response_language: ResponseLanguage | NotGiven = NOT_GIVEN,
Expand All @@ -103,7 +102,6 @@ async def create(
avatar=avatar,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
response_language=response_language,
Expand All @@ -128,7 +126,6 @@ async def modify(
description: str | NotGiven = NOT_GIVEN,
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN,
tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN,
requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN,
budget: BudgetLevel | NotGiven = NOT_GIVEN,
visibility: Visibility | NotGiven = NOT_GIVEN,
Expand All @@ -141,7 +138,6 @@ async def modify(
description=description,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
visibility=visibility,
Expand Down
9 changes: 0 additions & 9 deletions ai21/clients/studio/resources/maestro/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Requirement,
RunResponse,
TERMINATED_RUN_STATUSES,
ToolResources,
ToolDefinition,
)
from ai21.types import NotGiven, NOT_GIVEN
Expand All @@ -28,7 +27,6 @@ def create(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand All @@ -39,7 +37,6 @@ def create(
input=input,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
include=include,
Expand Down Expand Up @@ -75,7 +72,6 @@ def create_and_poll(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand All @@ -88,7 +84,6 @@ def create_and_poll(
input=input,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
include=include,
Expand All @@ -108,7 +103,6 @@ async def create(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand All @@ -119,7 +113,6 @@ async def create(
input=input,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
include=include,
Expand Down Expand Up @@ -155,7 +148,6 @@ async def create_and_poll(
input: str | List[MaestroMessage],
models: List[str] | NotGiven = NOT_GIVEN,
tools: List[ToolDefinition] | NotGiven = NOT_GIVEN,
tool_resources: ToolResources | NotGiven = NOT_GIVEN,
requirements: List[Requirement] | NotGiven = NOT_GIVEN,
budget: Budget | NotGiven = NOT_GIVEN,
include: List[OutputOptions] | NotGiven = NOT_GIVEN,
Expand All @@ -168,7 +160,6 @@ async def create_and_poll(
input=input,
models=models,
tools=tools,
tool_resources=tool_resources,
requirements=requirements,
budget=budget,
include=include,
Expand Down
3 changes: 1 addition & 2 deletions ai21/models/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Optional

from ai21.models.ai21_base_model import AI21BaseModel
from ai21.models.maestro.run import Budget, ToolDefinition, ToolResources
from ai21.models.maestro.run import Budget, ToolDefinition


class BudgetLevel(str, Enum):
Expand Down Expand Up @@ -54,7 +54,6 @@ class Agent(AI21BaseModel):
user_id: str
models: Optional[List[str]] = None
tools: Optional[List[ToolDefinition]] = None
tool_resources: Optional[ToolResources] = None
requirements: Optional[List[AgentRequirement]] = None
budget: Optional[Budget] = None
visibility: Optional[Visibility] = None
Expand Down
2 changes: 0 additions & 2 deletions ai21/models/maestro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
OutputOptions,
Requirement,
ToolDefinition,
ToolResources,
WebSearchResult,
HttpTool,
McpTool,
Expand All @@ -23,7 +22,6 @@
"OutputOptions",
"Requirement",
"ToolDefinition",
"ToolResources",
"WebSearchResult",
"HttpTool",
"McpTool",
Expand Down
5 changes: 0 additions & 5 deletions ai21/models/maestro/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ class WebSearch(TypedDict, total=False):
use_cached_pages: Optional[bool]


class ToolResources(TypedDict, total=False):
file_search: Optional[FileSearch]
web_search: Optional[WebSearch]


ToolDefinition = Annotated[
Union[
HttpTool,
Expand Down
11 changes: 11 additions & 0 deletions ai21/utils/typing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any, Dict, get_args, cast

from ai21.types import NotGiven
Expand Down Expand Up @@ -30,3 +31,13 @@ def extract_type(type_to_extract: Any) -> type:
raise RuntimeError(
f"Expected type {type_to_extract} to have a type argument at index 0 but it did not"
) from err


def warn_if_tool_resources_in_kwargs(kwargs: Dict[str, Any], stacklevel: int = 3) -> None:
if "tool_resources" in kwargs:
warnings.warn(
"The 'tool_resources' parameter is deprecated and will be removed in a future version. "
"Use the 'tools' parameter instead.",
DeprecationWarning,
stacklevel=stacklevel,
)
Loading