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 079ff189e50 CAMEL-21586: Create a OpenAI Embedding Model builder acting as Java Bean for a Kamelet (#16699) 079ff189e50 is described below commit 079ff189e50702fe67348f2ffec5d02b7564e4c2 Author: Zineb BENDHIBA <bendhiba.zi...@gmail.com> AuthorDate: Fri Jan 3 16:48:49 2025 +0100 CAMEL-21586: Create a OpenAI Embedding Model builder acting as Java Bean for a Kamelet (#16699) --- components/camel-kamelet/pom.xml | 6 ++ .../embeddings/OpenAiEmbeddingModelBuilder.java | 79 ++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/components/camel-kamelet/pom.xml b/components/camel-kamelet/pom.xml index 3479598dc79..4b1896e1f81 100644 --- a/components/camel-kamelet/pom.xml +++ b/components/camel-kamelet/pom.xml @@ -43,6 +43,12 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-core-model</artifactId> </dependency> + <dependency> + <groupId>dev.langchain4j</groupId> + <artifactId>langchain4j-open-ai</artifactId> + <version>${langchain4j-version}</version> + <scope>provided</scope> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-djl</artifactId> diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/OpenAiEmbeddingModelBuilder.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/OpenAiEmbeddingModelBuilder.java new file mode 100644 index 00000000000..0900376370c --- /dev/null +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/utils/langchain4j/embeddings/OpenAiEmbeddingModelBuilder.java @@ -0,0 +1,79 @@ +/* + * 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.embedding.EmbeddingModel; +import dev.langchain4j.model.openai.OpenAiEmbeddingModel; + +import static java.time.Duration.ofSeconds; + +public final class OpenAiEmbeddingModelBuilder { + private String apiKey; + private String modelName; + private long timeout; + private int maxRetries; + private int dimensions; + private boolean logRequests; + private boolean logResponses; + + public OpenAiEmbeddingModelBuilder apiKey(String apiKey) { + this.apiKey = apiKey; + return this; + } + + public OpenAiEmbeddingModelBuilder modelName(String modelName) { + this.modelName = modelName; + return this; + } + + public OpenAiEmbeddingModelBuilder timeout(long timeout) { + this.timeout = timeout; + return this; + } + + public OpenAiEmbeddingModelBuilder maxRetries(int maxRetries) { + this.maxRetries = maxRetries; + return this; + } + + public OpenAiEmbeddingModelBuilder dimensions(int dimensions) { + this.dimensions = dimensions; + return this; + } + + public OpenAiEmbeddingModelBuilder logRequests(boolean logRequests) { + this.logRequests = logRequests; + return this; + } + + public OpenAiEmbeddingModelBuilder logResponses(boolean logResponses) { + this.logResponses = logResponses; + return this; + } + + public EmbeddingModel build() { + return OpenAiEmbeddingModel.builder() + .apiKey(apiKey) + .modelName(modelName) + .timeout(ofSeconds(timeout)) + .maxRetries(maxRetries) + .dimensions(dimensions) + .logRequests(logRequests) + .logRequests(logResponses) + .build(); + } +}