quarkus-langchain4j
quarkus-langchain4j copied to clipboard
Support for AWS bedrock
Hi there!
Are there any plans to support the langchain4j AWS bedrock integrations? Would be great if it could be added at some point..
Definitely!
I would like to contribute on this issue. Is there any specific process of this?
Not that I know of
some news on that issue? How to contribute?
The easiest way to include this would be to reuse what LangChain4j has and just set up the proper beans (as is done for other providers). The hard path is to use our own REST Client for the calls.
Hi @geoand,
Edit: Moved to PR
I should have read your message earlier. I will check what is up with the rest client. Can you provide me some insights why this is needed? I will try to adjust it then.
I can do things like this:
builder.asyncConfiguration(b -> b
.advancedOption(
SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR,
eventLoopGroup
))
.httpClientBuilder(NettyNioAsyncHttpClient.builder()
.eventLoopGroup(SdkEventLoopGroup.create(eventLoopGroup)));
If this is enough I would favor that, but for the usage of netty and therefore the vertx client, I would need to throw away the non async client, which is used by langchain4j in the BedrockChatModel, BedrockCohereEmbeddingModel and BedrockTitanEmbeddingModel and implement it myself with the async version.
Or something like this is possible, but not sure about the QuarkusRestClientBuilder.
public class QuarkusSdkHttpClient implements SdkHttpClient {
public QuarkusSdkHttpClient() {
var restApiBuilder = QuarkusRestClientBuilder.newBuilder()
.baseUri(new URI("..."))
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS);
restApiBuilder.build(null);
}
@Override
public ExecutableHttpRequest prepareRequest(final HttpExecuteRequest request) {
// TODO: prepare the custom client
return null;
}
@Override
public void close() {
// TODO: close the custom client
}
}
Already setting the baseUrl is kind of removing some flexibility you typically have with the SDK: Example 1: https://bedrock-runtime.eu-central-1.amazonaws.com Example 2: https://bedrock-runtime.cn-north-1.amazonaws.com.cn
- The region is currently only optional. If not specified the sdk determines the region by its default provider chain. Maybe I could copy some code of the SDK to use the config or the default chain here as well
- The host is dependent on the AWS partition. I would need to reimplement that. Maybe possible as well. I think there are only three.
The SdkHttpClient interface is not that bad actually. I have all infos for the request and what to set in the response, but I think setting it in a "low level" client is easier than in a "high level" client like the QuarkusRestClient. I will check what I could do here.