All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.langchain4j.auth.ModelAuthProvider Maven / Gradle / Ivy

There is a newer version: 0.21.0
Show newest version
package io.quarkiverse.langchain4j.auth;

import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.spi.CDI;

import io.quarkiverse.langchain4j.ModelName;

public interface ModelAuthProvider {
    String getAuthorization(Input input);

    interface Input {
        String method();

        URI uri();

        Map> headers();
    }

    static Optional resolve(String modelName) {
        Instance beanInstance = modelName == null
                ? CDI.current().select(ModelAuthProvider.class)
                : CDI.current().select(ModelAuthProvider.class, ModelName.Literal.of(modelName));

        //get the first one without causing a bean1 resolution exception
        ModelAuthProvider authorizer = null;
        for (var handle : beanInstance.handles()) {
            authorizer = handle.get();
            break;
        }
        return Optional.ofNullable(authorizer);
    }

    static Optional resolve() {
        return resolve(null);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy