generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR adds integration for the newly released [Nova](https://www.aboutamazon.com/news/aws/amazon-nova-artificial-intelligence-bedrock-aws) models in Bedrock. These models support both images and video as inputs. #### Image Sample Code ```python from langchain_aws import ChatBedrock from langchain_core.messages import HumanMessage image_path = "media/sunset.png" llm = ChatBedrock( model="us.amazon.nova-lite-v1:0", temperature=0.7 ) with open(image_path, "rb") as image_file: binary_data = image_file.read() message = HumanMessage( content=[ {"image": {"format": "png", "source": {"bytes": binary_data}}}, {"text": "Provide a summary of this photo"}, ] ) response = llm.invoke([message]) ``` #### Video Sample Code ```python from langchain_aws import ChatBedrock video_path = "media/cooking-quesadilla.mp4" llm = ChatBedrock( model="us.amazon.nova-lite-v1:0", temperature=0.7 ) with open(video_path, "rb") as video_file: binary_data = video_file.read() message = HumanMessage( content=[ {"video": {"format": "mp4", "source": {"bytes": binary_data}}}, {"type": "text", "text": "Describe the following video"}, ] ) response = llm.invoke([message]) ``` #### Tool Call Sample ```python from langchain_aws import ChatBedrock from langchain.tools import tool @tool def multiply(a: int, b: int) -> int: """Multiply two numbers.""" return a * b tools = [multiply] llm_with_tools = ChatBedrock( model="us.amazon.nova-lite-v1:0", temperature=1, top_p=1, model_kwargs={ "additional_model_request_fields": { "inferenceConfig": { "topK": 1 } } }, ).bind_tools(tools) response = llm_with_tools.invoke([("user", "What is 8*8")]) ``` **Note**: To get the best results with the Nova models when used in agent, structured or tool calls, use these values for temperature=1, top_p=1 and topK=1 as specified in the samples. --- #### Image and Video used in sample code ![sunset](https://github.com/user-attachments/assets/8d2d42df-b49d-41f8-8b85-cb9a84910903) https://github.com/user-attachments/assets/cf803340-18cf-444b-b72b-0e2866c6ce58
- Loading branch information
1 parent
f7dc810
commit 2ff60dd
Showing
9 changed files
with
1,249 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.