Claus Ibsen created CAMEL-24820:
-----------------------------------

             Summary: Make LangChain4j models easy to declare in YAML and 
properties: builder inference, component-level model, validator hints
                 Key: CAMEL-24820
                 URL: https://issues.apache.org/jira/browse/CAMEL-24820
             Project: Camel
          Issue Type: Improvement
          Components: camel-jbang, camel-yaml-dsl, camel-ai
            Reporter: Claus Ibsen


Using camel-langchain4j-chat from the YAML DSL is harder than it should be. A 
LangChain4j model has no public constructor; it is built through a nested 
builder, so the only way to declare one today without Java is:

{code:yaml}
- beans:
    - name: chatModel
      type: dev.langchain4j.model.ollama.OllamaChatModel
      builderClass: 
dev.langchain4j.model.ollama.OllamaChatModel$OllamaChatModelBuilder
      builderMethod: build
      properties:
        baseUrl: "{{ollama.base.url}}"
        modelName: "{{ollama.model}}"
{code}

A user has to know that LangChain4j models come from builders, the exact name 
of a nested builder class with a $ in it, and that the method is called build. 
None of that is Camel knowledge, and when they get it wrong the error is a 
reflection exception rather than a hint. This came up while writing the 
langchain4j-chat example for camel-jbang-examples (CAMEL-24808).

Proposal, cheapest first:

# *Builder inference in bean declarations.* When a bean type has no usable 
public constructor but a public static builder() method, call it and use 
build() as the default builder method. Then the declaration is type plus 
properties; builderClass and builderMethod stay as overrides for the odd cases. 
This is generic and helps every builder-style library, not only LangChain4j.
# *Validator hint.* The source validator (camel validate, the MCP server 
validate tool) should recognise a bean type without a public constructor and 
say: this class is built through a builder, add builderClass and builderMethod 
(or, once 1 exists, that the builder is inferred and which properties the 
builder accepts).
# *Component-level model.* Let camel.component.langchain4j-chat.chat-model 
accept the #class: syntax like any other bean property, with the builder 
inference behind it, so application.properties alone configures the model and 
the route is just langchain4j-chat:chatId. Same for langchain4j-embeddings, 
langchain4j-agent and the other langchain4j components that take a model bean.
# *Provider shortcuts.* camel.langchain4j.chat.provider=ollama with base-url 
and model keys, mapping to the right builder for the common providers (ollama, 
openai, anthropic, ...). This also gives Camel JBang a way to add the right 
langchain4j-* dependency from the provider name instead of from a class name.

1 and 2 remove most of the pain without new configuration surface; 3 and 4 are 
the follow-ups.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to