From 5ea6b182715cd355cc405554b81f3d0f725486f6 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Tue, 18 Jun 2024 19:31:17 +0100 Subject: [PATCH] feat(api): add new claude-3-5-sonnet-20240620 model (#545) --- .stats.yml | 2 +- src/anthropic/resources/messages.py | 31 ++++++---- src/anthropic/types/message_create_params.py | 4 +- tests/api_resources/test_messages.py | 60 +++++++++++++------- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/.stats.yml b/.stats.yml index 660e6d2d..68c3aa80 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 2 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-4f6df1026ffeed840bbfada906ac51144508d1e1b099084c593aa9bac97a3362.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-70873642f89316fbc45ceaccd3583971d0eb59d433f7864ca2fa8c321a320b4c.yml diff --git a/src/anthropic/resources/messages.py b/src/anthropic/resources/messages.py index 9579d98e..18badfa8 100644 --- a/src/anthropic/resources/messages.py +++ b/src/anthropic/resources/messages.py @@ -27,6 +27,7 @@ from ..types.message import Message from ..types.tool_param import ToolParam from ..types.message_param import MessageParam +from ..types.text_block_param import TextBlockParam from ..types.raw_message_stream_event import RawMessageStreamEvent __all__ = ["Messages", "AsyncMessages"] @@ -50,6 +51,7 @@ def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -61,7 +63,7 @@ def create( metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, stream: Literal[False] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -324,6 +326,7 @@ def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -335,7 +338,7 @@ def create( stream: Literal[True], metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -598,6 +601,7 @@ def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -609,7 +613,7 @@ def create( stream: bool, metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -872,6 +876,7 @@ def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -883,7 +888,7 @@ def create( metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -931,6 +936,7 @@ def stream( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -941,7 +947,7 @@ def stream( ], metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: str | NotGiven = NOT_GIVEN, + system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, top_k: int | NotGiven = NOT_GIVEN, top_p: float | NotGiven = NOT_GIVEN, @@ -1007,6 +1013,7 @@ async def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -1018,7 +1025,7 @@ async def create( metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, stream: Literal[False] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -1281,6 +1288,7 @@ async def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -1292,7 +1300,7 @@ async def create( stream: Literal[True], metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -1555,6 +1563,7 @@ async def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -1566,7 +1575,7 @@ async def create( stream: bool, metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -1829,6 +1838,7 @@ async def create( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -1840,7 +1850,7 @@ async def create( metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - system: 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, tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, @@ -1888,6 +1898,7 @@ def stream( model: Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -1898,7 +1909,7 @@ def stream( ], metadata: message_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, - system: str | NotGiven = NOT_GIVEN, + system: Union[str, Iterable[TextBlockParam]] | NotGiven = NOT_GIVEN, temperature: float | NotGiven = NOT_GIVEN, top_k: int | NotGiven = NOT_GIVEN, top_p: float | NotGiven = NOT_GIVEN, diff --git a/src/anthropic/types/message_create_params.py b/src/anthropic/types/message_create_params.py index cb0a0cfb..a76bc0f7 100644 --- a/src/anthropic/types/message_create_params.py +++ b/src/anthropic/types/message_create_params.py @@ -7,6 +7,7 @@ from .tool_param import ToolParam from .message_param import MessageParam +from .text_block_param import TextBlockParam __all__ = [ "MessageCreateParamsBase", @@ -123,6 +124,7 @@ class MessageCreateParamsBase(TypedDict, total=False): Union[ str, Literal[ + "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", @@ -153,7 +155,7 @@ class MessageCreateParamsBase(TypedDict, total=False): and the response `stop_sequence` value will contain the matched stop sequence. """ - system: str + system: Union[str, Iterable[TextBlockParam]] """System prompt. A system prompt is a way of providing context and instructions to Claude, such diff --git a/tests/api_resources/test_messages.py b/tests/api_resources/test_messages.py index af76de94..94dc8cc6 100644 --- a/tests/api_resources/test_messages.py +++ b/tests/api_resources/test_messages.py @@ -27,7 +27,7 @@ def test_method_create_overload_1(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) assert_matches_type(Message, message, path=["response"]) @@ -41,11 +41,16 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], stream=False, - system="Today's date is 2024-01-01.", + system=[ + { + "type": "text", + "text": "Today's date is 2024-06-01.", + } + ], temperature=1, tool_choice={"type": "auto"}, tools=[ @@ -116,7 +121,7 @@ def test_raw_response_create_overload_1(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) assert response.is_closed is True @@ -134,7 +139,7 @@ def test_streaming_response_create_overload_1(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -154,7 +159,7 @@ def test_method_create_overload_2(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) message_stream.response.close() @@ -169,11 +174,16 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], - system="Today's date is 2024-01-01.", + system=[ + { + "type": "text", + "text": "Today's date is 2024-06-01.", + } + ], temperature=1, tool_choice={"type": "auto"}, tools=[ @@ -244,7 +254,7 @@ def test_raw_response_create_overload_2(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) @@ -262,7 +272,7 @@ def test_streaming_response_create_overload_2(self, client: Anthropic) -> None: "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) as response: assert not response.is_closed @@ -287,7 +297,7 @@ async def test_method_create_overload_1(self, async_client: AsyncAnthropic) -> N "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) assert_matches_type(Message, message, path=["response"]) @@ -301,11 +311,16 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], stream=False, - system="Today's date is 2024-01-01.", + system=[ + { + "type": "text", + "text": "Today's date is 2024-06-01.", + } + ], temperature=1, tool_choice={"type": "auto"}, tools=[ @@ -376,7 +391,7 @@ async def test_raw_response_create_overload_1(self, async_client: AsyncAnthropic "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) assert response.is_closed is True @@ -394,7 +409,7 @@ async def test_streaming_response_create_overload_1(self, async_client: AsyncAnt "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -414,7 +429,7 @@ async def test_method_create_overload_2(self, async_client: AsyncAnthropic) -> N "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) await message_stream.response.aclose() @@ -429,11 +444,16 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], - system="Today's date is 2024-01-01.", + system=[ + { + "type": "text", + "text": "Today's date is 2024-06-01.", + } + ], temperature=1, tool_choice={"type": "auto"}, tools=[ @@ -504,7 +524,7 @@ async def test_raw_response_create_overload_2(self, async_client: AsyncAnthropic "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) @@ -522,7 +542,7 @@ async def test_streaming_response_create_overload_2(self, async_client: AsyncAnt "content": "Hello, world", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-20240620", stream=True, ) as response: assert not response.is_closed