-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws[minor]: Add ChatModel that uses Bedrock.converse API #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this class should be merged with the ChatBedrock Class with a flag being passed in at creation time to indicate which api to switch too. The reason being converse will not work in a chain unless we have prompt tenmplate, retrievers .... all having a similiar api. It may be better to continue to use invoke in the chain but internally in the ChatBedrock class fork and switch to converse api
Not sure i understand, why wouldn't it work with other components? its still implementing the BaseChatModel interface |
The reason being say I define a chain like
Prompt | llm | outputparse
And if I try and call it by doing chain.converse(..) that will not work so I have to invoke it using chain.invoke(..) however in LLM (ChatBedrock ) class we can fork and call converse api
Secondly from design we encapsulate the converse api since that is native and will proprietary to Bedrock only. SageMaker for example will not support converse api
From: Bagatur ***@***.***>
Reply-To: langchain-ai/langchain-aws ***@***.***>
Date: Thursday, June 13, 2024 at 3:24 PM
To: langchain-ai/langchain-aws ***@***.***>
Cc: "Grewal, Rupinder" ***@***.***>, Comment ***@***.***>
Subject: Re: [langchain-ai/langchain-aws] aws[minor]: Add ChatModel that uses Bedrock.converse API (PR #74)
The reason being converse will not work in a chain unless we have prompt tenmplate, retrievers...
Not sure i understand, why wouldn't it work with other components? its still implementing the BaseChatModel interface
—
Reply to this email directly, view it on GitHub<#74 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYMBZRRLRUDCUJXNGE5JMSDZHILWPAVCNFSM6AAAAABJJGOL7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRWHA4TANZXGY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
to clarify, this is using the bedrock client's converse API but the way you use the resulting langchain chat model is still via invoke. so your chain would continue to work |
Right but it would not be using the converse api. Our goal is to have the ChatBedrock use and switch to the converse api internally since that will be the dominant way of running the workloads. Hence I feel a new class by itself will not be so useful if I cannot plug it into any chain
From: Bagatur ***@***.***>
Reply-To: langchain-ai/langchain-aws ***@***.***>
Date: Thursday, June 13, 2024 at 5:52 PM
To: langchain-ai/langchain-aws ***@***.***>
Cc: "Grewal, Rupinder" ***@***.***>, Comment ***@***.***>
Subject: Re: [langchain-ai/langchain-aws] aws[minor]: Add ChatModel that uses Bedrock.converse API (PR #74)
The reason being say I define a chain like Prompt | llm | outputparse And if I try and call it by doing chain.converse(..) that will not work so I have to invoke it using chain.invoke(..) however in LLM (ChatBedrock ) class we can fork and call converse api Secondly from design we encapsulate the converse api since that is native and will proprietary to Bedrock only. SageMaker for example will not support converse api From: Bagatur @.> Reply-To: langchain-ai/langchain-aws @.> Date: Thursday, June 13, 2024 at 3:24 PM To: langchain-ai/langchain-aws @.> Cc: "Grewal, Rupinder" @.>, Comment @.> Subject: Re: [langchain-ai/langchain-aws] aws[minor]: Add ChatModel that uses Bedrock.converse API (PR #74<#74>) The reason being converse will not work in a chain unless we have prompt tenmplate, retrievers... Not sure i understand, why wouldn't it work with other components? its still implementing the BaseChatModel interface — Reply to this email directly, view it on GitHub<#74 (comment)<#74 (comment)>>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYMBZRRLRUDCUJXNGE5JMSDZHILWPAVCNFSM6AAAAABJJGOL7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRWHA4TANZXGY. You are receiving this because you commented.Message ID: @.>
to clarify, this is using the bedrock client's converse API but the way you use the result langchain chat model is still via invoke. so your chain would continue to work
—
Reply to this email directly, view it on GitHub<#74 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYMBZRUBGOQ2J4NOABAFVGTZHI5B7AVCNFSM6AAAAABJJGOL7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRXGAZDANRWG4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
@baskaryan is there a way for me to test this (other than copying the code locally)? I would really like to give it a try. |
Nevermind, I got it, leaving it here for reference (using poetry):
|
Here are my findings after playing with the ChatBedrockConverse model:
With these changes, I was able to run the https://python.langchain.com/v0.1/docs/use_cases/tool_use/multiple_tools/ example with bedrock, using anthropic. {
"input": "Take 3 to the fifth power and multiply that by the sum of twelve and three, then square the whole result",
"conversation_id": null,
"chat_history": [],
"output": [
{
"type": "text",
"text": "So the final result of taking 3 to the 5th power (243), multiplying by 12 + 3 (15) to get 3645, and then squaring that is 13286025.",
"index": 0
}
]
} |
From a user perspective, will it be confusing to switch class name yet again, to BedrockChat -> ChatBedrock -> ChatBedrockConverse is getting a little crazy IMO 😅 |
idea is to eventually replace ChatBedrock with ChatBedrockConverse. issue is converse doesn't currently support guardrails or custom models afaik, so it'd be breaking to replace now. but for all regular functionality converse provides a more reliable/universal api (eg we can implement tool calling for all models in one go) so it seems worth exposing now. very open to different names (eg ChatBedrockV2). also this is being marked as beta and we can make clear in the docs that this is a preview of what's to come, and folks should only switch to it if they are having issues with ChatBedrock or want to get ahead of the curve |
We cannot change the name as that is 1/ breaking change and will cause confusion for existing customers 2/ We need to follow the naming convention of LangChain which is ChatXYZ.... like ChatAnthropic etc. So ChatBedrock will need to stay 3/ Converse API is a internal to Bedrock and not a feature of LangChain and hence it has to be encapsulated in the ChatBedrock class |
I echo @austinmw's and @rsgrewal-aws position on this. Would it make more sense to have an optional parameter for @3coins thoughts? |
also there is another PR -- #76 may be we can review that |
@austinmw @anjanvb |
Understood. Would have been ideal IMO to turn on converse functionality in ChatBedrock directly with an optional parameter, but if that makes the class logic too complicated to maintain then I guess a new beta class will have to do. |
i would suggest to then add the builder pattern to compose this class at run time and inject the objects which provide or do not provide the functionality. But changing the Class name and pivoting to a new class has impacts and consequences wider and we will tend to loose customer trust . This will be the 3rd class we will be introducing for Bedrock |
@baskaryan @rsgrewal-aws @austinmw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM up to streaming tool calls (discussed offline):
https://smith.langchain.com/public/f05cf920-a2a6-46f1-aeaf-dbd4859c4d8d/r
tool call IDs are null in aggregated output
@@ -0,0 +1,30 @@ | |||
"""Standard LangChain interface tests""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) could we keep the standard tests in test_standard.py? will be easier to find.
I'm good with this approach @3coins @baskaryan |
Awesome -- good with this for now - this will help a lot. I think we can may be start to refactor this class and do the builder / composite pattern to start to reduce the complexity and reduce all the if-then statements |
Updated the other PR to submit just the new changes for the stuff I found during testing with the anthropic claude model using the new bedrock converse endpoint. |
Decisions to discuss: