-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Langchain4j Cohere provider.
- Loading branch information
1 parent
66ba5be
commit 497f47f
Showing
17 changed files
with
809 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2025 Oracle and/or its affiliates. | ||
Licensed 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.integrations.langchain4j.providers</groupId> | ||
<artifactId>helidon-integrations-langchain4j-providers-project</artifactId> | ||
<version>4.2.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>helidon-integrations-langchain4j-providers-cohere</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.common</groupId> | ||
<artifactId>helidon-common-config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common</groupId> | ||
<artifactId>helidon-common-types</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common</groupId> | ||
<artifactId>helidon-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.service</groupId> | ||
<artifactId>helidon-service-registry</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.builder</groupId> | ||
<artifactId>helidon-builder-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.integrations.langchain4j</groupId> | ||
<artifactId>helidon-integrations-langchain4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.langchain4j</groupId> | ||
<artifactId>langchain4j-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.langchain4j</groupId> | ||
<artifactId>langchain4j-cohere</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common.features</groupId> | ||
<artifactId>helidon-common-features-api</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config-yaml</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.helidon.config.metadata</groupId> | ||
<artifactId>helidon-config-metadata-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.helidon.codegen</groupId> | ||
<artifactId>helidon-codegen-apt</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.helidon.builder</groupId> | ||
<artifactId>helidon-builder-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.helidon.service</groupId> | ||
<artifactId>helidon-service-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.helidon.codegen</groupId> | ||
<artifactId>helidon-codegen-helidon-copyright</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.helidon.common.features</groupId> | ||
<artifactId>helidon-common-features-processor</artifactId> | ||
<version>${helidon.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.config.metadata</groupId> | ||
<artifactId>helidon-config-metadata-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.codegen</groupId> | ||
<artifactId>helidon-codegen-apt</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.builder</groupId> | ||
<artifactId>helidon-builder-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.service</groupId> | ||
<artifactId>helidon-service-codegen</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.codegen</groupId> | ||
<artifactId>helidon-codegen-helidon-copyright</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.common.features</groupId> | ||
<artifactId>helidon-common-features-processor</artifactId> | ||
<version>${helidon.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...ers/cohere/src/main/java/io/helidon/integrations/langchain4j/providers/cohere/Cohere.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2025 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.integrations.langchain4j.providers.cohere; | ||
|
||
import io.helidon.common.Weighted; | ||
import io.helidon.integrations.langchain4j.Ai; | ||
import io.helidon.service.registry.Qualifier; | ||
|
||
final class Cohere { | ||
static final String COHERE = "cohere"; | ||
static final String SCORING_MODEL = COHERE + "." + Ai.SCORING_MODEL_NAME; | ||
static final Qualifier COHERE_QUALIFIER = Qualifier.createNamed(COHERE); | ||
static final double WEIGHT = Weighted.DEFAULT_WEIGHT - 20; | ||
|
||
private Cohere() { | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...rc/main/java/io/helidon/integrations/langchain4j/providers/cohere/CohereCommonConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2025 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.integrations.langchain4j.providers.cohere; | ||
|
||
import java.time.Duration; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import io.helidon.builder.api.Option; | ||
|
||
interface CohereCommonConfig { | ||
/** | ||
* If set to {@code false} (default), Cohere model will not be available even if configured. | ||
* | ||
* @return whether Cohere model is enabled, defaults to {@code false} | ||
*/ | ||
@Option.Configured | ||
boolean enabled(); | ||
|
||
/** | ||
* The base URL for the Cohere API. | ||
* | ||
* @return the base URL | ||
*/ | ||
@Option.Configured | ||
Optional<String> baseUrl(); | ||
|
||
/** | ||
* The API key used to authenticate requests to the Cohere API. | ||
* | ||
* @return an {@link java.util.Optional} containing the API key | ||
*/ | ||
@Option.Configured | ||
Optional<String> apiKey(); | ||
|
||
/** | ||
* Whether to log API requests. | ||
* | ||
* @return an {@link java.util.Optional} containing true if requests should be logged, false otherwise | ||
*/ | ||
@Option.Configured | ||
Optional<Boolean> logRequests(); | ||
|
||
/** | ||
* Whether to log API responses. | ||
* | ||
* @return an {@link java.util.Optional} containing true if responses should be logged, false otherwise | ||
*/ | ||
@Option.Configured | ||
Optional<Boolean> logResponses(); | ||
|
||
/** | ||
* A map containing custom headers. | ||
* | ||
* @return custom headers map | ||
*/ | ||
@Option.Configured | ||
@Option.Singular | ||
Map<String, String> customHeaders(); | ||
|
||
/** | ||
* The timeout setting for API requests. | ||
* | ||
* @return the timeout setting in {@link java.time.Duration#parse} format | ||
*/ | ||
@Option.Configured | ||
Optional<Duration> timeout(); | ||
|
||
/** | ||
* The model name to use (e.g., "gpt-3.5-turbo"). | ||
* | ||
* @return the model name | ||
*/ | ||
@Option.Configured | ||
Optional<String> modelName(); | ||
} |
52 changes: 52 additions & 0 deletions
52
...elidon/integrations/langchain4j/providers/cohere/CohereEmbeddingModelConfigBlueprint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2025 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.integrations.langchain4j.providers.cohere; | ||
|
||
import java.util.Optional; | ||
|
||
import io.helidon.builder.api.Option; | ||
import io.helidon.builder.api.Prototype; | ||
|
||
/** | ||
* Configuration for the Cohere embedding model, {@link dev.langchain4j.model.cohere.CohereEmbeddingModel}. | ||
* | ||
* @see dev.langchain4j.model.cohere.CohereEmbeddingModel | ||
*/ | ||
@Prototype.Configured(CohereEmbeddingModelConfigBlueprint.CONFIG_ROOT) | ||
@Prototype.Blueprint | ||
interface CohereEmbeddingModelConfigBlueprint extends CohereCommonConfig { | ||
/** | ||
* Default configuration prefix. | ||
*/ | ||
String CONFIG_ROOT = "langchain4j.cohere.embedding-model"; | ||
|
||
/** | ||
* Gets the input type. | ||
* | ||
* @return an {@link java.util.Optional} containing the input type | ||
*/ | ||
@Option.Configured | ||
Optional<String> inputType(); | ||
|
||
/** | ||
* Gets the maximum number of segments per batch. | ||
* | ||
* @return an {@link java.util.Optional} containing the maximum number of segments per batch | ||
*/ | ||
@Option.Configured | ||
Optional<Integer> maxSegmentsPerBatch(); | ||
} |
Oops, something went wrong.