https://github.com/stephanj/langchain4j-cohere
https://github.com/stephanj/langchain4j-cohere
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stephanj/langchain4j-cohere
- Owner: stephanj
- License: apache-2.0
- Created: 2024-03-30T21:02:33.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-31T09:46:10.000Z (about 1 year ago)
- Last Synced: 2025-01-30T04:16:28.412Z (4 months ago)
- Language: Java
- Size: 88.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cohere LangChain4J support
Cleanup of existing Langchain4J Cohere client (backwards compatible).
See also the [Cohere embed API documentation](https://docs.cohere.com/docs/embed)```java
class CohereClient extends CohereExecute {private final CohereApi cohereApi;
@Builder
CohereClient(String baseUrl,
String apiKey,
Duration timeout,
boolean logRequests,
boolean logResponses) {
cohereApi = new CohereApiFactory()
.createHttpClient(baseUrl, apiKey, timeout, logRequests, logResponses).build();
}public RerankResponse rerank(RerankRequest request) {
return execute(cohereApi.rerank(request));
}public EmbedResponse embed(EmbedRequest request) {
return execute(cohereApi.embed(request));
}public void embedAsync(EmbedRequest request, AsyncCallback callback) {
execute(cohereApi.embed(request), callback);
}
}
```## ReRank (existed in v0.29.0)
## EmbeddingModel (new)
```java
CohereEmbeddingModel model = CohereEmbeddingModel.withApiKey(System.getenv("COHERE_API_KEY"));Response embed = model.embed("Hello World");
assertThat(embed.content().vector()).isNotEmpty();
```Specify model
```Java
String cohereApiKey = System.getenv("COHERE_API_KEY");
CohereEmbeddingModel cohereEmbeddingModel = new CohereEmbeddingModel(
"https://api.cohere.ai/v1/",
cohereApiKey,
CohereLanguageModel.EMBED_ENGLISH_V3_0,
CohereInputType.SEARCH_DOCUMENT,
Duration.ofSeconds(60),
false,
false);Response embed = cohereEmbeddingModel.embed("Hello World");
assertThat(embed.content().vector()).isNotEmpty();
```## Preparations
Extra Cohere features are also included but not yet activated because Langchain4J doesn't support it yet.### Summarize
### (De)tokenizer
### Generate
### Detect Language
### Classify