Dhairya-007 opened a new pull request, #30055:
URL: https://github.com/apache/camel/pull/30055

   ## Problem
   
   `CamelLangChain4jChatAugmentedData` is documented as a `String`:
   
   ```java
   @Metadata(description = "Augmented Data for RAG", javaType = "String")
   public static final String AUGMENTED_DATA = 
"CamelLangChain4jChatAugmentedData";
   ```
   
   The producer reads it as a `List` of langchain4j `Content` and hands it 
straight to a `ContentInjector`:
   
   ```java
   private ChatMessage addAugmentedData(ChatMessage chatMessage, Exchange 
exchange) {
       // check if there's any augmented data
       List<Content> augmentedData = exchange.getIn().getHeader(AUGMENTED_DATA, 
List.class);
   
       // inject data
       if (augmentedData != null && augmentedData.size() != 0) {
           ContentInjector contentInjector = new DefaultContentInjector();
           // inject with new List of Contents
           return contentInjector.inject(augmentedData, chatMessage);
   ```
   
   and the component's own aggregator is what fills it, converting the 
retrieved Strings into `Content` precisely because `String` is *not* what the 
header carries:
   
   ```java
   // create a list of contents from the retrieved Strings
   List<Content> newContents = newAugmentedData.get().stream()
           .map(DefaultContent::new)
           .collect(Collectors.toList());
   
   // Get or create the augmented data list from the old exchange
   List<Content> augmentedData = 
Optional.ofNullable(oldExchange.getIn().getHeader(AUGMENTED_DATA, List.class))
           .orElse(new ArrayList<Content>());
   augmentedData.addAll(newContents);
   ...
   oldExchange.getIn().setHeader(AUGMENTED_DATA, augmentedData);
   ```
   
   So a user who follows the catalog and sets a `String` does not get their 
text injected: the value reaches `getHeader(..., List.class)`, and whatever 
comes back is passed to `inject`, which expects `Content`. The one type the 
header is documented as is the one type the code does not accept.
   
   ## Fix
   
   Document the type the producer reads, and say in the description which class 
fills the header:
   
   ```java
   javaType = "java.util.List<dev.langchain4j.rag.content.Content>"
   ```
   
   Metadata only - no behaviour change. The deprecated nested 
`LangChain4jChat.Headers` copy is left alone, since it is 
`@Deprecated(forRemoval = true)` and is not the endpoint's `headersClass`.
   
   The regenerated `langchain4j-chat.json` files are included.
   


-- 
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]

Reply via email to