From 6ec964fe9af19b6e46a713c71c5f45fa9a8012cf Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 27 Nov 2024 20:51:13 -0500 Subject: [PATCH 1/4] Added stop sequence parameter to ChatBedrock model --- libs/aws/langchain_aws/chat_models/bedrock.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/aws/langchain_aws/chat_models/bedrock.py b/libs/aws/langchain_aws/chat_models/bedrock.py index 54d34ffb..833cdb7c 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock.py +++ b/libs/aws/langchain_aws/chat_models/bedrock.py @@ -36,7 +36,7 @@ from langchain_core.runnables import Runnable, RunnableMap, RunnablePassthrough from langchain_core.tools import BaseTool from langchain_core.utils.pydantic import TypeBaseModel, is_basemodel_subclass -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field from langchain_aws.chat_models.bedrock_converse import ChatBedrockConverse from langchain_aws.function_calling import ( @@ -392,6 +392,12 @@ class ChatBedrock(BaseChatModel, BedrockBase): """Use the new Bedrock ``converse`` API which provides a standardized interface to all Bedrock models. Support still in beta. See ChatBedrockConverse docs for more.""" + stop_sequences: Optional[List[str]] = Field(default=None, alias='stop') + """Stop sequence inference parameter from new Bedrock ``converse`` API providing + a sequence of characters that causes a model to stop generating a response. See + https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_InferenceConfiguration.html + for more.""" + @property def _llm_type(self) -> str: """Return type of chat model.""" From b8571ec14b701c086e2f591561c89a0c91a1699d Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 16 Dec 2024 17:07:38 -0500 Subject: [PATCH 2/4] Added stop sequence parameter to ChatBedrock model --- libs/aws/langchain_aws/chat_models/bedrock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/aws/langchain_aws/chat_models/bedrock.py b/libs/aws/langchain_aws/chat_models/bedrock.py index 833cdb7c..95ec2ac3 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock.py +++ b/libs/aws/langchain_aws/chat_models/bedrock.py @@ -392,12 +392,12 @@ class ChatBedrock(BaseChatModel, BedrockBase): """Use the new Bedrock ``converse`` API which provides a standardized interface to all Bedrock models. Support still in beta. See ChatBedrockConverse docs for more.""" - stop_sequences: Optional[List[str]] = Field(default=None, alias='stop') + stop_sequences: Optional[List[str]] = Field(default=None, alias="stop") """Stop sequence inference parameter from new Bedrock ``converse`` API providing a sequence of characters that causes a model to stop generating a response. See https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_InferenceConfiguration.html for more.""" - + @property def _llm_type(self) -> str: """Return type of chat model.""" From 7fa51ee0bda1b2d7568888a7dd6902089fa9804d Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 16 Dec 2024 17:12:33 -0500 Subject: [PATCH 3/4] Added field import for stop sequence parameter for chat bedrock model --- libs/aws/langchain_aws/chat_models/bedrock.py | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/aws/langchain_aws/chat_models/bedrock.py b/libs/aws/langchain_aws/chat_models/bedrock.py index eec12cef..a4b19655 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock.py +++ b/libs/aws/langchain_aws/chat_models/bedrock.py @@ -36,7 +36,6 @@ from langchain_core.runnables import Runnable, RunnableMap, RunnablePassthrough from langchain_core.tools import BaseTool from langchain_core.utils.pydantic import TypeBaseModel, is_basemodel_subclass -from pydantic import BaseModel, ConfigDict, model_validator from langchain_aws.chat_models.bedrock_converse import ChatBedrockConverse from langchain_aws.function_calling import ( From 464745e27155baa2301aa59654c549c760ddfc0b Mon Sep 17 00:00:00 2001 From: zhaoJoseph <94765138+zhaoJoseph@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:19:09 -0500 Subject: [PATCH 4/4] Update bedrock.py add pydantic field type for stop sequence --- libs/aws/langchain_aws/chat_models/bedrock.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/aws/langchain_aws/chat_models/bedrock.py b/libs/aws/langchain_aws/chat_models/bedrock.py index a4b19655..b6b5d2f9 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock.py +++ b/libs/aws/langchain_aws/chat_models/bedrock.py @@ -36,6 +36,7 @@ from langchain_core.runnables import Runnable, RunnableMap, RunnablePassthrough from langchain_core.tools import BaseTool from langchain_core.utils.pydantic import TypeBaseModel, is_basemodel_subclass +from pydantic import BaseModel, ConfigDict, Field, model_validator from langchain_aws.chat_models.bedrock_converse import ChatBedrockConverse from langchain_aws.function_calling import (