LangChain4j
LangChain4j Adapter
Section titled “LangChain4j Adapter”AiSupport implementation backed by LangChain4j StreamingChatLanguageModel. When this JAR is on the classpath, @AiEndpoint automatically uses LangChain4j for streaming.
Maven Coordinates
Section titled “Maven Coordinates”<dependency> <groupId>org.atmosphere</groupId> <artifactId>atmosphere-langchain4j</artifactId> <version>LATEST</version> <!-- check Maven Central for latest --></dependency>How It Works
Section titled “How It Works”Drop the dependency alongside atmosphere-ai and the framework auto-detects it via ServiceLoader:
@AiEndpoint(path = "/ai/chat", systemPrompt = "You are a helpful assistant")public class MyChat {
@Prompt public void onPrompt(String message, StreamingSession session) { session.stream(message); // uses LangChain4j automatically }}The LangChain4jAiSupport implementation has priority 100, which takes precedence over the built-in client (priority 0).
Direct Usage
Section titled “Direct Usage”For full control, use LangChain4jStreamingAdapter directly:
var session = StreamingSessions.start(resource);model.chat(ChatMessage.userMessage(prompt), new AtmosphereStreamingResponseHandler(session));AtmosphereStreamingResponseHandler
Section titled “AtmosphereStreamingResponseHandler”Bridges LangChain4j’s StreamingChatResponseHandler to Atmosphere’s StreamingSession:
| LangChain4j Callback | StreamingSession Action |
|---|---|
onPartialResponse(text) | session.send(text) |
onCompleteResponse(response) | session.complete() |
onError(throwable) | session.error(message) |
Spring Boot Auto-Configuration
Section titled “Spring Boot Auto-Configuration”AtmosphereLangChain4jAutoConfiguration bridges a Spring-managed StreamingChatLanguageModel bean to the LangChain4jAiSupport SPI automatically.
Samples
Section titled “Samples”- Spring Boot LangChain4j Chat — complete example with LangChain4j
See Also
Section titled “See Also”- AI Integration —
AiSupportSPI,@AiEndpoint, filters, routing - Spring AI Adapter
- Google ADK Adapter
- Embabel Adapter