LangChain4j Chat
Send a message, a prompt template filled with variables, or a conversation to a chat model of LangChain4j and return its answer as text.
What’s inside
-
LangChain4j Chat component, URI syntax:
langchain4j-chat:chatId
Please refer to the above links for usage and configuration details.
Maven coordinates
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-langchain4j-chat-starter</artifactId>
</dependency> Spring Boot Auto-Configuration
Providing a ChatModel
The Camel starter configures the component but does not create a LangChain4j ChatModel. Add a LangChain4j provider starter to create one from application properties. Use the -spring-boot-starter variant with Spring Boot 3 or the -spring-boot4-starter variant with Spring Boot 4. For example, langchain4j-ollama-spring-boot4-starter creates an ollamaChatModel bean that can be referenced with chatModel=#ollamaChatModel.
When exactly one ChatModel is available, Camel autowires it and the chatModel endpoint option can be omitted. See the LangChain4j Spring Boot integration documentation for provider starters, properties, and compatible versions.
The starter supports 14 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
camel.component.langchain4j-chat.api-key | The API key or access token of the provider, when the model is created from the provider (set as accessToken on Hugging Face and gitHubToken on GitHub Models). Setting it for a provider that has none, such as Ollama, fails. | String | |
camel.component.langchain4j-chat.autowired-enabled | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean |
camel.component.langchain4j-chat.base-url | The URL of the provider’s API (http://localhost:11434 for a local Ollama), when the model is created from the provider. Ollama has no default and needs it; OpenAI uses https://api.openai.com/v1 when it is not set. | String | |
camel.component.langchain4j-chat.chat-model | The LangChain4j ChatModel that answers the messages, such as an OpenAiChatModel or OllamaChatModel bean. Autowired when the registry has exactly one ChatModel. When it is not set, the model is created from provider or customProvider; with neither, the producer fails to start. The option is a dev.langchain4j.model.chat.ChatModel type. | ChatModel | |
camel.component.langchain4j-chat.chat-operation | What the producer sends to the chat model. CHAT_SINGLE_MESSAGE sends the body as one message: a ChatMessage as it is, any other body as the text of a UserMessage. CHAT_SINGLE_MESSAGE_WITH_PROMPT fills the PromptTemplate in the CamelLangChain4jChatPromptTemplate header with the variables of the Map body, and sends the result as a UserMessage. CHAT_MULTIPLE_MESSAGES sends the List of ChatMessage in the body in one request, such as a SystemMessage and the conversation so far. | chat-single-message | LangChain4jChatOperations |
camel.component.langchain4j-chat.configuration | The configuration shared by the endpoints. Each endpoint starts from a copy of it. The option is a org.apache.camel.component.langchain4j.chat.LangChain4jChatConfiguration type. | LangChain4jChatConfiguration | |
camel.component.langchain4j-chat.custom-provider | The fully qualified class name of the LangChain4j chat model class of a provider that is not listed in provider (dev.langchain4j.model.jlama.JlamaChatModel), created from the options here through its static builder() as a listed provider is. Set either provider or customProvider; setting both fails. | String | |
camel.component.langchain4j-chat.enabled | Whether to enable auto configuration of the langchain4j-chat component. This is enabled by default. | Boolean | |
camel.component.langchain4j-chat.lazy-start-producer | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean |
camel.component.langchain4j-chat.model-name | The name of the model at the provider (qwen2.5, gpt-4o-mini, …), when the model is created from the provider. It is set under the name that the builder of the provider uses for it, such as modelId on Hugging Face. | String | |
camel.component.langchain4j-chat.model-properties | Provider-specific properties of the model, set on the model’s builder as they are (model.numPredict=512 for Ollama, model.maxTokens=1024 for OpenAI), when the model is created from the provider. A property that the builder does not have fails when the endpoint is created. This is a multi-value option with prefix: model. | Object> | |
camel.component.langchain4j-chat.provider | The LangChain4j provider of the chat model, to create the model from the options here (modelName, baseUrl, apiKey, temperature, timeout, and provider-specific model.* properties) instead of a ChatModel bean. The LangChain4j module of the provider (dev.langchain4j:langchain4j-ollama, …) must be on the classpath; the Camel CLI downloads it. Endpoints with the same model options share one model. Ignored when chatModel is set, also when it is autowired. For a provider not listed, set customProvider instead. | String | |
camel.component.langchain4j-chat.temperature | The sampling temperature of the model, when the model is created from the provider: lower values give more focused and repeatable answers, higher values more varied ones. The accepted range depends on the provider (0.0 to 2.0 on OpenAI). The provider’s default when not set. | Double | |
camel.component.langchain4j-chat.timeout | The timeout of the HTTP requests to the provider (30s, 2m), when the model is created from the provider. OpenAI and Ollama use it as both the connect and the read timeout; when it is not set, they wait 15 seconds to connect and 60 seconds for the answer. | Duration |