You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zb...@apache.org on 2024/03/14 08:28:13 UTC
(camel) branch main updated: CAMEL-20095 : add langchain component (#13341)
This is an automated email from the ASF dual-hosted git repository.
zbendhiba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 04ca9696e0a CAMEL-20095 : add langchain component (#13341)
04ca9696e0a is described below
commit 04ca9696e0acacccafc6b4ddf7756c5e6566d864
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Thu Mar 14 09:28:07 2024 +0100
CAMEL-20095 : add langchain component (#13341)
Co-authored-by: Luca Burgazzoli <lb...@gmail.com>
---
bom/camel-bom/pom.xml | 10 ++
catalog/camel-allcomponents/pom.xml | 10 ++
components/camel-ai/camel-langchain-chat/pom.xml | 66 +++++++
.../chat/LangchainChatComponentConfigurer.java | 82 +++++++++
.../chat/LangchainChatConfigurationConfigurer.java | 55 ++++++
.../chat/LangchainChatEndpointConfigurer.java | 66 +++++++
.../chat/LangchainChatEndpointUriFactory.java | 71 ++++++++
.../camel/component/chat/langchain-chat.json | 41 +++++
.../services/org/apache/camel/component.properties | 7 +
.../org/apache/camel/component/langchain-chat | 2 +
.../camel/configurer/langchain-chat-component | 2 +
.../camel/configurer/langchain-chat-endpoint | 2 +
...camel.component.chat.LangchainChatConfiguration | 2 +
.../camel/urifactory/langchain-chat-endpoint | 2 +
.../main/java/docs/langchain-chat-component.adoc | 149 ++++++++++++++++
.../apache/camel/component/chat/LangchainChat.java | 32 ++++
.../component/chat/LangchainChatComponent.java | 66 +++++++
.../component/chat/LangchainChatConfiguration.java | 75 ++++++++
.../component/chat/LangchainChatEndpoint.java | 74 ++++++++
.../component/chat/LangchainChatOperations.java | 23 +++
.../component/chat/LangchainChatProducer.java | 145 ++++++++++++++++
.../camel/component/chat/LangchainChatIT.java | 190 +++++++++++++++++++++
.../camel/component/chat/OllamaTestSupport.java | 50 ++++++
.../src/test/resources/log4j2.properties | 35 ++++
.../camel-ai/camel-langchain-embeddings/pom.xml | 96 +++++++++++
.../LangchainEmbeddingsComponentConfigurer.java | 76 +++++++++
...LangchainEmbeddingsConfigurationConfigurer.java | 49 ++++++
.../LangchainEmbeddingsConverterLoader.java | 56 ++++++
.../LangchainEmbeddingsEndpointConfigurer.java | 60 +++++++
.../LangchainEmbeddingsEndpointUriFactory.java | 70 ++++++++
.../langchain/embeddings/langchain-embeddings.json | 43 +++++
.../services/org/apache/camel/TypeConverterLoader | 2 +
.../services/org/apache/camel/component.properties | 7 +
.../apache/camel/component/langchain-embeddings | 2 +
.../configurer/langchain-embeddings-component | 2 +
.../camel/configurer/langchain-embeddings-endpoint | 2 +
...ain.embeddings.LangchainEmbeddingsConfiguration | 2 +
.../camel/urifactory/langchain-embeddings-endpoint | 2 +
.../langchain/embeddings/langchain-embeddings.json | 43 +++++
.../main/docs/langchain-embeddings-component.adoc | 42 +++++
.../langchain/embeddings/LangchainEmbeddings.java | 43 +++++
.../embeddings/LangchainEmbeddingsComponent.java | 62 +++++++
.../LangchainEmbeddingsConfiguration.java | 52 ++++++
.../embeddings/LangchainEmbeddingsConverter.java | 45 +++++
.../embeddings/LangchainEmbeddingsEndpoint.java | 74 ++++++++
.../embeddings/LangchainEmbeddingsProducer.java | 56 ++++++
.../embeddings/LangchainEmbeddingsComponentIT.java | 120 +++++++++++++
.../LangchainEmbeddingsComponentTest.java | 64 +++++++
.../embeddings/LangchainEmbeddingsTestSupport.java | 58 +++++++
.../src/test/resources/log4j2.properties | 35 ++++
components/camel-ai/pom.xml | 54 ++++++
.../component/qdrant/QdrantConverterLoader.java | 6 +
.../camel/component/qdrant/QdrantConverter.java | 18 ++
components/pom.xml | 1 +
.../modules/ROOT/examples/json/langchain-chat.json | 1 +
.../ROOT/examples/json/langchain-embeddings.json | 1 +
docs/components/modules/ROOT/nav.adoc | 1 +
.../ROOT/pages/langchain-embeddings-component.adoc | 1 +
parent/pom.xml | 11 ++
test-infra/camel-test-infra-ollama/pom.xml | 48 ++++++
.../src/main/resources/META-INF/MANIFEST.MF | 0
.../infra/ollama/commons/OllamaProperties.java | 30 ++++
.../infra/ollama/services/OllamaContainer.java | 64 +++++++
.../services/OllamaLocalContainerService.java | 108 ++++++++++++
.../infra/ollama/services/OllamaRemoteService.java | 51 ++++++
.../test/infra/ollama/services/OllamaService.java | 26 +++
.../ollama/services/OllamaServiceFactory.java | 37 ++++
.../infra/ollama/services/container.properties | 19 +++
test-infra/pom.xml | 1 +
69 files changed, 2898 insertions(+)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index bcc594d68ec..a0d42c33e32 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1282,6 +1282,16 @@
<artifactId>camel-kudu</artifactId>
<version>4.5.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-chat</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-embeddings</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-language</artifactId>
diff --git a/catalog/camel-allcomponents/pom.xml b/catalog/camel-allcomponents/pom.xml
index db4029c69e8..a4f3074ba0a 100644
--- a/catalog/camel-allcomponents/pom.xml
+++ b/catalog/camel-allcomponents/pom.xml
@@ -1092,6 +1092,16 @@
<artifactId>camel-kudu</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-chat</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-embeddings</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-language</artifactId>
diff --git a/components/camel-ai/camel-langchain-chat/pom.xml b/components/camel-ai/camel-langchain-chat/pom.xml
new file mode 100644
index 00000000000..3c7fd63dc50
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>camel-ai-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-langchain-chat</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Camel Langchain</name>
+ <description>Langchain4j Chat component</description>
+
+ <properties>
+ <firstVersion>4.5.0</firstVersion>
+ <supportLevel>Preview</supportLevel>
+ <label>ai</label>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ </dependency>
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-ollama</artifactId>
+ <version>${langchain4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-ollama</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatComponentConfigurer.java b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatComponentConfigurer.java
new file mode 100644
index 00000000000..f68999cb496
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatComponentConfigurer.java
@@ -0,0 +1,82 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.chat;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainChatComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ private org.apache.camel.component.chat.LangchainChatConfiguration getOrCreateConfiguration(LangchainChatComponent target) {
+ if (target.getConfiguration() == null) {
+ target.setConfiguration(new org.apache.camel.component.chat.LangchainChatConfiguration());
+ }
+ return target.getConfiguration();
+ }
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ LangchainChatComponent target = (LangchainChatComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
+ case "chatmodel":
+ case "chatModel": getOrCreateConfiguration(target).setChatModel(property(camelContext, dev.langchain4j.model.chat.ChatLanguageModel.class, value)); return true;
+ case "chatoperation":
+ case "chatOperation": getOrCreateConfiguration(target).setChatOperation(property(camelContext, org.apache.camel.component.chat.LangchainChatOperations.class, value)); return true;
+ case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.chat.LangchainChatConfiguration.class, value)); return true;
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"chatModel"};
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return boolean.class;
+ case "chatmodel":
+ case "chatModel": return dev.langchain4j.model.chat.ChatLanguageModel.class;
+ case "chatoperation":
+ case "chatOperation": return org.apache.camel.component.chat.LangchainChatOperations.class;
+ case "configuration": return org.apache.camel.component.chat.LangchainChatConfiguration.class;
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ LangchainChatComponent target = (LangchainChatComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return target.isAutowiredEnabled();
+ case "chatmodel":
+ case "chatModel": return getOrCreateConfiguration(target).getChatModel();
+ case "chatoperation":
+ case "chatOperation": return getOrCreateConfiguration(target).getChatOperation();
+ case "configuration": return target.getConfiguration();
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatConfigurationConfigurer.java b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatConfigurationConfigurer.java
new file mode 100644
index 00000000000..de1064949a2
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatConfigurationConfigurer.java
@@ -0,0 +1,55 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.chat;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.component.chat.LangchainChatConfiguration;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainChatConfigurationConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ org.apache.camel.component.chat.LangchainChatConfiguration target = (org.apache.camel.component.chat.LangchainChatConfiguration) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "ChatModel": target.setChatModel(property(camelContext, dev.langchain4j.model.chat.ChatLanguageModel.class, value)); return true;
+ case "chatoperation":
+ case "ChatOperation": target.setChatOperation(property(camelContext, org.apache.camel.component.chat.LangchainChatOperations.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "ChatModel": return dev.langchain4j.model.chat.ChatLanguageModel.class;
+ case "chatoperation":
+ case "ChatOperation": return org.apache.camel.component.chat.LangchainChatOperations.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.component.chat.LangchainChatConfiguration target = (org.apache.camel.component.chat.LangchainChatConfiguration) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "ChatModel": return target.getChatModel();
+ case "chatoperation":
+ case "ChatOperation": return target.getChatOperation();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointConfigurer.java b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointConfigurer.java
new file mode 100644
index 00000000000..fde83fe6f9b
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointConfigurer.java
@@ -0,0 +1,66 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.chat;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainChatEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ LangchainChatEndpoint target = (LangchainChatEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "chatModel": target.getConfiguration().setChatModel(property(camelContext, dev.langchain4j.model.chat.ChatLanguageModel.class, value)); return true;
+ case "chatoperation":
+ case "chatOperation": target.getConfiguration().setChatOperation(property(camelContext, org.apache.camel.component.chat.LangchainChatOperations.class, value)); return true;
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"chatModel"};
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "chatModel": return dev.langchain4j.model.chat.ChatLanguageModel.class;
+ case "chatoperation":
+ case "chatOperation": return org.apache.camel.component.chat.LangchainChatOperations.class;
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ LangchainChatEndpoint target = (LangchainChatEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "chatmodel":
+ case "chatModel": return target.getConfiguration().getChatModel();
+ case "chatoperation":
+ case "chatOperation": return target.getConfiguration().getChatOperation();
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointUriFactory.java b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointUriFactory.java
new file mode 100644
index 00000000000..974e9e143f2
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/java/org/apache/camel/component/chat/LangchainChatEndpointUriFactory.java
@@ -0,0 +1,71 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.chat;
+
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.spi.EndpointUriFactory;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+public class LangchainChatEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory {
+
+ private static final String BASE = ":chatId";
+
+ private static final Set<String> PROPERTY_NAMES;
+ private static final Set<String> SECRET_PROPERTY_NAMES;
+ private static final Set<String> MULTI_VALUE_PREFIXES;
+ static {
+ Set<String> props = new HashSet<>(4);
+ props.add("chatId");
+ props.add("chatModel");
+ props.add("chatOperation");
+ props.add("lazyStartProducer");
+ PROPERTY_NAMES = Collections.unmodifiableSet(props);
+ SECRET_PROPERTY_NAMES = Collections.emptySet();
+ MULTI_VALUE_PREFIXES = Collections.emptySet();
+ }
+
+ @Override
+ public boolean isEnabled(String scheme) {
+ return "langchain-chat".equals(scheme);
+ }
+
+ @Override
+ public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException {
+ String syntax = scheme + BASE;
+ String uri = syntax;
+
+ Map<String, Object> copy = new HashMap<>(properties);
+
+ uri = buildPathParameter(syntax, uri, "chatId", null, true, copy);
+ uri = buildQueryParameters(uri, copy, encode);
+ return uri;
+ }
+
+ @Override
+ public Set<String> propertyNames() {
+ return PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> secretPropertyNames() {
+ return SECRET_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> multiValuePrefixes() {
+ return MULTI_VALUE_PREFIXES;
+ }
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/org/apache/camel/component/chat/langchain-chat.json b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/org/apache/camel/component/chat/langchain-chat.json
new file mode 100644
index 00000000000..969a9810cab
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/org/apache/camel/component/chat/langchain-chat.json
@@ -0,0 +1,41 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "langchain-chat",
+ "title": "langchain 4j chat",
+ "description": "Langchain4j Chat component",
+ "deprecated": false,
+ "firstVersion": "4.5.0",
+ "label": "ai",
+ "javaType": "org.apache.camel.component.chat.LangchainChatComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-langchain-chat",
+ "version": "4.5.0-SNAPSHOT",
+ "scheme": "langchain-chat",
+ "extendsScheme": "",
+ "syntax": "langchain-chat:chatId",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false,
+ "remote": true
+ },
+ "componentProperties": {
+ "chatOperation": { "index": 0, "kind": "property", "displayName": "Chat Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.chat.LangchainChatOperations", "enum": [ "CHAT_SINGLE_MESSAGE", "CHAT_SINGLE_MESSAGE_WITH_PROMPT", "CHAT_MULTIPLE_MESSAGES" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "CHAT_SINGLE_MESSAGE", "configurationClass": "org.apache.camel.compone [...]
+ "configuration": { "index": 1, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.chat.LangchainChatConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The configuration." },
+ "lazyStartProducer": { "index": 2, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...]
+ "autowiredEnabled": { "index": 3, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 t [...]
+ "chatModel": { "index": 4, "kind": "property", "displayName": "Chat Model", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "dev.langchain4j.model.chat.ChatLanguageModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.chat.LangchainChatConfiguration", "configurationField": "configuration", "description": "Chat Language Model of type dev.langchain4j.model.chat [...]
+ },
+ "headers": {
+ "CamelLangchainChatPromptTemplate": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The prompt Template.", "constantName": "org.apache.camel.component.chat.LangchainChat$Headers#PROMPT_TEMPLATE" }
+ },
+ "properties": {
+ "chatId": { "index": 0, "kind": "path", "displayName": "Chat Id", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The id" },
+ "chatOperation": { "index": 1, "kind": "parameter", "displayName": "Chat Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.chat.LangchainChatOperations", "enum": [ "CHAT_SINGLE_MESSAGE", "CHAT_SINGLE_MESSAGE_WITH_PROMPT", "CHAT_MULTIPLE_MESSAGES" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "CHAT_SINGLE_MESSAGE", "configurationClass": "org.apache.camel.compon [...]
+ "lazyStartProducer": { "index": 2, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 produc [...]
+ "chatModel": { "index": 3, "kind": "parameter", "displayName": "Chat Model", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "dev.langchain4j.model.chat.ChatLanguageModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.chat.LangchainChatConfiguration", "configurationField": "configuration", "description": "Chat Language Model of type dev.langchain4j.model.cha [...]
+ }
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component.properties
new file mode 100644
index 00000000000..b122443e700
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+components=langchain-chat
+groupId=org.apache.camel
+artifactId=camel-langchain-chat
+version=4.5.0-SNAPSHOT
+projectName=Camel Langchain
+projectDescription=Langchain4j Chat component
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-chat b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-chat
new file mode 100644
index 00000000000..8652d5320ee
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-chat
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.chat.LangchainChatComponent
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-component b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-component
new file mode 100644
index 00000000000..586e71753fa
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-component
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.chat.LangchainChatComponentConfigurer
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-endpoint b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-endpoint
new file mode 100644
index 00000000000..57cbed3ba16
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-chat-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.chat.LangchainChatEndpointConfigurer
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.chat.LangchainChatConfiguration b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.chat.LangchainChatConfiguration
new file mode 100644
index 00000000000..67fe0e1f8d9
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.chat.LangchainChatConfiguration
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.chat.LangchainChatConfigurationConfigurer
diff --git a/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-chat-endpoint b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-chat-endpoint
new file mode 100644
index 00000000000..4b88abb9b54
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-chat-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.chat.LangchainChatEndpointUriFactory
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/docs/langchain-chat-component.adoc b/components/camel-ai/camel-langchain-chat/src/main/java/docs/langchain-chat-component.adoc
new file mode 100644
index 00000000000..b4f67f10f03
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/docs/langchain-chat-component.adoc
@@ -0,0 +1,149 @@
+= Langchain4j Chat Component
+:doctitle: Langchain4j Chat
+:shortname: langchain-chat
+:artifactid: camel-langchain-chat
+:description: Langchain4j Chat
+:since: 4.5
+:supportlevel: Preview
+:tabs-sync-option:
+:component-header: Only producer is supported
+//Manually maintained attributes
+:camel-spring-boot-name: langchain-chat
+
+*Since Camel {since}*
+
+*{component-header}*
+
+The Langchain Chat Component allows you to integrate with any LLM supported by https://github.com/langchain4j/langchain4j[Langchain4j].
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-chat</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+== URI format
+
+[source]
+----
+langchain-chat:chatIdId[?options]
+----
+
+Where *chatId* can be any string to uniquely identify the endpoint
+
+
+// component-configure options: START
+
+// component-configure options: END
+
+// component options: START
+include::partial$component-configure-options.adoc[]
+include::partial$component-endpoint-options.adoc[]
+// component options: END
+
+// endpoint options: START
+
+// endpoint options: END
+
+include::spring-boot:partial$starter.adoc[]
+
+== Using a specific Chat Model
+The Camel Langchain chat component provides an abstraction for interacting with various types of Large Language Models (LLMs) supported by https://github.com/langchain4j/langchain4j[Langchain4j].
+
+To integrate with a specific Large Language Model, users should follow these steps:
+
+=== Example of Integrating with OpenAI
+Add the dependency for Langchain4j OpenAI support:
+
+[source,xml]
+----
+<dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-open-ai</artifactId>
+ <version>x.x.x</version>
+</dependency>
+----
+
+Init the OpenAI Chat Language Model, add add it to the Camel Registry:
+[source, java]
+----
+ChatLanguageModel model = OpenAiChatModel.builder()
+ .apiKey(openApiKey)
+ .modelName(GPT_3_5_TURBO)
+ .temperature(0.3)
+ .timeout(ofSeconds(3000))
+ .build();
+context.getRegistry().bind("chatModel", model);
+----
+
+Use the model in the Camel Langchain Chat Producer
+[source, java]
+----
+ from("direct:chat")
+ .to("langchain-chat:test?chatModel=#chatModel")
+
+----
+
+[NOTE]
+====
+To switch to another Large Language Model and its corresponding dependency, simply replace the `langchain4j-open-ai` dependency with the appropriate dependency for the desired model. Update the initialization parameters accordingly in the code snippet provided above.
+====
+
+== Send a prompt with variables
+To send a prompt with variables, use the Operation type `LangchainChatOperations.CHAT_SINGLE_MESSAGE_WITH_PROMPT`.
+This operation allows you to send a single prompt message with dynamic variables, which will be replaced with values provided in the request.
+
+Example of route :
+[source, java]
+----
+ from("direct:chat")
+ .to("langchain-chat:test?chatModel=#chatModel&chatOperation=CHAT_SINGLE_MESSAGE_WITH_PROMPT")
+
+----
+
+Example of usage:
+[source, java]
+----
+var promptTemplate = "Create a recipe for a {{dishType}} with the following ingredients: {{ingredients}}";
+
+Map<String, Object> variables = new HashMap<>();
+variables.put("dishType", "oven dish");
+variables.put("ingredients", "potato, tomato, feta, olive oil");
+
+String response = template.requestBodyAndHeader("direct:chat", variables,
+ LangchainChat.Headers.PROMPT_TEMPLATE, promptTemplate, String.class);
+----
+
+== Chat with history
+You can send a new prompt along with the chat message history by passing all messages in a list of type `dev.langchain4j.data.message.ChatMessage`.
+Use the Operation type `LangchainChatOperations.CHAT_MULTIPLE_MESSAGES`.
+This operation allows you to continue the conversation with the context of previous messages.
+
+Example of route :
+[source, java]
+----
+ from("direct:chat")
+ .to("langchain-chat:test?chatModel=#chatModel&chatOperation=CHAT_MULTIPLE_MESSAGES")
+
+----
+
+Example of usage:
+[source, java]
+----
+List<ChatMessage> messages = new ArrayList<>();
+messages.add(new SystemMessage("You are asked to provide recommendations for a restaurant based on user reviews."));
+// Add more chat messages as needed
+
+String response = template.requestBody("direct:send-multiple", messages, String.class);
+----
+
+
+
+
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChat.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChat.java
new file mode 100644
index 00000000000..79c711cd57d
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChat.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.camel.spi.Metadata;
+
+public class LangchainChat {
+
+ public static final String SCHEME = "langchain-chat";
+
+ private LangchainChat() {
+ }
+
+ public static class Headers {
+ @Metadata(description = "The prompt Template.", javaType = "String")
+ public static final String PROMPT_TEMPLATE = "CamelLangchainChatPromptTemplate";
+ }
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatComponent.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatComponent.java
new file mode 100644
index 00000000000..17ce89c93a4
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatComponent.java
@@ -0,0 +1,66 @@
+/*
+ * 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.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+
+import static org.apache.camel.component.chat.LangchainChat.SCHEME;
+
+@Component(SCHEME)
+public class LangchainChatComponent extends DefaultComponent {
+
+ @Metadata
+ LangchainChatConfiguration configuration;
+
+ public LangchainChatComponent() {
+ this(null);
+ }
+
+ public LangchainChatComponent(CamelContext context) {
+ super(context);
+ this.configuration = new LangchainChatConfiguration();
+
+ }
+
+ public LangchainChatConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The configuration.
+ */
+ public void setConfiguration(LangchainChatConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+
+ LangchainChatConfiguration langchainChatConfiguration = this.configuration.copy();
+
+ Endpoint endpoint = new LangchainChatEndpoint(uri, this, remaining, langchainChatConfiguration);
+
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatConfiguration.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatConfiguration.java
new file mode 100644
index 00000000000..3d9e4236dd4
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatConfiguration.java
@@ -0,0 +1,75 @@
+/*
+ * 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 dev.langchain4j.model.chat.ChatLanguageModel;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangchainChatConfiguration implements Cloneable {
+
+ @UriParam
+ @Metadata(required = true, defaultValue = "CHAT_SINGLE_MESSAGE")
+ private LangchainChatOperations chatOperation = LangchainChatOperations.CHAT_SINGLE_MESSAGE;
+
+ @UriParam(label = "advanced")
+ @Metadata(autowired = true)
+ private ChatLanguageModel chatModel;
+
+ public LangchainChatConfiguration() {
+ }
+
+ /**
+ * Operation in case of Endpoint of type CHAT. value is one the values of
+ * org.apache.camel.component.langchain.LangchainChatOperations
+ *
+ * @return
+ */
+ public LangchainChatOperations getChatOperation() {
+ return chatOperation;
+ }
+
+ public void setChatOperation(LangchainChatOperations chatOperation) {
+ this.chatOperation = chatOperation;
+ }
+
+ /**
+ * Chat Language Model of type dev.langchain4j.model.chat.ChatLanguageModel
+ *
+ * @return
+ */
+ public ChatLanguageModel getChatModel() {
+ return chatModel;
+ }
+
+ public void setChatModel(ChatLanguageModel chatModel) {
+ this.chatModel = chatModel;
+ }
+
+ public LangchainChatConfiguration copy() {
+ try {
+ return (LangchainChatConfiguration) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatEndpoint.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatEndpoint.java
new file mode 100644
index 00000000000..6d1d7d1e2fa
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatEndpoint.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+
+import static org.apache.camel.component.chat.LangchainChat.SCHEME;
+
+@UriEndpoint(firstVersion = "4.5.0", scheme = SCHEME,
+ title = "langchain 4j chat",
+ syntax = "langchain-chat:chatId", producerOnly = true,
+ category = { Category.AI }, headersClass = LangchainChat.Headers.class)
+public class LangchainChatEndpoint extends DefaultEndpoint {
+
+ @Metadata(required = true)
+ @UriPath(description = "The id")
+ private final String chatId;
+
+ @UriParam
+ private LangchainChatConfiguration configuration;
+
+ public LangchainChatEndpoint(String uri, LangchainChatComponent component, String chatId,
+ LangchainChatConfiguration configuration) {
+ super(uri, component);
+ this.chatId = chatId;
+ this.configuration = configuration;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new LangchainChatProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Cannot consume from an LangchainEndpoint: " + getEndpointUri());
+ }
+
+ /**
+ * Chat ID
+ *
+ * @return
+ */
+ public String getChatId() {
+ return chatId;
+ }
+
+ public LangchainChatConfiguration getConfiguration() {
+ return configuration;
+ }
+
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatOperations.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatOperations.java
new file mode 100644
index 00000000000..217122851ed
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatOperations.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public enum LangchainChatOperations {
+ CHAT_SINGLE_MESSAGE,
+ CHAT_SINGLE_MESSAGE_WITH_PROMPT,
+ CHAT_MULTIPLE_MESSAGES
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatProducer.java b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatProducer.java
new file mode 100644
index 00000000000..ff15e373b09
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/main/java/org/apache/camel/component/chat/LangchainChatProducer.java
@@ -0,0 +1,145 @@
+/*
+ * 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 promptTemplate is a required header", exchange, LangchainChat.Headers.PROMPT_TEMPLATE);
+ }
+
+ Map<String, Object> variables = (Map<String, Object>) exchange.getIn().getMandatoryBody(Map.class);
+
+ var response = sendWithPromptTemplate(promptTemplate, variables);
+
+ populateResponse(response, exchange);
+ }
+
+ private void processSingleMessage(Exchange exchange) throws InvalidPayloadException {
+ final var message = exchange.getIn().getMandatoryBody();
+
+ if (message instanceof String text) {
+ populateResponse(sendMessage(text), exchange);
+ } else if (message instanceof ChatMessage chatMessage) {
+ populateResponse(sendChatMessage(chatMessage), exchange);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private void processMultipleMessages(Exchange exchange) throws InvalidPayloadException {
+ List<ChatMessage> messages = exchange.getIn().getMandatoryBody(List.class);
+ populateResponse(sendListChatMessage(messages), exchange);
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ this.chatLanguageModel = this.endpoint.getConfiguration().getChatModel();
+ ObjectHelper.notNull(chatLanguageModel, "chatLanguageModel");
+ }
+
+ private void populateResponse(String response, Exchange exchange) {
+ exchange.getMessage().setBody(response);
+ }
+
+ /**
+ * Send one simple message
+ *
+ * @param message
+ * @return
+ */
+ public String sendMessage(String message) {
+ return this.chatLanguageModel.generate(message);
+ }
+
+ /**
+ * Send a ChatMessage
+ *
+ * @param chatMessage
+ * @return
+ */
+ private String sendChatMessage(ChatMessage chatMessage) {
+ Response<AiMessage> response = this.chatLanguageModel.generate(chatMessage);
+ return extractAiResponse(response);
+ }
+
+ /**
+ * Send a ChatMessage
+ *
+ * @param chatMessages
+ * @return
+ */
+ private String sendListChatMessage(List<ChatMessage> chatMessages) {
+ Response<AiMessage> response = this.chatLanguageModel.generate(chatMessages);
+ return extractAiResponse(response);
+ }
+
+ private String extractAiResponse(Response<AiMessage> response) {
+ AiMessage message = response.content();
+ return message == null ? null : message.text();
+ }
+
+ public String sendWithPromptTemplate(String promptTemplate, Map<String, Object> variables) {
+ PromptTemplate template = PromptTemplate.from(promptTemplate);
+ Prompt prompt = template.apply(variables);
+ return this.sendMessage(prompt.text());
+ }
+
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/LangchainChatIT.java b/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/LangchainChatIT.java
new file mode 100644
index 00000000000..cc93917dfe5
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/LangchainChatIT.java
@@ -0,0 +1,190 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import dev.langchain4j.data.message.AiMessage;
+import dev.langchain4j.data.message.ChatMessage;
+import dev.langchain4j.data.message.SystemMessage;
+import dev.langchain4j.data.message.UserMessage;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.NoSuchHeaderException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisabledIfSystemProperty(named = "ci.env.name", matches = ".*", disabledReason = "Requires too much network resources")
+public class LangchainChatIT extends OllamaTestSupport {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ this.context.getRegistry().bind("chatModel", chatLanguageModel);
+
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:send-simple-message")
+ .to("langchain-chat:test1?chatModel=#chatModel&chatOperation=CHAT_SINGLE_MESSAGE")
+ .onException(InvalidPayloadException.class) // Handle InvalidPayloadException
+ .handled(true)
+ .to("mock:invalid-payload")
+ .end()
+ .to("mock:response");
+
+ from("direct:send-message-prompt")
+ .to("langchain-chat:test2?chatModel=#chatModel&chatOperation=CHAT_SINGLE_MESSAGE_WITH_PROMPT")
+ .onException(InvalidPayloadException.class) // Handle InvalidPayloadException
+ .handled(true)
+ .to("mock:invalid-payload")
+ .end()
+ .onException(NoSuchHeaderException.class) // Handle NoSuchHeaderException
+ .handled(true)
+ .to("mock:invalid-header")
+ .end()
+ .to("mock:response");
+
+ from("direct:send-multiple")
+ .to("langchain-chat:test2?chatModel=#chatModel&chatOperation=CHAT_MULTIPLE_MESSAGES")
+ .onException(InvalidPayloadException.class) // Handle InvalidPayloadException
+ .handled(true)
+ .to("mock:invalid-payload")
+ .end()
+ .to("mock:response");
+
+ };
+ };
+ }
+
+ @Test
+ void testSendMessage() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:response", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ String response = template.requestBody("direct:send-simple-message", "Hello my name is Darth Vader!", String.class);
+ mockEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ void testSendChatMessage() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:response", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ ChatMessage userMessage = new UserMessage("Hello my name is Darth Vader!");
+
+ String response = template.requestBody("direct:send-simple-message", userMessage,
+ String.class);
+ mockEndpoint.assertIsSatisfied();
+ assertNotNull(response);
+ }
+
+ @Test
+ void testSendEmptyMessage() throws InterruptedException {
+ MockEndpoint mockErrorHandler = this.context.getEndpoint("mock:invalid-payload", MockEndpoint.class);
+ mockErrorHandler.expectedMessageCount(1);
+
+ template.sendBody("direct:send-simple-message", null);
+ // Assert that the error message is routed to the mock error endpoint
+ mockErrorHandler.assertIsSatisfied();
+ }
+
+ @Test
+ void testSendMessageWithPrompt() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:response", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ // Example copied from Langchain4j examples
+ var promptTemplate = "Create a recipe for a {{dishType}} with the following ingredients: {{ingredients}}";
+
+ Map<String, Object> variables = new HashMap<>();
+ variables.put("dishType", "oven dish");
+ variables.put("ingredients", "potato, tomato, feta, olive oil");
+
+ String response = template.requestBodyAndHeader("direct:send-message-prompt", variables,
+ LangchainChat.Headers.PROMPT_TEMPLATE, promptTemplate, String.class);
+ mockEndpoint.assertIsSatisfied();
+
+ assertTrue(response.contains("potato"));
+ assertTrue(response.contains("tomato"));
+ assertTrue(response.contains("feta"));
+ assertTrue(response.contains("olive oil"));
+ }
+
+ @Test
+ void testSendMessageEmptyPrompt() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:invalid-header", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ Map<String, Object> variables = new HashMap<>();
+ variables.put("dishType", "oven dish");
+ variables.put("ingredients", "potato, tomato, feta, olive oil");
+
+ template.sendBody("direct:send-message-prompt", variables);
+ mockEndpoint.assertIsSatisfied();
+
+ }
+
+ @Test
+ void testSendMessageEmptyVariables() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:invalid-payload", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ // Example copied from Langchain4j examples
+ var promptTemplate = "Create a recipe for a {{dishType}} with the following ingredients: {{ingredients}}";
+
+ template.sendBodyAndHeader("direct:send-message-prompt", null,
+ LangchainChat.Headers.PROMPT_TEMPLATE, promptTemplate);
+ mockEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ void testSendMultipleMessages() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:response", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ List<ChatMessage> messages = new ArrayList<>();
+ messages.add(new SystemMessage("You are asked to provide recommendations for a restaurant based on user reviews."));
+ messages.add(new UserMessage("Hello, my name is Karen."));
+ messages.add(new AiMessage("Hello Karen, how can I help you?"));
+ messages.add(new UserMessage("I'd like you to recommend a restaurant for me."));
+ messages.add(new AiMessage("Sure, what type of cuisine are you interested in?"));
+ messages.add(new UserMessage("I'd like Moroccan food."));
+ messages.add(new AiMessage("Sure, do you have a preference for the location?"));
+ messages.add(new UserMessage("Paris, Rue Montorgueil."));
+
+ String response = template.requestBody("direct:send-multiple", messages, String.class);
+ mockEndpoint.assertIsSatisfied();
+
+ assertNotNull(response);
+ }
+
+ @Test
+ void testSendMultipleEmpty() throws InterruptedException {
+ MockEndpoint mockEndpoint = this.context.getEndpoint("mock:invalid-payload", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:send-multiple", null);
+ mockEndpoint.assertIsSatisfied();
+ }
+
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/OllamaTestSupport.java b/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/OllamaTestSupport.java
new file mode 100644
index 00000000000..bf7b551c823
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/test/java/org/apache/camel/component/chat/OllamaTestSupport.java
@@ -0,0 +1,50 @@
+/*
+ * 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 dev.langchain4j.model.chat.ChatLanguageModel;
+import dev.langchain4j.model.ollama.OllamaChatModel;
+import org.apache.camel.test.infra.ollama.services.OllamaService;
+import org.apache.camel.test.infra.ollama.services.OllamaServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static java.time.Duration.ofSeconds;
+
+public class OllamaTestSupport extends CamelTestSupport {
+
+ protected ChatLanguageModel chatLanguageModel;
+
+ @RegisterExtension
+ static OllamaService OLLAMA = OllamaServiceFactory.createService();
+
+ @Override
+ protected void setupResources() throws Exception {
+ super.setupResources();
+
+ chatLanguageModel = createModel();
+ }
+
+ public ChatLanguageModel createModel() {
+ return OllamaChatModel.builder()
+ .baseUrl(OLLAMA.getBaseUrl())
+ .modelName(OLLAMA.getModel())
+ .temperature(0.3)
+ .timeout(ofSeconds(3000))
+ .build();
+ }
+}
diff --git a/components/camel-ai/camel-langchain-chat/src/test/resources/log4j2.properties b/components/camel-ai/camel-langchain-chat/src/test/resources/log4j2.properties
new file mode 100644
index 00000000000..ab0c8f96ef2
--- /dev/null
+++ b/components/camel-ai/camel-langchain-chat/src/test/resources/log4j2.properties
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-langchain-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n
+
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
+# To log to stdout
+#rootLogger.appenderRef.out.ref = out
+
+logger.camel-langchain.name = org.apache.camel.component.langchain
+logger.camel-langchain.level = DEBUG
diff --git a/components/camel-ai/camel-langchain-embeddings/pom.xml b/components/camel-ai/camel-langchain-embeddings/pom.xml
new file mode 100644
index 00000000000..98b2bbfe2f0
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>camel-ai-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-langchain-embeddings</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Camel :: Langchain4j Embedding</name>
+ <description>Langchain4j Embedding</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-core</artifactId>
+ <version>${langchain4j.version}</version>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-direct</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-qdrant</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-embeddings</artifactId>
+ <version>${langchain4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-embeddings-all-minilm-l6-v2</artifactId>
+ <version>${langchain4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test infra -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-qdrant</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentConfigurer.java b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentConfigurer.java
new file mode 100644
index 00000000000..5e85d8beef6
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentConfigurer.java
@@ -0,0 +1,76 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.langchain.embeddings;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainEmbeddingsComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ private org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration getOrCreateConfiguration(LangchainEmbeddingsComponent target) {
+ if (target.getConfiguration() == null) {
+ target.setConfiguration(new org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration());
+ }
+ return target.getConfiguration();
+ }
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ LangchainEmbeddingsComponent target = (LangchainEmbeddingsComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
+ case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration.class, value)); return true;
+ case "embeddingmodel":
+ case "embeddingModel": getOrCreateConfiguration(target).setEmbeddingModel(property(camelContext, dev.langchain4j.model.embedding.EmbeddingModel.class, value)); return true;
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"embeddingModel"};
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return boolean.class;
+ case "configuration": return org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration.class;
+ case "embeddingmodel":
+ case "embeddingModel": return dev.langchain4j.model.embedding.EmbeddingModel.class;
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ LangchainEmbeddingsComponent target = (LangchainEmbeddingsComponent) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "autowiredenabled":
+ case "autowiredEnabled": return target.isAutowiredEnabled();
+ case "configuration": return target.getConfiguration();
+ case "embeddingmodel":
+ case "embeddingModel": return getOrCreateConfiguration(target).getEmbeddingModel();
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfigurationConfigurer.java b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfigurationConfigurer.java
new file mode 100644
index 00000000000..52ca63c4ed2
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfigurationConfigurer.java
@@ -0,0 +1,49 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.langchain.embeddings;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainEmbeddingsConfigurationConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration target = (org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "EmbeddingModel": target.setEmbeddingModel(property(camelContext, dev.langchain4j.model.embedding.EmbeddingModel.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "EmbeddingModel": return dev.langchain4j.model.embedding.EmbeddingModel.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration target = (org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "EmbeddingModel": return target.getEmbeddingModel();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverterLoader.java b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverterLoader.java
new file mode 100644
index 00000000000..c94255693a3
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverterLoader.java
@@ -0,0 +1,56 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.langchain.embeddings;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.DeferredContextBinding;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+@DeferredContextBinding
+public final class LangchainEmbeddingsConverterLoader implements TypeConverterLoader, CamelContextAware {
+
+ private CamelContext camelContext;
+
+ public LangchainEmbeddingsConverterLoader() {
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
+ registerConverters(registry);
+ }
+
+ private void registerConverters(TypeConverterRegistry registry) {
+ addTypeConverter(registry, dev.langchain4j.data.embedding.Embedding.class, float[].class, false,
+ (type, exchange, value) -> org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConverter.toEmbedding((float[]) value));
+ addTypeConverter(registry, dev.langchain4j.data.embedding.Embedding.class, java.util.List.class, false,
+ (type, exchange, value) -> org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConverter.toEmbedding((java.util.List) value));
+ addTypeConverter(registry, dev.langchain4j.data.segment.TextSegment.class, java.lang.String.class, false,
+ (type, exchange, value) -> org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConverter.toTextSegment((java.lang.String) value));
+ }
+
+ private static void addTypeConverter(TypeConverterRegistry registry, Class<?> toType, Class<?> fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) {
+ registry.addTypeConverter(toType, fromType, new SimpleTypeConverter(allowNull, method));
+ }
+
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointConfigurer.java b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointConfigurer.java
new file mode 100644
index 00000000000..a08eb379817
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointConfigurer.java
@@ -0,0 +1,60 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.langchain.embeddings;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LangchainEmbeddingsEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ LangchainEmbeddingsEndpoint target = (LangchainEmbeddingsEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "embeddingModel": target.getConfiguration().setEmbeddingModel(property(camelContext, dev.langchain4j.model.embedding.EmbeddingModel.class, value)); return true;
+ case "lazystartproducer":
+ case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"embeddingModel"};
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "embeddingModel": return dev.langchain4j.model.embedding.EmbeddingModel.class;
+ case "lazystartproducer":
+ case "lazyStartProducer": return boolean.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ LangchainEmbeddingsEndpoint target = (LangchainEmbeddingsEndpoint) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "embeddingmodel":
+ case "embeddingModel": return target.getConfiguration().getEmbeddingModel();
+ case "lazystartproducer":
+ case "lazyStartProducer": return target.isLazyStartProducer();
+ default: return null;
+ }
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointUriFactory.java b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointUriFactory.java
new file mode 100644
index 00000000000..144ee3f4a74
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpointUriFactory.java
@@ -0,0 +1,70 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.langchain.embeddings;
+
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.spi.EndpointUriFactory;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+public class LangchainEmbeddingsEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory {
+
+ private static final String BASE = ":embeddingId";
+
+ private static final Set<String> PROPERTY_NAMES;
+ private static final Set<String> SECRET_PROPERTY_NAMES;
+ private static final Set<String> MULTI_VALUE_PREFIXES;
+ static {
+ Set<String> props = new HashSet<>(3);
+ props.add("embeddingId");
+ props.add("embeddingModel");
+ props.add("lazyStartProducer");
+ PROPERTY_NAMES = Collections.unmodifiableSet(props);
+ SECRET_PROPERTY_NAMES = Collections.emptySet();
+ MULTI_VALUE_PREFIXES = Collections.emptySet();
+ }
+
+ @Override
+ public boolean isEnabled(String scheme) {
+ return "langchain-embeddings".equals(scheme);
+ }
+
+ @Override
+ public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException {
+ String syntax = scheme + BASE;
+ String uri = syntax;
+
+ Map<String, Object> copy = new HashMap<>(properties);
+
+ uri = buildPathParameter(syntax, uri, "embeddingId", null, true, copy);
+ uri = buildQueryParameters(uri, copy, encode);
+ return uri;
+ }
+
+ @Override
+ public Set<String> propertyNames() {
+ return PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> secretPropertyNames() {
+ return SECRET_PROPERTY_NAMES;
+ }
+
+ @Override
+ public Set<String> multiValuePrefixes() {
+ return MULTI_VALUE_PREFIXES;
+ }
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+}
+
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json
new file mode 100644
index 00000000000..a064e3985a3
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json
@@ -0,0 +1,43 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "langchain-embeddings",
+ "title": "Langchain4j Embeddings",
+ "description": "Langchain4j Embeddings",
+ "deprecated": false,
+ "firstVersion": "4.5.0",
+ "label": "ai",
+ "javaType": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-langchain-embeddings",
+ "version": "4.5.0-SNAPSHOT",
+ "scheme": "langchain-embeddings",
+ "extendsScheme": "",
+ "syntax": "langchain-embeddings:embeddingId",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false,
+ "remote": true
+ },
+ "componentProperties": {
+ "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The configuration." },
+ "embeddingModel": { "index": 1, "kind": "property", "displayName": "Embedding Model", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "dev.langchain4j.model.embedding.EmbeddingModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "configurationField": "configuration", "description": "The EmbeddingModel engine to [...]
+ "lazyStartProducer": { "index": 2, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...]
+ "autowiredEnabled": { "index": 3, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 t [...]
+ },
+ "headers": {
+ "CamelLangchainEmbeddingsFinishReason": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "dev.langchain4j.model.output.FinishReason", "enum": [ "STOP", "LENGTH", "TOOL_EXECUTION", "CONTENT_FILTER", "OTHER" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Finish Reason.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#F [...]
+ "CamelLangchainEmbeddingsInputTokenCount": { "index": 1, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Input Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#INPUT_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsOutputTokenCount": { "index": 2, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Output Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#OUTPUT_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsTotalTokenCount": { "index": 3, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Total Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#TOTAL_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsVector": { "index": 4, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "float[]", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A dense vector embedding of a text", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#VECTOR" }
+ },
+ "properties": {
+ "embeddingId": { "index": 0, "kind": "path", "displayName": "Embedding Id", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The id" },
+ "embeddingModel": { "index": 1, "kind": "parameter", "displayName": "Embedding Model", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "dev.langchain4j.model.embedding.EmbeddingModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "configurationField": "configuration", "description": "The EmbeddingModel engine to [...]
+ "lazyStartProducer": { "index": 2, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 produc [...]
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 00000000000..fc38f27562e
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConverterLoader
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component.properties
new file mode 100644
index 00000000000..ebe04257dec
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+components=langchain-embeddings
+groupId=org.apache.camel
+artifactId=camel-langchain-embeddings
+version=4.5.0-SNAPSHOT
+projectName=Camel :: Langchain4j Embedding
+projectDescription=Langchain4j Embedding
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-embeddings b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-embeddings
new file mode 100644
index 00000000000..8fda737c3e7
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/component/langchain-embeddings
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsComponent
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-component b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-component
new file mode 100644
index 00000000000..6518e6cac3a
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-component
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsComponentConfigurer
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-endpoint b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-endpoint
new file mode 100644
index 00000000000..3097b080345
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/langchain-embeddings-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsEndpointConfigurer
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration
new file mode 100644
index 00000000000..16012d394cc
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfigurationConfigurer
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-embeddings-endpoint b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-embeddings-endpoint
new file mode 100644
index 00000000000..ade7ae7ef13
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/services/org/apache/camel/urifactory/langchain-embeddings-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsEndpointUriFactory
diff --git a/components/camel-ai/camel-langchain-embeddings/src/generated/resources/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json
new file mode 100644
index 00000000000..00a08f7f076
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/generated/resources/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json
@@ -0,0 +1,43 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "langchain-embeddings",
+ "title": "Langchain4j Embeddings",
+ "description": "Perform operations on the Qdrant Vector Database.",
+ "deprecated": false,
+ "firstVersion": "4.5.0",
+ "label": "ai",
+ "javaType": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsComponent",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-langchain-embeddings",
+ "version": "4.4.0-SNAPSHOT",
+ "scheme": "langchain-embeddings",
+ "extendsScheme": "",
+ "syntax": "langchain-embeddings:embeddingId",
+ "async": false,
+ "api": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false,
+ "remote": true
+ },
+ "componentProperties": {
+ "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The configuration." },
+ "embeddingModel": { "index": 1, "kind": "property", "displayName": "Embedding Model", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "dev.langchain4j.model.embedding.EmbeddingModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "configurationField": "configuration", "description": "The EmbeddingModel engine to [...]
+ "lazyStartProducer": { "index": 2, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...]
+ "autowiredEnabled": { "index": 3, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 t [...]
+ },
+ "headers": {
+ "CamelLangchainEmbeddingsFinishReason": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "dev.langchain4j.model.output.FinishReason", "enum": [ "STOP", "LENGTH", "TOOL_EXECUTION", "CONTENT_FILTER", "OTHER" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Finish Reason.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#F [...]
+ "CamelLangchainEmbeddingsInputTokenCount": { "index": 1, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Input Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#INPUT_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsOutputTokenCount": { "index": 2, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Output Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#OUTPUT_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsTotalTokenCount": { "index": 3, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Total Token Count.", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#TOTAL_TOKEN_COUNT" },
+ "CamelLangchainEmbeddingsVector": { "index": 4, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "float[]", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A dense vector embedding of a text", "constantName": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddings$Headers#VECTOR" }
+ },
+ "properties": {
+ "embeddingId": { "index": 0, "kind": "path", "displayName": "Embedding Id", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The id" },
+ "embeddingModel": { "index": 1, "kind": "parameter", "displayName": "Embedding Model", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "dev.langchain4j.model.embedding.EmbeddingModel", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsConfiguration", "configurationField": "configuration", "description": "The EmbeddingModel engine to [...]
+ "lazyStartProducer": { "index": 2, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 produc [...]
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/docs/langchain-embeddings-component.adoc b/components/camel-ai/camel-langchain-embeddings/src/main/docs/langchain-embeddings-component.adoc
new file mode 100644
index 00000000000..74d073f649c
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/docs/langchain-embeddings-component.adoc
@@ -0,0 +1,42 @@
+= Langchain4j Embeddings Component
+:doctitle: Langchain4j Embeddings
+:shortname: langchain-embeddings
+:artifactid: camel-langchain-embeddings
+:description: Langchain4j Embeddings
+:since: 4.5
+:supportlevel: Preview
+:tabs-sync-option:
+:component-header: Only producer is supported
+//Manually maintained attributes
+:camel-spring-boot-name: langchain-embeddings
+
+*Since Camel {since}*
+
+*{component-header}*
+
+The Langchain embeddings component provides support to compute embeddings using Langchain4j embeddings.
+
+== URI format
+
+[source]
+----
+langchain-embeddings:embeddingId[?options]
+----
+
+Where *embeddingId* can be any string to uniquely identify the endpoint
+
+
+// component-configure options: START
+
+// component-configure options: END
+
+// component options: START
+include::partial$component-configure-options.adoc[]
+include::partial$component-endpoint-options.adoc[]
+// component options: END
+
+// endpoint options: START
+
+// endpoint options: END
+
+include::spring-boot:partial$starter.adoc[]
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddings.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddings.java
new file mode 100644
index 00000000000..619f2651640
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddings.java
@@ -0,0 +1,43 @@
+/*
+ * 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.langchain.embeddings;
+
+import org.apache.camel.spi.Metadata;
+
+public final class LangchainEmbeddings {
+ public static final String SCHEME = "langchain-embeddings";
+
+ private LangchainEmbeddings() {
+ }
+
+ public static class Headers {
+ @Metadata(description = "The Finish Reason.", javaType = "dev.langchain4j.model.output.FinishReason")
+ public static final String FINISH_REASON = "CamelLangchainEmbeddingsFinishReason";
+
+ @Metadata(description = "The Input Token Count.", javaType = "int")
+ public static final String INPUT_TOKEN_COUNT = "CamelLangchainEmbeddingsInputTokenCount";
+
+ @Metadata(description = "The Output Token Count.", javaType = "int")
+ public static final String OUTPUT_TOKEN_COUNT = "CamelLangchainEmbeddingsOutputTokenCount";
+
+ @Metadata(description = "The Total Token Count.", javaType = "int")
+ public static final String TOTAL_TOKEN_COUNT = "CamelLangchainEmbeddingsTotalTokenCount";
+
+ @Metadata(description = "A dense vector embedding of a text", javaType = "float[]")
+ public static final String VECTOR = "CamelLangchainEmbeddingsVector";
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponent.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponent.java
new file mode 100644
index 00000000000..a55a16b8cf4
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponent.java
@@ -0,0 +1,62 @@
+/*
+ * 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.langchain.embeddings;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+
+@Component(LangchainEmbeddings.SCHEME)
+public class LangchainEmbeddingsComponent extends DefaultComponent {
+ @Metadata
+ private LangchainEmbeddingsConfiguration configuration;
+
+ public LangchainEmbeddingsComponent() {
+ this(null);
+ }
+
+ public LangchainEmbeddingsComponent(CamelContext context) {
+ super(context);
+
+ this.configuration = new LangchainEmbeddingsConfiguration();
+ }
+
+ public LangchainEmbeddingsConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The configuration.
+ */
+ public void setConfiguration(LangchainEmbeddingsConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ LangchainEmbeddingsConfiguration configuration = this.configuration.copy();
+
+ LangchainEmbeddingsEndpoint endpoint = new LangchainEmbeddingsEndpoint(uri, this, remaining, configuration);
+ setProperties(endpoint, parameters);
+
+ return endpoint;
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfiguration.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfiguration.java
new file mode 100644
index 00000000000..70d2c36fe22
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConfiguration.java
@@ -0,0 +1,52 @@
+/*
+ * 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.langchain.embeddings;
+
+import dev.langchain4j.model.embedding.EmbeddingModel;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangchainEmbeddingsConfiguration implements Cloneable {
+
+ @Metadata(required = true, autowired = true)
+ @UriParam
+ private EmbeddingModel embeddingModel;
+
+ public EmbeddingModel getEmbeddingModel() {
+ return embeddingModel;
+ }
+
+ /**
+ * The {@link EmbeddingModel} engine to use.
+ */
+ public void setEmbeddingModel(EmbeddingModel embeddingModel) {
+ this.embeddingModel = embeddingModel;
+ }
+
+ public LangchainEmbeddingsConfiguration copy() {
+ try {
+ return (LangchainEmbeddingsConfiguration) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverter.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverter.java
new file mode 100644
index 00000000000..5b28163e6cc
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsConverter.java
@@ -0,0 +1,45 @@
+/*
+ * 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.langchain.embeddings;
+
+import java.util.List;
+
+import dev.langchain4j.data.embedding.Embedding;
+import dev.langchain4j.data.segment.TextSegment;
+import org.apache.camel.Converter;
+
+/**
+ * Converter methods to convert from / to langchain4j embedding types.
+ */
+@Converter(generateLoader = true)
+public class LangchainEmbeddingsConverter {
+
+ @Converter
+ public static TextSegment toTextSegment(String value) {
+ return TextSegment.from(value);
+ }
+
+ @Converter
+ public static Embedding toEmbedding(float[] value) {
+ return Embedding.from(value);
+ }
+
+ @Converter
+ public static Embedding toEmbedding(List<Float> value) {
+ return Embedding.from(value);
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpoint.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpoint.java
new file mode 100644
index 00000000000..9c657d44096
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsEndpoint.java
@@ -0,0 +1,74 @@
+/*
+ * 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.langchain.embeddings;
+
+import org.apache.camel.Category;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+
+/**
+ * Langchain4j Embeddings
+ */
+@UriEndpoint(firstVersion = "4.5.0", scheme = LangchainEmbeddings.SCHEME, title = "Langchain4j Embeddings",
+ syntax = "langchain4j-embeddings:embeddingId", producerOnly = true, category = {
+ Category.AI
+ }, headersClass = LangchainEmbeddings.Headers.class)
+public class LangchainEmbeddingsEndpoint extends DefaultEndpoint {
+ @Metadata(required = true)
+ @UriPath(description = "The id")
+ private final String embeddingId;
+
+ @UriParam
+ private LangchainEmbeddingsConfiguration configuration;
+
+ public LangchainEmbeddingsEndpoint(
+ String endpointUri,
+ Component component,
+ String embeddingId,
+ LangchainEmbeddingsConfiguration configuration) {
+
+ super(endpointUri, component);
+
+ this.embeddingId = embeddingId;
+ this.configuration = configuration;
+ }
+
+ public LangchainEmbeddingsConfiguration getConfiguration() {
+ return this.configuration;
+ }
+
+ public String getEmbeddingId() {
+ return this.embeddingId;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new LangchainEmbeddingsProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Consumer is not implemented for this component");
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsProducer.java b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsProducer.java
new file mode 100644
index 00000000000..cd0b4d89b73
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/main/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsProducer.java
@@ -0,0 +1,56 @@
+/*
+ * 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.langchain.embeddings;
+
+import dev.langchain4j.data.embedding.Embedding;
+import dev.langchain4j.data.segment.TextSegment;
+import dev.langchain4j.model.embedding.EmbeddingModel;
+import dev.langchain4j.model.output.Response;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+
+public class LangchainEmbeddingsProducer extends DefaultProducer {
+ public LangchainEmbeddingsProducer(LangchainEmbeddingsEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public LangchainEmbeddingsEndpoint getEndpoint() {
+ return (LangchainEmbeddingsEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ final TextSegment in = exchange.getMessage().getMandatoryBody(TextSegment.class);
+ final EmbeddingModel model = getEndpoint().getConfiguration().getEmbeddingModel();
+ final Response<Embedding> result = model.embed(in);
+ final Message message = exchange.getMessage();
+
+ if (result.finishReason() != null) {
+ message.setHeader(LangchainEmbeddings.Headers.FINISH_REASON, result.finishReason());
+ }
+
+ if (result.tokenUsage() != null) {
+ message.setHeader(LangchainEmbeddings.Headers.INPUT_TOKEN_COUNT, result.tokenUsage().inputTokenCount());
+ message.setHeader(LangchainEmbeddings.Headers.OUTPUT_TOKEN_COUNT, result.tokenUsage().outputTokenCount());
+ message.setHeader(LangchainEmbeddings.Headers.TOTAL_TOKEN_COUNT, result.tokenUsage().totalTokenCount());
+ }
+
+ message.setHeader(LangchainEmbeddings.Headers.VECTOR, result.content().vector());
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentIT.java b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentIT.java
new file mode 100644
index 00000000000..75e3180cbe9
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentIT.java
@@ -0,0 +1,120 @@
+/*
+ * 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.langchain.embeddings;
+
+import java.util.Collection;
+
+import dev.langchain4j.model.embedding.AllMiniLmL6V2EmbeddingModel;
+import io.qdrant.client.PointIdFactory;
+import io.qdrant.client.grpc.Collections;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.qdrant.Qdrant;
+import org.apache.camel.component.qdrant.QdrantAction;
+import org.apache.camel.component.qdrant.QdrantComponent;
+import org.apache.camel.test.infra.qdrant.services.QdrantService;
+import org.apache.camel.test.infra.qdrant.services.QdrantServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.apache.camel.component.langchain.embeddings.LangchainEmbeddingsTestSupport.POINT_ID_HEADER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class LangchainEmbeddingsComponentIT extends CamelTestSupport {
+ public static final long POINT_ID = 8;
+ public static final String QDRANT_URI = "qdrant:embeddings";
+
+ @RegisterExtension
+ static QdrantService QDRANT = QdrantServiceFactory.createSingletonService();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ var qc = context.getComponent(Qdrant.SCHEME, QdrantComponent.class);
+ qc.getConfiguration().setHost(QDRANT.getGrpcHost());
+ qc.getConfiguration().setPort(QDRANT.getGrpcPort());
+ qc.getConfiguration().setTls(false);
+
+ context.getRegistry().bind("embedding-model", new AllMiniLmL6V2EmbeddingModel());
+
+ return context;
+ }
+
+ @Test
+ @Order(1)
+ public void createCollection() {
+ Exchange result = fluentTemplate.to(QDRANT_URI)
+ .withHeader(Qdrant.Headers.ACTION, QdrantAction.CREATE_COLLECTION)
+ .withBody(
+ Collections.VectorParams.newBuilder()
+ .setSize(384)
+ .setDistance(Collections.Distance.Cosine).build())
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isNull();
+ }
+
+ @Test
+ @Order(2)
+ public void upsert() {
+ Exchange result = fluentTemplate.to("direct:in")
+ .withBody("hi")
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isNull();
+ }
+
+ @Test
+ @Order(3)
+ public void retrieve() {
+ Exchange result = fluentTemplate.to(QDRANT_URI)
+ .withHeader(Qdrant.Headers.ACTION, QdrantAction.RETRIEVE)
+ .withBody(PointIdFactory.id(POINT_ID))
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isNull();
+
+ assertThat(result.getIn().getBody()).isInstanceOfSatisfying(Collection.class, c -> assertThat(c).hasSize(1));
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:in")
+ .to("langchain-embeddings:test")
+ .setHeader(Qdrant.Headers.ACTION).constant(QdrantAction.UPSERT)
+ .setHeader(POINT_ID_HEADER).constant(POINT_ID)
+ .bean(LangchainEmbeddingsTestSupport.AsPointStruct.class)
+ .to(QDRANT_URI);
+ }
+ };
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentTest.java b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentTest.java
new file mode 100644
index 00000000000..228c91899b9
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsComponentTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.langchain.embeddings;
+
+import dev.langchain4j.data.embedding.Embedding;
+import dev.langchain4j.model.embedding.AllMiniLmL6V2EmbeddingModel;
+import dev.langchain4j.store.embedding.CosineSimilarity;
+import dev.langchain4j.store.embedding.RelevanceScore;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Message;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LangchainEmbeddingsComponentTest extends CamelTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ LangchainEmbeddingsComponent component
+ = context.getComponent(LangchainEmbeddings.SCHEME, LangchainEmbeddingsComponent.class);
+
+ component.getConfiguration().setEmbeddingModel(new AllMiniLmL6V2EmbeddingModel());
+
+ return context;
+ }
+
+ @Test
+ public void testSimpleEmbedding() {
+
+ Message first = fluentTemplate.to("langchain-embeddings:first")
+ .withBody("hi")
+ .request(Message.class);
+
+ Embedding firstEmbedding = first.getHeader(LangchainEmbeddings.Headers.VECTOR, Embedding.class);
+ assertThat(firstEmbedding.vector()).hasSize(384);
+
+ Message second = fluentTemplate.to("langchain-embeddings:second")
+ .withBody("hello")
+ .request(Message.class);
+
+ Embedding secondEmbedding = second.getHeader(LangchainEmbeddings.Headers.VECTOR, Embedding.class);
+ assertThat(secondEmbedding.vector()).hasSize(384);
+
+ double cosineSimilarity = CosineSimilarity.between(firstEmbedding, secondEmbedding);
+ assertThat(RelevanceScore.fromCosineSimilarity(cosineSimilarity)).isGreaterThan(0.9);
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsTestSupport.java b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsTestSupport.java
new file mode 100644
index 00000000000..16b22347c8a
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/test/java/org/apache/camel/component/langchain/embeddings/LangchainEmbeddingsTestSupport.java
@@ -0,0 +1,58 @@
+/*
+ * 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.langchain.embeddings;
+
+import dev.langchain4j.data.embedding.Embedding;
+import dev.langchain4j.data.segment.TextSegment;
+import io.qdrant.client.ValueFactory;
+import io.qdrant.client.VectorsFactory;
+import io.qdrant.client.grpc.Points;
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+
+public class LangchainEmbeddingsTestSupport {
+ public static final String POINT_ID_HEADER = "point.id";
+
+ private LangchainEmbeddingsTestSupport() {
+ }
+
+ // TODO: this should be turned into a proper converter or data type
+ public static class AsPointStruct {
+ @Handler
+ public Points.PointStruct asPointStruct(Exchange e) {
+ Embedding embedding = e.getMessage().getHeader(LangchainEmbeddings.Headers.VECTOR, Embedding.class);
+ TextSegment text = e.getMessage().getBody(TextSegment.class);
+ Points.PointId id = e.getMessage().getHeader(POINT_ID_HEADER, Points.PointId.class);
+
+ var builder = Points.PointStruct.newBuilder();
+ builder.setId(id);
+ builder.setVectors(VectorsFactory.vectors(embedding.vector()));
+
+ if (text != null) {
+ // this is the default for langchain4j
+ // https://github.com/langchain4j/langchain4j/blob/3e432486ffc5cb80861e118cbc974f478c3accfc/langchain4j-qdrant/src/main/java/dev/langchain4j/store/embedding/qdrant/QdrantEmbeddingStore.java#L261
+ builder.putPayload("text_segment", ValueFactory.value(text.text()));
+
+ text.metadata()
+ .asMap()
+ .forEach((key, value) -> builder.putPayload(key, ValueFactory.value(value)));
+ }
+
+ return builder.build();
+ }
+ }
+}
diff --git a/components/camel-ai/camel-langchain-embeddings/src/test/resources/log4j2.properties b/components/camel-ai/camel-langchain-embeddings/src/test/resources/log4j2.properties
new file mode 100644
index 00000000000..8f281ccdf54
--- /dev/null
+++ b/components/camel-ai/camel-langchain-embeddings/src/test/resources/log4j2.properties
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-langchain-embeddings-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n
+
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
+# To log to stdout
+#rootLogger.appenderRef.out.ref = out
+
+logger.camel-langchain-embeddings.name = org.apache.camel.component.langchain.embeddings
+logger.camel-langchain-embeddings.level = DEBUG
diff --git a/components/camel-ai/pom.xml b/components/camel-ai/pom.xml
new file mode 100644
index 00000000000..ccc6ddd2533
--- /dev/null
+++ b/components/camel-ai/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-ai-parent</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Camel :: AI :: Parent</name>
+ <description>Camel AI parent</description>
+
+ <modules>
+ <module>camel-langchain-chat</module>
+ <module>camel-langchain-embeddings</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j</artifactId>
+ <version>${langchain4j.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
diff --git a/components/camel-qdrant/src/generated/java/org/apache/camel/component/qdrant/QdrantConverterLoader.java b/components/camel-qdrant/src/generated/java/org/apache/camel/component/qdrant/QdrantConverterLoader.java
index 67c0d2d2bfe..c6caef710c9 100644
--- a/components/camel-qdrant/src/generated/java/org/apache/camel/component/qdrant/QdrantConverterLoader.java
+++ b/components/camel-qdrant/src/generated/java/org/apache/camel/component/qdrant/QdrantConverterLoader.java
@@ -41,6 +41,12 @@ public final class QdrantConverterLoader implements TypeConverterLoader, CamelCo
}
private void registerConverters(TypeConverterRegistry registry) {
+ addTypeConverter(registry, io.qdrant.client.grpc.Points.PointId.class, java.lang.Long.class, false,
+ (type, exchange, value) -> org.apache.camel.component.qdrant.QdrantConverter.toPointId((java.lang.Long) value));
+ addTypeConverter(registry, io.qdrant.client.grpc.Points.PointId.class, java.util.UUID.class, false,
+ (type, exchange, value) -> org.apache.camel.component.qdrant.QdrantConverter.toPointId((java.util.UUID) value));
+ addTypeConverter(registry, io.qdrant.client.grpc.Points.PointId.class, long.class, false,
+ (type, exchange, value) -> org.apache.camel.component.qdrant.QdrantConverter.toPointId((long) value));
addTypeConverter(registry, io.qdrant.client.grpc.Points.PointsSelector.class, io.qdrant.client.grpc.Points.Condition.class, false,
(type, exchange, value) -> org.apache.camel.component.qdrant.QdrantConverter.toPointSelector((io.qdrant.client.grpc.Points.Condition) value));
addTypeConverter(registry, io.qdrant.client.grpc.Points.PointsSelector.class, io.qdrant.client.grpc.Points.Filter.class, false,
diff --git a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantConverter.java b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantConverter.java
index e2e2b7b8fc9..c872626ea7d 100644
--- a/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantConverter.java
+++ b/components/camel-qdrant/src/main/java/org/apache/camel/component/qdrant/QdrantConverter.java
@@ -21,7 +21,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.UUID;
+import io.qdrant.client.PointIdFactory;
import io.qdrant.client.grpc.Points;
import io.qdrant.client.grpc.Points.Filter;
import io.qdrant.client.grpc.Points.PointId;
@@ -81,4 +83,20 @@ public class QdrantConverter {
.setFilter(filter)
.build();
}
+
+ @Converter
+ public static PointId toPointId(long id) {
+ return PointIdFactory.id(id);
+ }
+
+ @Converter
+ public static PointId toPointId(Long id) {
+ return PointIdFactory.id(id);
+ }
+
+ @Converter
+ public static PointId toPointId(UUID id) {
+ return PointIdFactory.id(id);
+ }
+
}
diff --git a/components/pom.xml b/components/pom.xml
index f9c96cbe9ab..e70bde3d31f 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -75,6 +75,7 @@
<!-- regular modules in alphabetic order -->
<module>camel-activemq</module>
+ <module>camel-ai</module>
<module>camel-amqp</module>
<module>camel-arangodb</module>
<module>camel-as2</module>
diff --git a/docs/components/modules/ROOT/examples/json/langchain-chat.json b/docs/components/modules/ROOT/examples/json/langchain-chat.json
new file mode 120000
index 00000000000..8d7e5e3a5f9
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/json/langchain-chat.json
@@ -0,0 +1 @@
+../../../../../../components/camel-ai/camel-langchain-chat/src/generated/resources/META-INF/org/apache/camel/component/chat/langchain-chat.json
\ No newline at end of file
diff --git a/docs/components/modules/ROOT/examples/json/langchain-embeddings.json b/docs/components/modules/ROOT/examples/json/langchain-embeddings.json
new file mode 120000
index 00000000000..2005cd09014
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/json/langchain-embeddings.json
@@ -0,0 +1 @@
+../../../../../../components/camel-ai/camel-langchain-embeddings/src/generated/resources/META-INF/org/apache/camel/component/langchain/embeddings/langchain-embeddings.json
\ No newline at end of file
diff --git a/docs/components/modules/ROOT/nav.adoc b/docs/components/modules/ROOT/nav.adoc
index 8a45c2c20cd..b48101fb036 100644
--- a/docs/components/modules/ROOT/nav.adoc
+++ b/docs/components/modules/ROOT/nav.adoc
@@ -211,6 +211,7 @@
*** xref:openshift-builds-component.adoc[Openshift Builds]
*** xref:openshift-deploymentconfigs-component.adoc[Openshift Deployment Configs]
** xref:kudu-component.adoc[Kudu]
+** xref:langchain-embeddings-component.adoc[Langchain4j Embeddings]
** xref:language-component.adoc[Language]
** xref:ldap-component.adoc[LDAP]
** xref:ldif-component.adoc[LDIF]
diff --git a/docs/components/modules/ROOT/pages/langchain-embeddings-component.adoc b/docs/components/modules/ROOT/pages/langchain-embeddings-component.adoc
new file mode 120000
index 00000000000..41ef0777511
--- /dev/null
+++ b/docs/components/modules/ROOT/pages/langchain-embeddings-component.adoc
@@ -0,0 +1 @@
+../../../../../components/camel-ai/camel-langchain-embeddings/src/main/docs/langchain-embeddings-component.adoc
\ No newline at end of file
diff --git a/parent/pom.xml b/parent/pom.xml
index 381a9fa4ef1..e16aa7f67a7 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -304,6 +304,7 @@
<kubernetes-client-version>6.10.0</kubernetes-client-version>
<kubernetes-model-version>6.9.2</kubernetes-model-version>
<kudu-version>1.17.0</kudu-version>
+ <langchain4j.version>0.28.0</langchain4j.version>
<leveldbjni-version>1.8</leveldbjni-version>
<leveldb-api-version>0.12</leveldb-api-version>
<leveldb-version>0.12</leveldb-version>
@@ -1694,6 +1695,16 @@
<artifactId>camel-kudu</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-chat</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-langchain-embeddings</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-language</artifactId>
diff --git a/test-infra/camel-test-infra-ollama/pom.xml b/test-infra/camel-test-infra-ollama/pom.xml
new file mode 100644
index 00000000000..191fa247ea2
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>camel-test-infra-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-test-infra-ollama</artifactId>
+ <name>Camel :: Test Infra :: Ollama</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>${testcontainers-version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/test-infra/camel-test-infra-ollama/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-ollama/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/commons/OllamaProperties.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/commons/OllamaProperties.java
new file mode 100644
index 00000000000..374c5ee7ac4
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/commons/OllamaProperties.java
@@ -0,0 +1,30 @@
+/*
+ * 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.test.infra.ollama.commons;
+
+public class OllamaProperties {
+
+ public static final String PORT = "ollama.port";
+ public static final String CONTAINER = "ollama.container";
+ public static final String MODEL = "ollama.model";
+
+ public static final String BASE_URL = "ollama.url";
+
+ private OllamaProperties() {
+
+ }
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaContainer.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaContainer.java
new file mode 100644
index 00000000000..ac94bc3809d
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaContainer.java
@@ -0,0 +1,64 @@
+/*
+ * 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.test.infra.ollama.services;
+
+import java.io.IOException;
+
+import com.github.dockerjava.api.command.InspectContainerResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.DockerImageName;
+
+public class OllamaContainer extends GenericContainer<OllamaContainer> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(OllamaContainer.class);
+
+ private final DockerImageName dockerImageName;
+
+ private final Integer port;
+ private final String model;
+ private final String imageName;
+
+ public OllamaContainer(DockerImageName image, Integer port, String model, String imageName) {
+ super(image);
+
+ this.dockerImageName = image;
+ this.port = port;
+ this.model = model;
+ this.imageName = imageName;
+ withExposedPorts(port);
+ withImagePullPolicy(dockerImageName -> !dockerImageName.getVersionPart().endsWith(model));
+ setWaitStrategy(Wait.forListeningPort());
+ withLogConsumer(new Slf4jLogConsumer(LOGGER));
+ }
+
+ @Override
+ protected void containerIsStarted(InspectContainerResponse containerInfo) {
+ if (!this.dockerImageName.equals(DockerImageName.parse(imageName))) {
+ try {
+ LOGGER.info("Start pulling the '{}' model ... would take several minutes ...", model);
+ execInContainer("ollama", "pull", model);
+ LOGGER.info("Model pulling competed!");
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException("Error pulling model", e);
+ }
+ }
+ }
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerService.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerService.java
new file mode 100644
index 00000000000..ea97e7673e2
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerService.java
@@ -0,0 +1,108 @@
+/*
+ * 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.test.infra.ollama.services;
+
+import java.util.List;
+
+import com.github.dockerjava.api.DockerClient;
+import com.github.dockerjava.api.model.Image;
+import org.apache.camel.test.infra.common.LocalPropertyResolver;
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.ollama.commons.OllamaProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.DockerClientFactory;
+import org.testcontainers.utility.DockerImageName;
+
+public class OllamaLocalContainerService implements OllamaService, ContainerService<OllamaContainer> {
+ private static final Logger LOG = LoggerFactory.getLogger(OllamaLocalContainerService.class);
+
+ public static final String CONTAINER_PORT = LocalPropertyResolver.getProperty(
+ OllamaLocalContainerService.class, OllamaProperties.PORT);
+
+ public static final String CONTAINER_NAME = LocalPropertyResolver.getProperty(
+ OllamaLocalContainerService.class, OllamaProperties.CONTAINER);
+
+ public static String OLLAMA_MODEL = LocalPropertyResolver.getProperty(
+ OllamaLocalContainerService.class, OllamaProperties.MODEL);
+
+ public static final String LOCAL_OLLAMA_IMAGE = String.format("tc-%s-%s", CONTAINER_NAME, OLLAMA_MODEL);
+
+ private final DockerImageName dockerImageName;
+
+ private final OllamaContainer container;
+
+ private final Integer port;
+
+ public OllamaLocalContainerService() {
+ port = Integer.valueOf(CONTAINER_PORT);
+
+ dockerImageName = resolveImageName();
+
+ container = initContainer();
+ }
+
+ protected OllamaContainer initContainer() {
+ return new OllamaContainer(dockerImageName, port, OLLAMA_MODEL, LOCAL_OLLAMA_IMAGE);
+ }
+
+ protected DockerImageName resolveImageName() {
+ DockerImageName dockerImageName = DockerImageName.parse(CONTAINER_NAME);
+ DockerClient dockerClient = DockerClientFactory.instance().client();
+ List<Image> images = dockerClient.listImagesCmd().withReferenceFilter(LOCAL_OLLAMA_IMAGE).exec();
+ if (images.isEmpty()) {
+ return dockerImageName;
+ }
+ return DockerImageName.parse(LOCAL_OLLAMA_IMAGE);
+ }
+
+ @Override
+ public String getBaseUrl() {
+ return "http://" + container.getHost() + ":" + container.getMappedPort(port);
+ }
+
+ @Override
+ public String getModel() {
+ return OLLAMA_MODEL;
+ }
+
+ @Override
+ public void registerProperties() {
+ System.setProperty(OllamaProperties.PORT, String.valueOf(port));
+ System.setProperty(OllamaProperties.BASE_URL, String.valueOf(getBaseUrl()));
+ }
+
+ @Override
+ public void initialize() {
+ LOG.info("Trying to start the Ollama container");
+ container.start();
+
+ registerProperties();
+ LOG.info("Ollama instance running at {}", port);
+ }
+
+ @Override
+ public void shutdown() {
+ LOG.info("Stopping the Ollama container");
+ container.stop();
+ }
+
+ @Override
+ public OllamaContainer getContainer() {
+ return container;
+ }
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaRemoteService.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaRemoteService.java
new file mode 100644
index 00000000000..190f89ea479
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaRemoteService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.test.infra.ollama.services;
+
+import org.apache.camel.test.infra.ollama.commons.OllamaProperties;
+
+public class OllamaRemoteService implements OllamaService {
+
+ public OllamaRemoteService() {
+ }
+
+ @Override
+ public void registerProperties() {
+ // NO-OP
+ }
+
+ @Override
+ public void initialize() {
+ registerProperties();
+ }
+
+ @Override
+ public void shutdown() {
+ // NO-OP
+ }
+
+ @Override
+ public String getBaseUrl() {
+ return System.getProperty(OllamaProperties.BASE_URL);
+ }
+
+ @Override
+ public String getModel() {
+ return System.getProperty(OllamaProperties.MODEL);
+ }
+
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaService.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaService.java
new file mode 100644
index 00000000000..57282e7a751
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.infra.ollama.services;
+
+import org.apache.camel.test.infra.common.services.TestService;
+
+public interface OllamaService extends TestService {
+
+ String getBaseUrl();
+
+ String getModel();
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaServiceFactory.java b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaServiceFactory.java
new file mode 100644
index 00000000000..602af9e80a8
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaServiceFactory.java
@@ -0,0 +1,37 @@
+/*
+ * 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.test.infra.ollama.services;
+
+import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
+
+public final class OllamaServiceFactory {
+
+ private OllamaServiceFactory() {
+
+ }
+
+ public static SimpleTestServiceBuilder<OllamaService> builder() {
+ return new SimpleTestServiceBuilder<>("org/apache/camel/test/infra/ollama");
+ }
+
+ public static OllamaService createService() {
+ return builder()
+ .addLocalMapping(OllamaLocalContainerService::new)
+ .addRemoteMapping(OllamaRemoteService::new)
+ .build();
+ }
+}
diff --git a/test-infra/camel-test-infra-ollama/src/test/resources/org/apache/camel/test/infra/ollama/services/container.properties b/test-infra/camel-test-infra-ollama/src/test/resources/org/apache/camel/test/infra/ollama/services/container.properties
new file mode 100644
index 00000000000..1a8f0f63bcb
--- /dev/null
+++ b/test-infra/camel-test-infra-ollama/src/test/resources/org/apache/camel/test/infra/ollama/services/container.properties
@@ -0,0 +1,19 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+ollama.port=11434
+ollama.container=ollama/ollama:0.1.27
+ollama.model=orca-mini
\ No newline at end of file
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index f95984a05ed..fcd9be09cf2 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -78,5 +78,6 @@
<module>camel-test-infra-smb</module>
<module>camel-test-infra-cli</module>
<module>camel-test-infra-qdrant</module>
+ <module>camel-test-infra-ollama</module>
</modules>
</project>