quarkus-langchain4j icon indicating copy to clipboard operation
quarkus-langchain4j copied to clipboard

Support for AWS bedrock

Open ginccc opened this issue 1 year ago • 5 comments

Hi there!

Are there any plans to support the langchain4j AWS bedrock integrations? Would be great if it could be added at some point..

ginccc avatar May 20 '24 13:05 ginccc

Definitely!

geoand avatar May 20 '24 14:05 geoand

I would like to contribute on this issue. Is there any specific process of this?

abhilashapractice avatar May 24 '24 04:05 abhilashapractice

Not that I know of

geoand avatar May 31 '24 08:05 geoand

some news on that issue? How to contribute?

rndtavares avatar Jul 22 '24 20:07 rndtavares

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.

geoand avatar Jul 23 '24 05:07 geoand

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.

holomekc avatar Mar 16 '25 01:03 holomekc