Skip to main content

Bedrock Chat

Amazon Bedrock is a fully managed service that makes FMs from leading AI startups and Amazon available via an API, so you can choose from a wide range of FMs to find the model that is best suited for your use case

%pip install boto3
from langchain.chat_models import BedrockChat
from langchain.schema import HumanMessage
chat = BedrockChat(model_id="anthropic.claude-v2", model_kwargs={"temperature":0.1})
messages = [
HumanMessage(
content="Translate this sentence from English to French. I love programming."
)
]
chat(messages)
    AIMessage(content=" Voici la traduction en franรงais : J'adore programmer.", additional_kwargs={}, example=False)

For BedrockChat with Streamingโ€‹

from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

chat = BedrockChat(
model_id="anthropic.claude-v2",
streaming=True,
callbacks=[StreamingStdOutCallbackHandler()],
model_kwargs={"temperature": 0.1},
)
messages = [
HumanMessage(
content="Translate this sentence from English to French. I love programming."
)
]
chat(messages)