From 86c63f0e7441a9fe894b3ae7cd7e871060d5ebbf Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:42:01 +0000 Subject: [PATCH] feat(messages): allow message response in params (#339) --- examples/messages.py | 35 +++++++++++++++++++++++ src/anthropic/types/beta/message_param.py | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 examples/messages.py diff --git a/examples/messages.py b/examples/messages.py new file mode 100644 index 00000000..5fb8b5cd --- /dev/null +++ b/examples/messages.py @@ -0,0 +1,35 @@ +from anthropic import Anthropic + +client = Anthropic() + +response = client.beta.messages.create( + max_tokens=1024, + messages=[ + { + "role": "user", + "content": "Hello!", + } + ], + model="claude-2.1", +) +print(response) + +response2 = client.beta.messages.create( + max_tokens=1024, + messages=[ + { + "role": "user", + "content": "Hello!", + }, + { + "role": response.role, + "content": response.content, + }, + { + "role": "user", + "content": "How are you?", + }, + ], + model="claude-2.1", +) +print(response2) diff --git a/src/anthropic/types/beta/message_param.py b/src/anthropic/types/beta/message_param.py index 3a4c2c98..7fc17d42 100644 --- a/src/anthropic/types/beta/message_param.py +++ b/src/anthropic/types/beta/message_param.py @@ -5,12 +5,13 @@ from typing import Union, Iterable from typing_extensions import Literal, Required, TypedDict +from .content_block import ContentBlock from .text_block_param import TextBlockParam __all__ = ["MessageParam"] class MessageParam(TypedDict, total=False): - content: Required[Union[str, Iterable[TextBlockParam]]] + content: Required[Union[str, Iterable[Union[TextBlockParam, ContentBlock]]]] role: Required[Literal["user", "assistant"]]