From 1ad9e4ff559f16760de15e2352a64bb2b3103071 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:31:43 +0000 Subject: [PATCH] docs: use latest sonnet in example snippets (#781) --- README.md | 30 +++++++++++++++--------------- examples/images.py | 2 +- examples/messages.py | 4 ++-- examples/messages_stream.py | 2 +- examples/tools.py | 4 ++-- examples/tools_stream.py | 2 +- helpers.md | 4 ++-- tests/test_client.py | 8 ++++---- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index cd376246..5a61b0c1 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ message = client.messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(message.content) ``` @@ -70,7 +70,7 @@ async def main() -> None: "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(message.content) @@ -97,7 +97,7 @@ stream = client.messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", stream=True, ) for event in stream: @@ -119,7 +119,7 @@ stream = await client.messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", stream=True, ) async for event in stream: @@ -145,7 +145,7 @@ async def main() -> None: "content": "Say hello there!", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) as stream: async for text in stream.text_stream: print(text, end="", flush=True) @@ -198,7 +198,7 @@ await client.beta.messages.batches.create( { "custom_id": "my-first-request", "params": { - "model": "claude-3-5-sonnet-20240620", + "model": "claude-3-5-sonnet-latest", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello, world"}], }, @@ -206,7 +206,7 @@ await client.beta.messages.batches.create( { "custom_id": "my-second-request", "params": { - "model": "claude-3-5-sonnet-20240620", + "model": "claude-3-5-sonnet-latest", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hi again, friend"}], }, @@ -250,7 +250,7 @@ message = client.messages.create( "content": "Hello!", } ], - model="anthropic.claude-3-sonnet-20240229-v1:0", + model="anthropic.claude-3-5-sonnet-20241022-v2:0", ) print(message) ``` @@ -281,7 +281,7 @@ from anthropic import AnthropicVertex client = AnthropicVertex() message = client.messages.create( - model="claude-3-sonnet@20240229", + model="claude-3-5-sonnet-v2@20241022", max_tokens=100, messages=[ { @@ -399,7 +399,7 @@ try: "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) except anthropic.APIConnectionError as e: print("The server could not be reached") @@ -440,7 +440,7 @@ message = client.messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(message._request_id) # req_018EeWyXxfu5pfWkrYcMdjWG ``` @@ -475,7 +475,7 @@ client.with_options(max_retries=5).messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) ``` @@ -507,7 +507,7 @@ client.with_options(timeout=5.0).messages.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) ``` @@ -571,7 +571,7 @@ response = client.messages.with_raw_response.create( "role": "user", "content": "Hello, Claude", }], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(response.headers.get('X-My-Header')) @@ -605,7 +605,7 @@ with client.messages.with_streaming_response.create( "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) as response: print(response.headers.get("X-My-Header")) diff --git a/examples/images.py b/examples/images.py index 0da834bc..0ebf2eb5 100644 --- a/examples/images.py +++ b/examples/images.py @@ -25,6 +25,6 @@ ], }, ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(response.model_dump_json(indent=2)) diff --git a/examples/messages.py b/examples/messages.py index f2e7e3c2..55151dd0 100644 --- a/examples/messages.py +++ b/examples/messages.py @@ -10,7 +10,7 @@ "content": "Hello!", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(response) @@ -30,6 +30,6 @@ "content": "How are you?", }, ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) print(response2) diff --git a/examples/messages_stream.py b/examples/messages_stream.py index be69a2c1..a7288aab 100644 --- a/examples/messages_stream.py +++ b/examples/messages_stream.py @@ -14,7 +14,7 @@ async def main() -> None: "content": "Say hello there!", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) as stream: async for event in stream: if event.type == "text": diff --git a/examples/tools.py b/examples/tools.py index c0a8ea60..b6978757 100644 --- a/examples/tools.py +++ b/examples/tools.py @@ -21,7 +21,7 @@ ] message = client.messages.create( - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", max_tokens=1024, messages=[user_message], tools=tools, @@ -32,7 +32,7 @@ tool = next(c for c in message.content if c.type == "tool_use") response = client.messages.create( - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", max_tokens=1024, messages=[ user_message, diff --git a/examples/tools_stream.py b/examples/tools_stream.py index 0fe9cfc1..4d712508 100644 --- a/examples/tools_stream.py +++ b/examples/tools_stream.py @@ -8,7 +8,7 @@ async def main() -> None: async with client.messages.stream( max_tokens=1024, - model="claude-3-haiku-20240307", + model="claude-3-5-sonnet-latest", tools=[ { "name": "get_weather", diff --git a/helpers.md b/helpers.md index 55c249a2..65eac0bf 100644 --- a/helpers.md +++ b/helpers.md @@ -11,7 +11,7 @@ async with client.messages.stream( "content": "Say hello there!", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) as stream: async for text in stream.text_stream: print(text, end="", flush=True) @@ -60,7 +60,7 @@ async with client.messages.stream( "content": "Say hello there!", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ) as stream: async for event in stream: if event.type == "text": diff --git a/tests/test_client.py b/tests/test_client.py index f50233f0..ca181ada 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -745,7 +745,7 @@ def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> No "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ), ), cast_to=httpx.Response, @@ -772,7 +772,7 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ), ), cast_to=httpx.Response, @@ -1625,7 +1625,7 @@ async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ), ), cast_to=httpx.Response, @@ -1652,7 +1652,7 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) "content": "Hello, Claude", } ], - model="claude-3-opus-20240229", + model="claude-3-5-sonnet-latest", ), ), cast_to=httpx.Response,