A beginner-friendly guide to building Generative AI applications in Java using LangChain4j. Covers calling the OpenAI Chat API directly via Java's HttpClient, then simplifying that with LangChain4j's high-level abstraction. Also shows how to run LLMs locally with Ollama and how to spin up Ollama in a Docker container using Testcontainers for cost-free local development and testing.
Table of contents
Introduction to Generative AIGetting Started with OpenAI using JavaUsing LangChain4j to interact with OpenAIRunning a LLM model locally using OllamaWorking with Ollama using LangChain4j and TestcontainersConclusionSort: