davsclaus opened a new pull request, #26613: URL: https://github.com/apache/camel/pull/26613
## Description Steps 3 and 4 of [CAMEL-24820](https://issues.apache.org/jira/browse/CAMEL-24820), on top of #26611 (steps 1 and 2 are not LangChain4j specific, so this is a separate PR; the base branch is #26611's and will be switched to `main` once that merges). The chat model of `langchain4j-chat`, the chat model that drives `langchain4j-agent`, and the embedding model of `langchain4j-embeddings` can be declared by their **provider** and the options every provider has, without a bean of the provider's model class: ```properties camel.component.langchain4j-chat.provider = ollama camel.component.langchain4j-chat.model-name = qwen2.5 camel.component.langchain4j-chat.base-url = http://localhost:11434 ``` ```yaml - to: uri: langchain4j-agent:assistant parameters: provider: openai apiKey: "{{openai.api.key}}" modelName: gpt-4o-mini timeout: 30s model.maxTokens: 1024 tags: support ``` Options (on the component and the endpoint): `provider`, `modelName`, `baseUrl`, `apiKey` (secret), `temperature`, `timeout`, and `model.*` for provider-specific builder properties. The provider is a short name — `ollama`, `openai`, `anthropic`, `azure-openai`, `mistral`, `gemini`, `vertex-ai`, `github`, `hugging-face` (with the obvious aliases) — or the fully qualified class name of any model class with a `builder()`. ### Why component options rather than `#class:` on `chat-model` (step 3 as written) - `camel.component.langchain4j-chat.chat-model = #class:…OllamaChatModel` does create the model after #26611, but only with builder defaults: component option binding has nowhere to hang nested `chat-model.base-url` on a builder before it is built, and doing that generically in property binding is invasive. - Ordinary component options land in the catalog, the docs tables, `camel validate` and the MCP tools for free, so a model can also spell them wrong and be told. ### How the dependency follows the provider (step 4) `LangChain4jModelFactory` (new, in `camel-langchain4j-core`, now a dependency of the three components) resolves the model class through the CamelContext class resolver. `camel run` already maps `dev.langchain4j.model.<provider>` packages to `dev.langchain4j:langchain4j-<provider>` in `camel-main-known-dependencies.properties` and downloads on class resolution, so no Camel JBang change is needed; when the module is missing outside JBang the error names the artifact. ### Details - The common options are set under the name the provider's builder uses (`apiKey` → `accessToken` on Hugging Face, `gitHubToken` on GitHub Models; `modelName` → `modelId` / `deploymentName`; `baseUrl` → `endpoint`). An option the provider does not have (an `apiKey` for Ollama), or a `model.*` property the builder does not have, fails naming what the builder accepts. - Endpoints with the same provider options share one model instance (cached per component by the spec record). - The agent is created as with an `AgentConfiguration` holding only the model (no memory); `agent`, `agentFactory` or an autowired `agentConfiguration` take precedence, as does a configured `chatModel`/`embeddingModel`. - `langchain4j-embeddings`' `embeddingModel` is no longer marked required, as the provider is the alternative. - Docs: a "Configuring the model by provider" section on the three component pages; catalog copies updated. ## Tests - `camel-langchain4j-core`: `LangChain4jModelFactoryTest` — real `OllamaChatModel`/`OllamaEmbeddingModel` (test-scoped `langchain4j-ollama`), alias mapping via a Hugging-Face-shaped test model, `model.*` pass-through, and the error messages (option the provider lacks, builder property it lacks, unknown provider, module not on the classpath, provider without embeddings, class of the wrong kind). - `LangChain4jChatProviderTest`, `LangChain4jAgentProviderTest`, `LangChain4jEmbeddingsProviderTest` — endpoint options, component options shared across endpoints, a configured bean winning, and the builder error surfacing through endpoint creation. - Unit test suites of the four modules green (core 9, chat 10, agent 74, embeddings 8); `-Psourcecheck` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
