Skip to content

Commit

Permalink
refactor(types): improve metadata types (#682)
Browse files Browse the repository at this point in the history
Co-authored-by: Stainless Bot <dev@stainlessapi.com>
  • Loading branch information
RobertCraigie and stainless-bot authored Oct 8, 2024
1 parent fe2e417 commit e037d1c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 63 deletions.
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from anthropic.types import (
MessageStartEvent,
MessageStopEvent,
MessageStreamEvent,
Metadata,
Model,
RawContentBlockDeltaEvent,
RawContentBlockStartEvent,
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.metadata_param import MetadataParam
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
Expand Down Expand Up @@ -64,7 +65,7 @@ def create(
max_tokens: int,
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -328,7 +329,7 @@ def create(
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
stream: Literal[True],
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -591,7 +592,7 @@ def create(
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
stream: bool,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -853,7 +854,7 @@ def create(
max_tokens: int,
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -986,7 +987,7 @@ async def create(
max_tokens: int,
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1250,7 +1251,7 @@ async def create(
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
stream: Literal[True],
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1513,7 +1514,7 @@ async def create(
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
stream: bool,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1775,7 +1776,7 @@ async def create(
max_tokens: int,
messages: Iterable[PromptCachingBetaMessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[PromptCachingBetaTextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down
17 changes: 9 additions & 8 deletions src/anthropic/resources/completions.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 ..types.completion import Completion
from ..types.model_param import ModelParam
from ..types.metadata_param import MetadataParam

__all__ = ["Completions", "AsyncCompletions"]

Expand Down Expand Up @@ -55,7 +56,7 @@ def create(
max_tokens_to_sample: int,
model: ModelParam,
prompt: str,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -160,7 +161,7 @@ def create(
model: ModelParam,
prompt: str,
stream: Literal[True],
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -264,7 +265,7 @@ def create(
model: ModelParam,
prompt: str,
stream: bool,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -367,7 +368,7 @@ def create(
max_tokens_to_sample: int,
model: ModelParam,
prompt: str,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -434,7 +435,7 @@ async def create(
max_tokens_to_sample: int,
model: ModelParam,
prompt: str,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -539,7 +540,7 @@ async def create(
model: ModelParam,
prompt: str,
stream: Literal[True],
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -643,7 +644,7 @@ async def create(
model: ModelParam,
prompt: str,
stream: bool,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
top_k: int | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -746,7 +747,7 @@ async def create(
max_tokens_to_sample: int,
model: ModelParam,
prompt: str,
metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
temperature: 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 @@ -29,6 +29,7 @@
from ..types.tool_param import ToolParam
from ..types.model_param import ModelParam
from ..types.message_param import MessageParam
from ..types.metadata_param import MetadataParam
from ..types.text_block_param import TextBlockParam
from ..types.tool_choice_param import ToolChoiceParam
from ..types.raw_message_stream_event import RawMessageStreamEvent
Expand Down Expand Up @@ -72,7 +73,7 @@ def create(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -336,7 +337,7 @@ def create(
messages: Iterable[MessageParam],
model: ModelParam,
stream: Literal[True],
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -599,7 +600,7 @@ def create(
messages: Iterable[MessageParam],
model: ModelParam,
stream: bool,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -861,7 +862,7 @@ def create(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -920,7 +921,7 @@ def stream(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1004,7 +1005,7 @@ async def create(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1268,7 +1269,7 @@ async def create(
messages: Iterable[MessageParam],
model: ModelParam,
stream: Literal[True],
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1531,7 +1532,7 @@ async def create(
messages: Iterable[MessageParam],
model: ModelParam,
stream: bool,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1793,7 +1794,7 @@ async def create(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1852,7 +1853,7 @@ def stream(
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN,
metadata: MetadataParam | NotGiven = NOT_GIVEN,
stop_sequences: List[str] | NotGiven = NOT_GIVEN,
system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN,
temperature: float | NotGiven = NOT_GIVEN,
Expand Down
1 change: 1 addition & 0 deletions src/anthropic/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .model_param import ModelParam as ModelParam
from .content_block import ContentBlock as ContentBlock
from .message_param import MessageParam as MessageParam
from .metadata_param import MetadataParam as MetadataParam
from .tool_use_block import ToolUseBlock as ToolUseBlock
from .input_json_delta import InputJSONDelta as InputJSONDelta
from .text_block_param import TextBlockParam as TextBlockParam
Expand Down
16 changes: 5 additions & 11 deletions src/anthropic/types/beta/prompt_caching/message_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

from typing import List, Union, Iterable, Optional
from typing import List, Union, Iterable
from typing_extensions import Literal, Required, TypeAlias, TypedDict

from ...model_param import ModelParam
from ...metadata_param import MetadataParam
from ...tool_choice_param import ToolChoiceParam
from ...tool_choice_any_param import ToolChoiceAnyParam
from ...tool_choice_auto_param import ToolChoiceAutoParam
Expand Down Expand Up @@ -132,7 +133,7 @@ class MessageCreateParamsBase(TypedDict, total=False):
details and options.
"""

metadata: Metadata
metadata: MetadataParam
"""An object describing metadata about the request."""

stop_sequences: List[str]
Expand Down Expand Up @@ -266,15 +267,8 @@ class MessageCreateParamsBase(TypedDict, total=False):
"""


class Metadata(TypedDict, total=False):
user_id: Optional[str]
"""An external identifier for the user who is associated with the request.
This should be a uuid, hash value, or other opaque identifier. Anthropic may use
this id to help detect abuse. Do not include any identifying information such as
name, email address, or phone number.
"""

Metadata: TypeAlias = MetadataParam
"""This is deprecated, `MetadataParam` should be used instead"""

ToolChoice: TypeAlias = ToolChoiceParam
"""This is deprecated, `ToolChoiceParam` should be used instead"""
Expand Down
25 changes: 10 additions & 15 deletions src/anthropic/types/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

from typing import List, Union, Optional
from typing_extensions import Literal, Required, TypedDict
from typing import List, Union
from typing_extensions import Literal, Required, TypeAlias, TypedDict

from .model_param import ModelParam
from .metadata_param import MetadataParam

__all__ = [
"CompletionRequestStreamingMetadata",
Expand Down Expand Up @@ -50,7 +51,7 @@ class CompletionCreateParamsBase(TypedDict, total=False):
details.
"""

metadata: Metadata
metadata: MetadataParam
"""An object describing metadata about the request."""

stop_sequences: List[str]
Expand Down Expand Up @@ -95,14 +96,8 @@ class CompletionCreateParamsBase(TypedDict, total=False):
"""


class Metadata(TypedDict, total=False):
user_id: Optional[str]
"""An external identifier for the user who is associated with the request.
This should be a uuid, hash value, or other opaque identifier. Anthropic may use
this id to help detect abuse. Do not include any identifying information such as
name, email address, or phone number.
"""
Metadata: TypeAlias = MetadataParam
"""This is deprecated, `MetadataParam` should be used instead"""


class CompletionCreateParamsNonStreaming(CompletionCreateParamsBase, total=False):
Expand All @@ -121,11 +116,11 @@ class CompletionCreateParamsStreaming(CompletionCreateParamsBase):
"""


CompletionRequestStreamingMetadata = Metadata
"""This is deprecated, `Metadata` should be used instead"""
CompletionRequestStreamingMetadata = MetadataParam
"""This is deprecated, `MetadataParam` should be used instead"""

CompletionRequestNonStreamingMetadata = Metadata
"""This is deprecated, `Metadata` should be used instead"""
CompletionRequestNonStreamingMetadata = MetadataParam
"""This is deprecated, `MetadataParam` should be used instead"""

CompletionRequestNonStreaming = CompletionCreateParamsNonStreaming
"""This is deprecated, `CompletionCreateParamsNonStreaming` should be used instead"""
Expand Down
Loading

0 comments on commit e037d1c

Please sign in to comment.