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 b4eea1d2d1a CAMEL-21726 : Add OpenAI and HuggingFace Chat Models to 
create RAG Kameletes (#17073)
b4eea1d2d1a is described below

commit b4eea1d2d1a7dac0d30f19f8fb030470cc7a0a13
Author: Zineb BENDHIBA <bendhiba.zi...@gmail.com>
AuthorDate: Wed Feb 5 20:09:36 2025 +0100

    CAMEL-21726 : Add OpenAI and HuggingFace Chat Models to create RAG 
Kameletes (#17073)
---
 .../chat/HugginFaceChatLanguageModelBuilder.java   | 73 ++++++++++++++++++++
 .../chat/OpenAiChatLanguageModelBuilder.java       | 80 ++++++++++++++++++++++
 2 files changed, 153 insertions(+)

diff --git 
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/HugginFaceChatLanguageModelBuilder.java
 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/HugginFaceChatLanguageModelBuilder.java
new file mode 100644
index 00000000000..3844efee4ea
--- /dev/null
+++ 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/HugginFaceChatLanguageModelBuilder.java
@@ -0,0 +1,73 @@
+/*
+ * 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.chat;
+
+import dev.langchain4j.model.huggingface.HuggingFaceLanguageModel;
+
+import static java.time.Duration.ofSeconds;
+
+public final class HugginFaceChatLanguageModelBuilder {
+    private String accessToken;
+    private String modelId;
+    private boolean waitForModel;
+    private int timeout;
+
+    private int maxNewTokens;
+
+    private double temperature;
+
+    public HugginFaceChatLanguageModelBuilder accessToken(String accessToken) {
+        this.accessToken = accessToken;
+        return this;
+    }
+
+    public HugginFaceChatLanguageModelBuilder modelId(String modelId) {
+        this.modelId = modelId;
+        return this;
+    }
+
+    public HugginFaceChatLanguageModelBuilder timeout(int timeout) {
+        this.timeout = timeout;
+        return this;
+    }
+
+    public HugginFaceChatLanguageModelBuilder waitForModel(boolean 
waitForModel) {
+        this.waitForModel = waitForModel;
+        return this;
+    }
+
+    public HugginFaceChatLanguageModelBuilder temperature(double temperature) {
+        this.temperature = temperature;
+        return this;
+    }
+
+    public HugginFaceChatLanguageModelBuilder maxNewTokens(int maxNewTokens) {
+        this.maxNewTokens = maxNewTokens;
+        return this;
+    }
+
+    public HuggingFaceLanguageModel build() {
+        return HuggingFaceLanguageModel.builder()
+                .accessToken(accessToken)
+                .modelId(modelId)
+                .waitForModel(waitForModel)
+                .timeout(ofSeconds(timeout))
+                .temperature(temperature)
+                .maxNewTokens(maxNewTokens)
+                .build();
+    }
+}
diff --git 
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/OpenAiChatLanguageModelBuilder.java
 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/OpenAiChatLanguageModelBuilder.java
new file mode 100644
index 00000000000..bde9dd6bcb7
--- /dev/null
+++ 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/chat/OpenAiChatLanguageModelBuilder.java
@@ -0,0 +1,80 @@
+/*
+ * 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.chat;
+
+import dev.langchain4j.model.chat.ChatLanguageModel;
+import dev.langchain4j.model.openai.OpenAiChatModel;
+
+import static java.time.Duration.ofSeconds;
+
+public final class OpenAiChatLanguageModelBuilder {
+    private String apiKey;
+    private String modelName;
+    private long timeout;
+    private int maxRetries;
+    private boolean logRequests;
+    private boolean logResponses;
+
+    private Double temperature;
+
+    public OpenAiChatLanguageModelBuilder apiKey(String apiKey) {
+        this.apiKey = apiKey;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder modelName(String modelName) {
+        this.modelName = modelName;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder timeout(long timeout) {
+        this.timeout = timeout;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder maxRetries(int maxRetries) {
+        this.maxRetries = maxRetries;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder logRequests(boolean logRequests) {
+        this.logRequests = logRequests;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder logResponses(boolean logResponses) {
+        this.logResponses = logResponses;
+        return this;
+    }
+
+    public OpenAiChatLanguageModelBuilder temperature(Double temperature) {
+        this.temperature = temperature;
+        return this;
+    }
+
+    public ChatLanguageModel build() {
+        return OpenAiChatModel.builder()
+                .apiKey(apiKey)
+                .modelName(modelName)
+                .timeout(ofSeconds(timeout))
+                .maxRetries(maxRetries)
+                .logRequests(logRequests)
+                .logRequests(logResponses)
+                .temperature(temperature)
+                .build();
+    }
+}

Reply via email to