Large Language Models
Large Language Models (LLMs) are advanced AI systems designed to comprehend, generate, and manipulate human language, enabling a wide array of natural language processing tasks. These models utilize vast amounts of data to learn complex patterns and nuances within human language, enabling tasks like text generation, translation, and sentiment analysis. LLMs, such as GPT-3 by OpenAI and BERT by Google, have substantially improved the understanding and generation of human language. They serve as the backbone for chatbots, content generation, language translation, and even personalized content recommendation systems. LLMs can be trained on colossal datasets, allowing them to understand context, grammar, and semantics, delivering responses that mimic human-like language. They’re revolutionizing various industries, from customer service (with chatbots) to content creation and summarization for journalism or data analysis. With their ability to understand the context and nuances of language, LLMs enable the automation of tasks that previously required human understanding.
The size and complexity of these models demand significant computational resources for both training and deployment. Ethical concerns and biases within LLMs are topics of ongoing discussion and research within the AI community. Continued research and development in LLMs are constantly pushing the boundaries of what AI can achieve in language understanding and generation.
LLMs are a core component of the Quarkus LangChain4j extension. The extension does not serve its own LLMs, but rather provides a standard interface for interacting with many different LLMs such as OpenAI GPT-3/4, Hugging Face, Ollama, and Jlama. This interface is designed to be simple and intuitive, allowing developers to quickly integrate LLMs into their applications.
Note that each LLM has a different feature set. Please check the specific documentation for the LLM you are using to see what features are available:
Access to LLMs
To access LLMs that are hosted in the cloud, AI Services must submit API keys or access tokens as bearer access tokens using an HTTP Authorization header, for example: Authorization: Bearer <API key>
.
API key is the main token type that can be used to access remote LLMs and you can configure it for every supported model that must be accessed with an API key, for example:
# Access OpenAI with API key
quarkus.langchain4j.openai.api-key=${OPENAI_API_KEY}
# Access AI Gemini with API key
quarkus.langchain4j.ai.gemini.api-key=${AI_GEMINI_API_KEY}
Model providers such as Google AI Gemini, Google Vertex Gemini and Azure OpenAI can also accept access tokens instead of API keys.
You can register a custom io.quarkiverse.langchain4j.auth.ModelAuthProvider
to load tokens or API keys from the database or other sources, for example:
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkiverse.langchain4j.auth.ModelAuthProvider;
@ApplicationScoped
public static class AzureOpenAiAuthProvider implements ModelAuthProvider {
@Override
public String getAuthorization(Input input) { (1)
String token = getToken(input);
return "Bearer " + token;
}
private String getToken(Input input) {
// ...
}
}
1 | Represents current HTTP request URI, method and headers |
When your Quarkus LangChain4j AI service application that uses one of the model provides that can accept access tokens requires an OpenId Connect or OAuth2 authorization code flow login, for example, with Google or Azure, these model providers can propagate the acquired access token to access LLM on the authenticated user’s behalf.
All you need to do to achieve it is to add the quarkus-langchain4j-oidc-model-auth-provider
dependency:
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-oidc-model-auth-provider</artifactId>
</dependency>