Skip to content

Commit

Permalink
refactor(types): improve tool type names (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored Oct 7, 2024
1 parent 53e87e8 commit f6f3afe
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 88 deletions.
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ from anthropic.types import (
TextBlockParam,
TextDelta,
Tool,
ToolChoice,
ToolChoiceAny,
ToolChoiceAuto,
ToolChoiceTool,
ToolResultBlockParam,
ToolUseBlock,
ToolUseBlockParam,
Expand Down
17 changes: 9 additions & 8 deletions src/anthropic/resources/beta/prompt_caching/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ...._base_client import make_request_options
from ....lib.streaming import PromptCachingBetaMessageStreamManager, AsyncPromptCachingBetaMessageStreamManager
from ....types.model_param import ModelParam
from ....types.tool_choice_param import ToolChoiceParam
from ....types.beta.prompt_caching import message_create_params
from ....types.beta.prompt_caching.prompt_caching_beta_message import PromptCachingBetaMessage
from ....types.beta.prompt_caching.prompt_caching_beta_tool_param import PromptCachingBetaToolParam
Expand Down Expand Up @@ -68,7 +69,7 @@ def create(
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -331,7 +332,7 @@ def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -594,7 +595,7 @@ def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -857,7 +858,7 @@ def create(
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -990,7 +991,7 @@ async def create(
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1253,7 +1254,7 @@ async def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1516,7 +1517,7 @@ async def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1779,7 +1780,7 @@ async def create(
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[PromptCachingBetaToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down
21 changes: 11 additions & 10 deletions src/anthropic/resources/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ..types.model_param import ModelParam
from ..types.message_param import MessageParam
from ..types.text_block_param import TextBlockParam
from ..types.tool_choice_param import ToolChoiceParam
from ..types.raw_message_stream_event import RawMessageStreamEvent

__all__ = ["Messages", "AsyncMessages"]
Expand Down Expand Up @@ -76,7 +77,7 @@ def create(
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -339,7 +340,7 @@ def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -602,7 +603,7 @@ def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -865,7 +866,7 @@ def create(
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -925,7 +926,7 @@ def stream(
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
Expand Down Expand Up @@ -1008,7 +1009,7 @@ async def create(
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1271,7 +1272,7 @@ async def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1534,7 +1535,7 @@ async def create(
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1797,7 +1798,7 @@ async def create(
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1857,7 +1858,7 @@ def stream(
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
top_p: float | NotGiven = NOT_GIVEN,
tool_choice: message_create_params.ToolChoice | NotGiven = NOT_GIVEN,
tool_choice: ToolChoiceParam | NotGiven = NOT_GIVEN,
tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
Expand Down
4 changes: 4 additions & 0 deletions src/anthropic/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
from .input_json_delta import InputJSONDelta as InputJSONDelta
from .text_block_param import TextBlockParam as TextBlockParam
from .image_block_param import ImageBlockParam as ImageBlockParam
from .tool_choice_param import ToolChoiceParam as ToolChoiceParam
from .message_stop_event import MessageStopEvent as MessageStopEvent
from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent
from .message_delta_usage import MessageDeltaUsage as MessageDeltaUsage
from .message_start_event import MessageStartEvent as MessageStartEvent
from .message_stream_event import MessageStreamEvent as MessageStreamEvent
from .tool_use_block_param import ToolUseBlockParam as ToolUseBlockParam
from .message_create_params import MessageCreateParams as MessageCreateParams
from .tool_choice_any_param import ToolChoiceAnyParam as ToolChoiceAnyParam
from .raw_message_stop_event import RawMessageStopEvent as RawMessageStopEvent
from .tool_choice_auto_param import ToolChoiceAutoParam as ToolChoiceAutoParam
from .tool_choice_tool_param import ToolChoiceToolParam as ToolChoiceToolParam
from .raw_message_delta_event import RawMessageDeltaEvent as RawMessageDeltaEvent
from .raw_message_start_event import RawMessageStartEvent as RawMessageStartEvent
from .tool_result_block_param import ToolResultBlockParam as ToolResultBlockParam
Expand Down
48 changes: 13 additions & 35 deletions src/anthropic/types/beta/prompt_caching/message_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from typing_extensions import Literal, Required, TypeAlias, TypedDict

from ...model_param import ModelParam
from ...tool_choice_param import ToolChoiceParam
from ...tool_choice_any_param import ToolChoiceAnyParam
from ...tool_choice_auto_param import ToolChoiceAutoParam
from ...tool_choice_tool_param import ToolChoiceToolParam
from .prompt_caching_beta_tool_param import PromptCachingBetaToolParam
from .prompt_caching_beta_message_param import PromptCachingBetaMessageParam
from .prompt_caching_beta_text_block_param import PromptCachingBetaTextBlockParam
Expand Down Expand Up @@ -162,7 +166,7 @@ class MessageCreateParamsBase(TypedDict, total=False):
deterministic.
"""

tool_choice: ToolChoice
tool_choice: ToolChoiceParam
"""How the model should use the provided tools.
The model can use a specific tool, any available tool, or decide by itself.
Expand Down Expand Up @@ -272,43 +276,17 @@ class Metadata(TypedDict, total=False):
"""


class ToolChoiceToolChoiceAuto(TypedDict, total=False):
type: Required[Literal["auto"]]
ToolChoice: TypeAlias = ToolChoiceParam
"""This is deprecated, `ToolChoiceParam` should be used instead"""

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output at most one tool
use.
"""


class ToolChoiceToolChoiceAny(TypedDict, total=False):
type: Required[Literal["any"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output exactly one tool
use.
"""


class ToolChoiceToolChoiceTool(TypedDict, total=False):
name: Required[str]
"""The name of the tool to use."""

type: Required[Literal["tool"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output exactly one tool
use.
"""
ToolChoiceToolChoiceAuto: TypeAlias = ToolChoiceAutoParam
"""This is deprecated, `ToolChoiceAutoParam` should be used instead"""

ToolChoiceToolChoiceAny: TypeAlias = ToolChoiceAnyParam
"""This is deprecated, `ToolChoiceAnyParam` should be used instead"""

ToolChoice: TypeAlias = Union[ToolChoiceToolChoiceAuto, ToolChoiceToolChoiceAny, ToolChoiceToolChoiceTool]
ToolChoiceToolChoiceTool: TypeAlias = ToolChoiceToolParam
"""This is deprecated, `ToolChoiceToolParam` should be used instead"""


class MessageCreateParamsNonStreaming(MessageCreateParamsBase, total=False):
Expand Down
48 changes: 13 additions & 35 deletions src/anthropic/types/message_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from .model_param import ModelParam
from .message_param import MessageParam
from .text_block_param import TextBlockParam
from .tool_choice_param import ToolChoiceParam
from .tool_choice_any_param import ToolChoiceAnyParam
from .tool_choice_auto_param import ToolChoiceAutoParam
from .tool_choice_tool_param import ToolChoiceToolParam

__all__ = [
"MessageCreateParamsBase",
Expand Down Expand Up @@ -162,7 +166,7 @@ class MessageCreateParamsBase(TypedDict, total=False):
deterministic.
"""

tool_choice: ToolChoice
tool_choice: ToolChoiceParam
"""How the model should use the provided tools.
The model can use a specific tool, any available tool, or decide by itself.
Expand Down Expand Up @@ -272,43 +276,17 @@ class Metadata(TypedDict, total=False):
"""


class ToolChoiceToolChoiceAuto(TypedDict, total=False):
type: Required[Literal["auto"]]
ToolChoice: TypeAlias = ToolChoiceParam
"""This is deprecated, `ToolChoiceParam` should be used instead"""

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output at most one tool
use.
"""


class ToolChoiceToolChoiceAny(TypedDict, total=False):
type: Required[Literal["any"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output exactly one tool
use.
"""


class ToolChoiceToolChoiceTool(TypedDict, total=False):
name: Required[str]
"""The name of the tool to use."""

type: Required[Literal["tool"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output exactly one tool
use.
"""
ToolChoiceToolChoiceAuto: TypeAlias = ToolChoiceAutoParam
"""This is deprecated, `ToolChoiceAutoParam` should be used instead"""

ToolChoiceToolChoiceAny: TypeAlias = ToolChoiceAnyParam
"""This is deprecated, `ToolChoiceAnyParam` should be used instead"""

ToolChoice: TypeAlias = Union[ToolChoiceToolChoiceAuto, ToolChoiceToolChoiceAny, ToolChoiceToolChoiceTool]
ToolChoiceToolChoiceTool: TypeAlias = ToolChoiceToolParam
"""This is deprecated, `ToolChoiceToolParam` should be used instead"""


class MessageCreateParamsNonStreaming(MessageCreateParamsBase, total=False):
Expand Down
18 changes: 18 additions & 0 deletions src/anthropic/types/tool_choice_any_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["ToolChoiceAnyParam"]


class ToolChoiceAnyParam(TypedDict, total=False):
type: Required[Literal["any"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output exactly one tool
use.
"""
18 changes: 18 additions & 0 deletions src/anthropic/types/tool_choice_auto_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["ToolChoiceAutoParam"]


class ToolChoiceAutoParam(TypedDict, total=False):
type: Required[Literal["auto"]]

disable_parallel_tool_use: bool
"""Whether to disable parallel tool use.
Defaults to `false`. If set to `true`, the model will output at most one tool
use.
"""
Loading

0 comments on commit f6f3afe

Please sign in to comment.