This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 d944fb9a8a2 CAMEL-21560: Create a HugginFace Embedding Model builder
acting as Java Bean for a Kamelet (#16700)
d944fb9a8a2 is described below
commit d944fb9a8a2874282f0571c348c1839481cfa6b3
Author: Zineb BENDHIBA <[email protected]>
AuthorDate: Fri Jan 3 16:49:00 2025 +0100
CAMEL-21560: Create a HugginFace Embedding Model builder acting as Java
Bean for a Kamelet (#16700)
---
components/camel-kamelet/pom.xml | 7 ++-
.../HuggingFaceEmbeddingModelBuilder.java | 58 ++++++++++++++++++++++
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/components/camel-kamelet/pom.xml b/components/camel-kamelet/pom.xml
index 4b1896e1f81..c11bbd5a92c 100644
--- a/components/camel-kamelet/pom.xml
+++ b/components/camel-kamelet/pom.xml
@@ -34,7 +34,6 @@
<description>To call Kamelets</description>
<dependencies>
-
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-reifier</artifactId>
@@ -54,6 +53,12 @@
<artifactId>camel-djl</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>dev.langchain4j</groupId>
+ <artifactId>langchain4j-hugging-face</artifactId>
+ <version>${langchain4j-version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>net.sf.extjwnl</groupId>
<artifactId>extjwnl</artifactId>
diff --git
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/HuggingFaceEmbeddingModelBuilder.java
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/HuggingFaceEmbeddingModelBuilder.java
new file mode 100644
index 00000000000..0f8ea42bab5
--- /dev/null
+++
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/HuggingFaceEmbeddingModelBuilder.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.kamelet.utils.langchain4j.embeddings;
+
+import dev.langchain4j.model.huggingface.HuggingFaceEmbeddingModel;
+
+import static java.time.Duration.ofSeconds;
+
+public final class HuggingFaceEmbeddingModelBuilder {
+ private String accessToken;
+ private String modelId;
+ private boolean waitForModel;
+ private int timeout;
+
+ public HuggingFaceEmbeddingModelBuilder accessToken(String accessToken) {
+ this.accessToken = accessToken;
+ return this;
+ }
+
+ public HuggingFaceEmbeddingModelBuilder modelId(String modelId) {
+ this.modelId = modelId;
+ return this;
+ }
+
+ public HuggingFaceEmbeddingModelBuilder timeout(int timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+
+ public HuggingFaceEmbeddingModelBuilder waitForModel(boolean waitForModel)
{
+ this.waitForModel = waitForModel;
+ return this;
+ }
+
+ public HuggingFaceEmbeddingModel build() {
+ return HuggingFaceEmbeddingModel.builder()
+ .accessToken(accessToken)
+ .modelId(modelId)
+ .waitForModel(waitForModel)
+ .timeout(ofSeconds(timeout))
+ .build();
+ }
+
+}