Skip to content

Commit

Permalink
feat(messages): allow message response in params (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Feb 8, 2024
1 parent 636bb83 commit 86c63f0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions examples/messages.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion src/anthropic/types/beta/message_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]

0 comments on commit 86c63f0

Please sign in to comment.