AI / LangChain4j interview questions
What LLM providers does LangChain4j support and how do you switch between them?
LangChain4j supports a wide range of LLM providers, both cloud-based and local, through its modular dependency design. Each provider is a separate Maven module that implements the core ChatLanguageModel and optionally EmbeddingModel, StreamingChatLanguageModel, and ImageModel interfaces.
| Provider | Artifact | Notable Models |
|---|---|---|
| OpenAI | langchain4j-open-ai | GPT-4o, GPT-4 Turbo, o1, o1-mini |
| Azure OpenAI | langchain4j-azure-open-ai | OpenAI models on Azure endpoints |
| Anthropic | langchain4j-anthropic | Claude 3.5, Claude 3 Opus/Sonnet/Haiku |
| Google Vertex AI | langchain4j-vertex-ai-gemini | Gemini 1.5 Pro, Gemini 1.5 Flash |
| Mistral AI | langchain4j-mistral-ai | Mistral Large, Codestral |
| Ollama | langchain4j-ollama | Llama 3, Mistral, Phi-3 (local) |
| HuggingFace | langchain4j-hugging-face | Open-source models via HF Inference |
| Amazon Bedrock | langchain4j-bedrock | Claude, Llama on Bedrock |
| Groq | langchain4j-open-ai (compatible) | OpenAI-compatible fast inference |
Switching providers is entirely a configuration concern — your AI Services interface and application logic do not change:
// OpenAI
ChatLanguageModel model = OpenAiChatModel.builder()
.apiKey("sk-...").modelName("gpt-4o").build();
// Switch to Anthropic — same interface, different builder
ChatLanguageModel model = AnthropicChatModel.builder()
.apiKey("sk-ant-...").modelName("claude-3-5-sonnet-20241022").build();
// Same AI Services usage for both
Assistant assistant = AiServices.builder(Assistant.class)
.chatLanguageModel(model).build();
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
