diff --git a/README.md b/README.md index 1e3a332f..f53dfc4f 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,10 @@ message = client.messages.create( messages=[ { "role": "user", - "content": "How does a court case get to the supreme court?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) print(message.content) ``` @@ -69,10 +69,10 @@ async def main() -> None: messages=[ { "role": "user", - "content": "How does a court case get to the supreme court?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) print(message.content) @@ -96,10 +96,10 @@ stream = client.messages.create( messages=[ { "role": "user", - "content": "your prompt here", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) for event in stream: @@ -118,10 +118,10 @@ stream = await client.messages.create( messages=[ { "role": "user", - "content": "your prompt here", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) async for event in stream: @@ -147,7 +147,7 @@ async def main() -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as stream: async for text in stream.text_stream: print(text, end="", flush=True) @@ -190,11 +190,12 @@ For a more fully fledged example see [`examples/bedrock.py`](https://github.com/ ## Token counting -You can estimate billing for a given request with the `client.count_tokens()` method, eg: +You can see the exact usage for a given request through the `usage` response property, e.g. ```py -client = Anthropic() -client.count_tokens('Hello world!') # 3 +message = client.messages.create(...) +message.usage +# Usage(input_tokens=25, output_tokens=13) ``` ## Using types @@ -227,10 +228,10 @@ try: messages=[ { "role": "user", - "content": "your prompt here", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) except anthropic.APIConnectionError as e: print("The server could not be reached") @@ -279,10 +280,10 @@ client.with_options(max_retries=5).messages.create( messages=[ { "role": "user", - "content": "Can you help me effectively ask for a raise at work?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) ``` @@ -311,10 +312,10 @@ client.with_options(timeout=5 * 1000).messages.create( messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) ``` @@ -374,9 +375,9 @@ response = client.messages.with_raw_response.create( max_tokens=1024, messages=[{ "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", }], - model="claude-2.1", + model="claude-3-opus-20240229", ) print(response.headers.get('X-My-Header')) @@ -407,10 +408,10 @@ with client.messages.with_streaming_response.create( messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as response: print(response.headers.get("X-My-Header")) diff --git a/api.md b/api.md index 3c83d177..cc30d742 100644 --- a/api.md +++ b/api.md @@ -1,21 +1,3 @@ -# Anthropic - -Methods: - -- client.count_tokens(\*args) -> int - -# Completions - -Types: - -```python -from anthropic.types import Completion -``` - -Methods: - -- client.completions.create(\*\*params) -> Completion - # Messages Types: @@ -26,6 +8,7 @@ from anthropic.types import ( ContentBlockDeltaEvent, ContentBlockStartEvent, ContentBlockStopEvent, + ImageBlockParam, Message, MessageDeltaEvent, MessageDeltaUsage, diff --git a/examples/images.py b/examples/images.py new file mode 100644 index 00000000..0da834bc --- /dev/null +++ b/examples/images.py @@ -0,0 +1,30 @@ +from pathlib import Path + +from anthropic import Anthropic + +client = Anthropic() + +response = client.messages.create( + max_tokens=1024, + messages=[ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "Hello!", + }, + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/png", + "data": Path(__file__).parent.joinpath("logo.png"), + }, + }, + ], + }, + ], + model="claude-3-opus-20240229", +) +print(response.model_dump_json(indent=2)) diff --git a/examples/logo.png b/examples/logo.png new file mode 100644 index 00000000..8c299f24 Binary files /dev/null and b/examples/logo.png differ diff --git a/examples/messages.py b/examples/messages.py index 72fff289..f2e7e3c2 100644 --- a/examples/messages.py +++ b/examples/messages.py @@ -10,7 +10,7 @@ "content": "Hello!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) print(response) @@ -30,6 +30,6 @@ "content": "How are you?", }, ], - model="claude-2.1", + model="claude-3-opus-20240229", ) print(response2) diff --git a/examples/messages_stream.py b/examples/messages_stream.py index 3c664cfd..2da36882 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-2.1", + model="claude-3-opus-20240229", ) as stream: async for text in stream.text_stream: print(text, end="", flush=True) diff --git a/examples/messages_stream_handler.py b/examples/messages_stream_handler.py index 65e24445..27e261d0 100644 --- a/examples/messages_stream_handler.py +++ b/examples/messages_stream_handler.py @@ -22,7 +22,7 @@ async def main() -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", event_handler=MyStream, ) as stream: accumulated = await stream.get_final_message() diff --git a/examples/text_completions_demo_async.py b/examples/text_completions_demo_async.py new file mode 100644 index 00000000..49fd5191 --- /dev/null +++ b/examples/text_completions_demo_async.py @@ -0,0 +1,20 @@ +#!/usr/bin/env -S poetry run python + +import asyncio + +import anthropic +from anthropic import AsyncAnthropic + + +async def main() -> None: + client = AsyncAnthropic() + + res = await client.completions.create( + model="claude-2.1", + prompt=f"{anthropic.HUMAN_PROMPT} how does a court case get to the Supreme Court? {anthropic.AI_PROMPT}", + max_tokens_to_sample=1000, + ) + print(res.completion) + + +asyncio.run(main()) diff --git a/examples/text_completions_demo_sync.py b/examples/text_completions_demo_sync.py new file mode 100644 index 00000000..e386e2ad --- /dev/null +++ b/examples/text_completions_demo_sync.py @@ -0,0 +1,18 @@ +#!/usr/bin/env -S poetry run python + +import anthropic +from anthropic import Anthropic + + +def main() -> None: + client = Anthropic() + + res = client.completions.create( + model="claude-2.1", + prompt=f"{anthropic.HUMAN_PROMPT} how does a court case get to the Supreme Court? {anthropic.AI_PROMPT}", + max_tokens_to_sample=1000, + ) + print(res.completion) + + +main() diff --git a/examples/text_completions_streaming.py b/examples/text_completions_streaming.py new file mode 100644 index 00000000..a738aad9 --- /dev/null +++ b/examples/text_completions_streaming.py @@ -0,0 +1,57 @@ +#!/usr/bin/env -S poetry run python + +import asyncio + +from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic, APIStatusError, AsyncAnthropic + +client = Anthropic() +async_client = AsyncAnthropic() + +question = """ +Hey Claude! How can I recursively list all files in a directory in Python? +""" + + +def sync_stream() -> None: + stream = client.completions.create( + prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}", + model="claude-2.1", + stream=True, + max_tokens_to_sample=300, + ) + + for completion in stream: + print(completion.completion, end="", flush=True) + + print() + + +async def async_stream() -> None: + stream = await async_client.completions.create( + prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}", + model="claude-2.1", + stream=True, + max_tokens_to_sample=300, + ) + + async for completion in stream: + print(completion.completion, end="", flush=True) + + print() + + +def stream_error() -> None: + try: + client.completions.create( + prompt=f"{HUMAN_PROMPT} {question}{AI_PROMPT}", + model="claude-unknown-model", + stream=True, + max_tokens_to_sample=300, + ) + except APIStatusError as err: + print(f"Caught API status error with response body: {err.response.text}") + + +sync_stream() +asyncio.run(async_stream()) +stream_error() diff --git a/helpers.md b/helpers.md index c0fecb25..ece0d550 100644 --- a/helpers.md +++ b/helpers.md @@ -11,7 +11,7 @@ async with client.messages.stream( "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as stream: async for text in stream.text_stream: print(text, end="", flush=True) @@ -74,7 +74,7 @@ async def main() -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", event_handler=MyStream, ) as stream: message = await stream.get_final_message() diff --git a/src/anthropic/_client.py b/src/anthropic/_client.py index 4b9e2b90..7a2710f1 100644 --- a/src/anthropic/_client.py +++ b/src/anthropic/_client.py @@ -267,7 +267,12 @@ def count_tokens( self, text: str, ) -> int: - """Count the number of tokens in a given string""" + """Count the number of tokens in a given string. + + Note that this is only accurate for older models, e.g. `claude-2.1`. For newer + models this can only be used as a _very_ rough estimate, instead you should rely + on the `usage` property in the response for exact counts. + """ # Note: tokenizer is untyped tokenizer = self.get_tokenizer() encoded_text = tokenizer.encode(text) # type: ignore @@ -522,7 +527,12 @@ async def count_tokens( self, text: str, ) -> int: - """Count the number of tokens in a given string""" + """Count the number of tokens in a given string. + + Note that this is only accurate for older models, e.g. `claude-2.1`. For newer + models this can only be used as a _very_ rough estimate, instead you should rely + on the `usage` property in the response for exact counts. + """ # Note: tokenizer is untyped tokenizer = await self.get_tokenizer() encoded_text = tokenizer.encode(text) # type: ignore diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py index 2f4bc7e5..02dc62f7 100644 --- a/src/anthropic/lib/streaming/_messages.py +++ b/src/anthropic/lib/streaming/_messages.py @@ -421,7 +421,8 @@ def accumulate_event(*, event: MessageStreamEvent, current_snapshot: Message | N ) elif event.type == "content_block_delta": content = current_snapshot.content[event.index] - content.text += event.delta.text + if content.type == "text" and event.delta.type == "text_delta": + content.text += event.delta.text elif event.type == "message_delta": current_snapshot.stop_reason = event.delta.stop_reason current_snapshot.stop_sequence = event.delta.stop_sequence diff --git a/src/anthropic/resources/completions.py b/src/anthropic/resources/completions.py index 55129656..c75f858f 100644 --- a/src/anthropic/resources/completions.py +++ b/src/anthropic/resources/completions.py @@ -40,7 +40,7 @@ def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, @@ -75,13 +75,7 @@ def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -115,14 +109,21 @@ def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -130,6 +131,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -145,7 +149,7 @@ def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, stream: Literal[True], metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, @@ -180,13 +184,7 @@ def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -220,14 +218,21 @@ def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -235,6 +240,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -250,7 +258,7 @@ def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, stream: bool, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, @@ -285,13 +293,7 @@ def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -325,14 +327,21 @@ def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -340,6 +349,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -355,7 +367,7 @@ def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, @@ -409,7 +421,7 @@ async def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, @@ -444,13 +456,7 @@ async def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -484,14 +490,21 @@ async def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -499,6 +512,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -514,7 +530,7 @@ async def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, stream: Literal[True], metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, @@ -549,13 +565,7 @@ async def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -589,14 +599,21 @@ async def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -604,6 +621,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -619,7 +639,7 @@ async def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, stream: bool, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, @@ -654,13 +674,7 @@ async def create( model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. prompt: The prompt that you want Claude to complete. @@ -694,14 +708,21 @@ async def create( temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -709,6 +730,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -724,7 +748,7 @@ async def create( self, *, max_tokens_to_sample: int, - model: Union[str, Literal["claude-2.1", "claude-instant-1"]], + model: Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]], prompt: str, metadata: completion_create_params.Metadata | NotGiven = NOT_GIVEN, stop_sequences: List[str] | NotGiven = NOT_GIVEN, diff --git a/src/anthropic/resources/messages.py b/src/anthropic/resources/messages.py index 59414ab2..17f968d1 100644 --- a/src/anthropic/resources/messages.py +++ b/src/anthropic/resources/messages.py @@ -68,11 +68,11 @@ def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -81,8 +81,7 @@ def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -119,15 +118,18 @@ def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -137,24 +139,39 @@ def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. metadata: An object describing metadata about the request. @@ -178,18 +195,25 @@ def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -197,6 +221,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -231,11 +258,11 @@ def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -244,8 +271,7 @@ def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -282,15 +308,18 @@ def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -300,24 +329,39 @@ def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. stream: Whether to incrementally stream the response using server-sent events. @@ -341,18 +385,25 @@ def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -360,6 +411,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -394,11 +448,11 @@ def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -407,8 +461,7 @@ def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -445,15 +498,18 @@ def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -463,24 +519,39 @@ def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. stream: Whether to incrementally stream the response using server-sent events. @@ -504,18 +575,25 @@ def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -523,6 +601,9 @@ def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -713,11 +794,11 @@ async def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -726,8 +807,7 @@ async def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -764,15 +844,18 @@ async def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -782,24 +865,39 @@ async def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. metadata: An object describing metadata about the request. @@ -823,18 +921,25 @@ async def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -842,6 +947,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -876,11 +984,11 @@ async def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -889,8 +997,7 @@ async def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -927,15 +1034,18 @@ async def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -945,24 +1055,39 @@ async def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. stream: Whether to incrementally stream the response using server-sent events. @@ -986,18 +1111,25 @@ async def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -1005,6 +1137,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -1039,11 +1174,11 @@ async def create( """ Create a Message. - Send a structured list of input messages, and the model will generate the next - message in the conversation. + Send a structured list of input messages with text and/or image content, and the + model will generate the next message in the conversation. - Messages can be used for either single queries to the model or for multi-turn - conversations. + The Messages API can be used for for either single queries or stateless + multi-turn conversations. Args: max_tokens: The maximum number of tokens to generate before stopping. @@ -1052,8 +1187,7 @@ async def create( only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. messages: Input messages. @@ -1090,15 +1224,18 @@ async def create( ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -1108,24 +1245,39 @@ async def create( { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. model: The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. stream: Whether to incrementally stream the response using server-sent events. @@ -1149,18 +1301,25 @@ async def create( A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). temperature: Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + Recommended for advanced use cases only. You usually only need to use + `temperature`. + top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options @@ -1168,6 +1327,9 @@ async def create( reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + Recommended for advanced use cases only. You usually only need to use + `temperature`. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request diff --git a/src/anthropic/types/__init__.py b/src/anthropic/types/__init__.py index 42df2f09..c576eaf9 100644 --- a/src/anthropic/types/__init__.py +++ b/src/anthropic/types/__init__.py @@ -9,6 +9,7 @@ from .content_block import ContentBlock as ContentBlock from .message_param import MessageParam as MessageParam from .text_block_param import TextBlockParam as TextBlockParam +from .image_block_param import ImageBlockParam as ImageBlockParam from .message_stop_event import MessageStopEvent as MessageStopEvent from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent from .message_delta_usage import MessageDeltaUsage as MessageDeltaUsage diff --git a/src/anthropic/types/completion.py b/src/anthropic/types/completion.py index d4bacc2f..ed2d6fdb 100644 --- a/src/anthropic/types/completion.py +++ b/src/anthropic/types/completion.py @@ -32,3 +32,7 @@ class Completion(BaseModel): """ type: Literal["completion"] + """Object type. + + For Text Completions, this is always `"completion"`. + """ diff --git a/src/anthropic/types/completion_create_params.py b/src/anthropic/types/completion_create_params.py index ff367899..52d0d41d 100644 --- a/src/anthropic/types/completion_create_params.py +++ b/src/anthropic/types/completion_create_params.py @@ -25,16 +25,10 @@ class CompletionCreateParamsBase(TypedDict, total=False): only specifies the absolute maximum number of tokens to generate. """ - model: Required[Union[str, Literal["claude-2.1", "claude-instant-1"]]] + model: Required[Union[str, Literal["claude-3-opus-20240229", "claude-2.1", "claude-instant-1"]]] """The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. """ @@ -69,8 +63,12 @@ class CompletionCreateParamsBase(TypedDict, total=False): temperature: float """Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. """ top_k: int @@ -78,6 +76,9 @@ class CompletionCreateParamsBase(TypedDict, total=False): Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + + Recommended for advanced use cases only. You usually only need to use + `temperature`. """ top_p: float @@ -87,6 +88,9 @@ class CompletionCreateParamsBase(TypedDict, total=False): for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + + Recommended for advanced use cases only. You usually only need to use + `temperature`. """ diff --git a/src/anthropic/types/image_block_param.py b/src/anthropic/types/image_block_param.py new file mode 100644 index 00000000..c0788c85 --- /dev/null +++ b/src/anthropic/types/image_block_param.py @@ -0,0 +1,25 @@ +# File generated from our OpenAPI spec by Stainless. + +from __future__ import annotations + +from typing import Union +from typing_extensions import Literal, Required, Annotated, TypedDict + +from .._types import Base64FileInput +from .._utils import PropertyInfo + +__all__ = ["ImageBlockParam", "Source"] + + +class Source(TypedDict, total=False): + data: Required[Annotated[Union[str, Base64FileInput], PropertyInfo(format="base64")]] + + media_type: Required[Literal["image/jpeg", "image/png", "image/gif", "image/webp"]] + + type: Literal["base64"] + + +class ImageBlockParam(TypedDict, total=False): + source: Required[Source] + + type: Literal["image"] diff --git a/src/anthropic/types/message.py b/src/anthropic/types/message.py index 005eb29b..3bbd7afa 100644 --- a/src/anthropic/types/message.py +++ b/src/anthropic/types/message.py @@ -21,7 +21,7 @@ class Message(BaseModel): """Content generated by the model. This is an array of content blocks, each of which has a `type` that determines - its shape. Currently, the only `type` available is `"text"`. + its shape. Currently, the only `type` in responses is `"text"`. Example: @@ -41,10 +41,7 @@ class Message(BaseModel): "role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" }, - { - "role": "assistant", - "content": "The best answer is (" - } + { "role": "assistant", "content": "The best answer is (" } ] ``` @@ -81,12 +78,29 @@ class Message(BaseModel): """ stop_sequence: Optional[str] = None - """Which custom stop sequence was generated. + """Which custom stop sequence was generated, if any. - This value will be non-null if one of your custom stop sequences was generated. + This value will be a non-null string if one of your custom stop sequences was + generated. """ type: Literal["message"] + """Object type. + + For Messages, this is always `"message"`. + """ usage: Usage - """Container for the number of tokens used.""" + """Billing and rate-limit usage. + + Anthropic's API bills and rate-limits by token counts, as tokens represent the + underlying cost to our systems. + + Under the hood, the API transforms requests into a format suitable for the + model. The model's output then goes through a parsing stage before becoming an + API response. As a result, the token counts in `usage` will not match one-to-one + with the exact visible content of an API request or response. + + For example, `output_tokens` will be non-zero, even for an empty string response + from Claude. + """ diff --git a/src/anthropic/types/message_create_params.py b/src/anthropic/types/message_create_params.py index 21d56395..3c3c7b3f 100644 --- a/src/anthropic/types/message_create_params.py +++ b/src/anthropic/types/message_create_params.py @@ -18,8 +18,7 @@ class MessageCreateParamsBase(TypedDict, total=False): only specifies the absolute maximum number of tokens to generate. Different models have different maximum values for this parameter. See - [input and output sizes](https://docs.anthropic.com/claude/reference/input-and-output-sizes) - for details. + [models](https://docs.anthropic.com/claude/docs/models-overview) for details. """ messages: Required[Iterable[MessageParam]] @@ -58,15 +57,18 @@ class MessageCreateParamsBase(TypedDict, total=False): ```json [ - { "role": "user", "content": "Please describe yourself using only JSON" }, - { "role": "assistant", "content": "Here is my JSON description:\n{" } + { + "role": "user", + "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" + }, + { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of - content blocks, where each block has a specific `type`. Using a `string` is - shorthand for an array of one content block of type `"text"`. The following - input messages are equivalent: + content blocks, where each block has a specific `type`. Using a `string` for + `content` is shorthand for an array of one content block of type `"text"`. The + following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } @@ -76,26 +78,41 @@ class MessageCreateParamsBase(TypedDict, total=False): { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` - See our - [guide to prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design) - for more details on how to best construct prompts. + Starting with Claude 3 models, you can also send image content blocks: + + ```json + { + "role": "user", + "content": [ + { + "type": "image", + "source": { + "type": "base64", + "media_type": "image/jpeg", + "data": "/9j/4AAQSkZJRg..." + } + }, + { "type": "text", "text": "What is in this image?" } + ] + } + ``` + + We currently support the `base64` source type for images, and the `image/jpeg`, + `image/png`, `image/gif`, and `image/webp` media types. + + See [examples](https://docs.anthropic.com/claude/reference/messages-examples) + for more input examples. Note that if you want to include a - [system prompt](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts), - you can use the top-level `system` parameter — there is no `"system"` role for - input messages in the Messages API. + [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can + use the top-level `system` parameter — there is no `"system"` role for input + messages in the Messages API. """ model: Required[str] """The model that will complete your prompt. - As we improve Claude, we develop new versions of it that you can query. The - `model` parameter controls which version of Claude responds to your request. - Right now we offer two model families: Claude, and Claude Instant. You can use - them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`, - respectively. - - See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for + See [models](https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. """ @@ -119,14 +136,18 @@ class MessageCreateParamsBase(TypedDict, total=False): A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our - [guide to system prompts](https://docs.anthropic.com/claude/docs/how-to-use-system-prompts). + [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts). """ temperature: float """Amount of randomness injected into the response. - Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / - multiple choice, and closer to 1 for creative and generative tasks. + Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` + for analytical / multiple choice, and closer to `1.0` for creative and + generative tasks. + + Note that even with `temperature` of `0.0`, the results will not be fully + deterministic. """ top_k: int @@ -134,6 +155,9 @@ class MessageCreateParamsBase(TypedDict, total=False): Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). + + Recommended for advanced use cases only. You usually only need to use + `temperature`. """ top_p: float @@ -143,6 +167,9 @@ class MessageCreateParamsBase(TypedDict, total=False): for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. + + Recommended for advanced use cases only. You usually only need to use + `temperature`. """ diff --git a/src/anthropic/types/message_delta_event.py b/src/anthropic/types/message_delta_event.py index 1498b7f2..bc0530e5 100644 --- a/src/anthropic/types/message_delta_event.py +++ b/src/anthropic/types/message_delta_event.py @@ -21,4 +21,16 @@ class MessageDeltaEvent(BaseModel): type: Literal["message_delta"] usage: MessageDeltaUsage - """Container for the number of tokens used.""" + """Billing and rate-limit usage. + + Anthropic's API bills and rate-limits by token counts, as tokens represent the + underlying cost to our systems. + + Under the hood, the API transforms requests into a format suitable for the + model. The model's output then goes through a parsing stage before becoming an + API response. As a result, the token counts in `usage` will not match one-to-one + with the exact visible content of an API request or response. + + For example, `output_tokens` will be non-zero, even for an empty string response + from Claude. + """ diff --git a/src/anthropic/types/message_param.py b/src/anthropic/types/message_param.py index 7fc17d42..5b321957 100644 --- a/src/anthropic/types/message_param.py +++ b/src/anthropic/types/message_param.py @@ -7,11 +7,12 @@ from .content_block import ContentBlock from .text_block_param import TextBlockParam +from .image_block_param import ImageBlockParam __all__ = ["MessageParam"] class MessageParam(TypedDict, total=False): - content: Required[Union[str, Iterable[Union[TextBlockParam, ContentBlock]]]] + content: Required[Union[str, Iterable[Union[TextBlockParam, ImageBlockParam, ContentBlock]]]] role: Required[Literal["user", "assistant"]] diff --git a/tests/api_resources/test_messages.py b/tests/api_resources/test_messages.py index cc76a125..9198ffdd 100644 --- a/tests/api_resources/test_messages.py +++ b/tests/api_resources/test_messages.py @@ -24,10 +24,10 @@ def test_method_create_overload_1(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) assert_matches_type(Message, message, path=["response"]) @@ -38,10 +38,10 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], stream=False, @@ -59,10 +59,10 @@ def test_raw_response_create_overload_1(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) assert response.is_closed is True @@ -77,10 +77,10 @@ def test_streaming_response_create_overload_1(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -97,10 +97,10 @@ def test_method_create_overload_2(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) message_stream.response.close() @@ -112,10 +112,10 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], @@ -133,10 +133,10 @@ def test_raw_response_create_overload_2(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) @@ -151,10 +151,10 @@ def test_streaming_response_create_overload_2(self, client: Anthropic) -> None: messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) as response: assert not response.is_closed @@ -176,10 +176,10 @@ async def test_method_create_overload_1(self, async_client: AsyncAnthropic) -> N messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) assert_matches_type(Message, message, path=["response"]) @@ -190,10 +190,10 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], stream=False, @@ -211,10 +211,10 @@ async def test_raw_response_create_overload_1(self, async_client: AsyncAnthropic messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) assert response.is_closed is True @@ -229,10 +229,10 @@ async def test_streaming_response_create_overload_1(self, async_client: AsyncAnt messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -249,10 +249,10 @@ async def test_method_create_overload_2(self, async_client: AsyncAnthropic) -> N messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) await message_stream.response.aclose() @@ -264,10 +264,10 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, metadata={"user_id": "13803d75-b4b5-4c3e-b2a2-6f21399b021b"}, stop_sequences=["string", "string", "string"], @@ -285,10 +285,10 @@ async def test_raw_response_create_overload_2(self, async_client: AsyncAnthropic messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) @@ -303,10 +303,10 @@ async def test_streaming_response_create_overload_2(self, async_client: AsyncAnt messages=[ { "role": "user", - "content": "In one sentence, what is good about the color blue?", + "content": "Hello, world", } ], - model="claude-2.1", + model="claude-3-opus-20240229", stream=True, ) as response: assert not response.is_closed diff --git a/tests/lib/streaming/test_messages.py b/tests/lib/streaming/test_messages.py index 1acbb26f..4d247238 100644 --- a/tests/lib/streaming/test_messages.py +++ b/tests/lib/streaming/test_messages.py @@ -24,7 +24,7 @@ # copied from the real API stream_example = """ event: message_start -data: {"type":"message_start","message":{"id":"msg_4QpJur2dWWDjF6C758FbBw5vm12BaVipnK","type":"message","role":"assistant","content":[],"model":"claude-2.1","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":1}}} +data: {"type":"message_start","message":{"id":"msg_4QpJur2dWWDjF6C758FbBw5vm12BaVipnK","type":"message","role":"assistant","content":[],"model":"claude-3-opus-20240229","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":11,"output_tokens":1}}} event: content_block_start data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} @@ -86,7 +86,7 @@ async def on_stream_event(self, event: MessageStreamEvent) -> None: def assert_basic_response(stream: SyncEventTracker | AsyncEventTracker, message: Message) -> None: assert message.id == "msg_4QpJur2dWWDjF6C758FbBw5vm12BaVipnK" - assert message.model == "claude-2.1" + assert message.model == "claude-3-opus-20240229" assert message.role == "assistant" assert message.stop_reason == "end_turn" assert message.stop_sequence is None @@ -121,7 +121,7 @@ def test_basic_response(self, respx_mock: MockRouter) -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", event_handler=SyncEventTracker, ) as stream: assert_basic_response(stream, stream.get_final_message()) @@ -138,7 +138,7 @@ def test_context_manager(self, respx_mock: MockRouter) -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as stream: assert not stream.response.is_closed @@ -160,7 +160,7 @@ async def test_basic_response(self, respx_mock: MockRouter) -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", event_handler=AsyncEventTracker, ) as stream: assert_basic_response(stream, await stream.get_final_message()) @@ -178,7 +178,7 @@ async def test_context_manager(self, respx_mock: MockRouter) -> None: "content": "Say hello there!", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ) as stream: assert not stream.response.is_closed diff --git a/tests/test_client.py b/tests/test_client.py index 6d214499..7485975f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -815,10 +815,10 @@ def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> No messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ), ), cast_to=httpx.Response, @@ -842,10 +842,10 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ), ), cast_to=httpx.Response, @@ -1633,10 +1633,10 @@ async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ), ), cast_to=httpx.Response, @@ -1660,10 +1660,10 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) messages=[ { "role": "user", - "content": "Where can I get a good coffee in my neighbourhood?", + "content": "Hello, Claude", } ], - model="claude-2.1", + model="claude-3-opus-20240229", ), ), cast_to=httpx.Response,