zbendhiba commented on code in PR #13341:
URL: https://github.com/apache/camel/pull/13341#discussion_r1523800836


##########
components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatProducer.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.chat;
+
+import java.util.List;
+import java.util.Map;
+
+import dev.langchain4j.data.message.AiMessage;
+import dev.langchain4j.data.message.ChatMessage;
+import dev.langchain4j.model.chat.ChatLanguageModel;
+import dev.langchain4j.model.input.Prompt;
+import dev.langchain4j.model.input.PromptTemplate;
+import dev.langchain4j.model.output.Response;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.NoSuchHeaderException;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangchainChatProducer extends DefaultProducer {
+
+    private final LangchainChatEndpoint endpoint;
+
+    private ChatLanguageModel chatLanguageModel;
+
+    public LangchainChatProducer(LangchainChatEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+
+        var operation = this.endpoint.getConfiguration().getChatOperation();
+
+        if (LangchainChatOperations.CHAT_SINGLE_MESSAGE.equals(operation)) {
+            processSingleMessage(exchange);
+        } else if 
(LangchainChatOperations.CHAT_SINGLE_MESSAGE_WITH_PROMPT.equals(operation)) {
+            processSingleMessageWithPrompt(exchange);
+        } else if 
(LangchainChatOperations.CHAT_MULTIPLE_MESSAGES.equals(operation)) {
+            processMultipleMessages(exchange);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void processSingleMessageWithPrompt(Exchange exchange) throws 
NoSuchHeaderException, InvalidPayloadException {
+        final String promptTemplate = 
exchange.getIn().getHeader(LangchainChat.Headers.PROMPT_TEMPLATE, String.class);
+        if (promptTemplate == null) {
+            throw new NoSuchHeaderException("The action is a required header", 
exchange, LangchainChat.Headers.PROMPT_TEMPLATE);

Review Comment:
   yes nice catch



-- 
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: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to