Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
billytrend-cohere authored Apr 23, 2024
1 parent e5fc558 commit 82f0a28
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![](banner.png)

[![Maven Central](https://img.shields.io/maven-central/v/com.cohere.cohere-java/cohere)](https://central.sonatype.com/artifact/com.cohere.cohere-java/cohere)
[![Maven Central](https://img.shields.io/maven-central/v/com.cohere/cohere-java)](https://central.sonatype.com/artifact/com.cohere/cohere-java)
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)

## ✨🪩✨ Announcing Cohere's new Java SDK ✨🪩✨
Expand All @@ -21,7 +21,7 @@ Add the dependency in your `build.gradle`:

```groovy
dependencies {
implementation 'com.cohere.cohere-java:cohere:1.x.x'
implementation 'com.cohere:cohere-java:+'
}
```

Expand All @@ -31,25 +31,37 @@ Add the dependency in your `pom.xml`:

```xml
<dependency>
<groupId>com.cohere.cohere-java</groupId>
<artifactId>cohere</artifactId>
<groupId>com.cohere</groupId>
<artifactId>cohere-java</artifactId>
<version>1.x.x</version>
</dependency>
```

## Usage
```java
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.ChatMessageRole;
import com.cohere.api.types.NonStreamedChatResponse;

Cohere cohere = Cohere.builder()
.apiKey("YOUR_API_KEY")
.build();

GenerateResponse response = cohere.generate(GenerateRequest.builder()
.prompt("Summarize the blog post...")
.build());
import java.util.List;

System.out.printlin("Received response!" + response);

public class ChatPost {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();

NonStreamedChatResponse response = cohere.chat(
ChatRequest.builder()
.message("What year was he born?")
.chatHistory(
List.of(ChatMessage.builder().role(ChatMessageRole.USER).message("Who discovered gravity?").build(),
ChatMessage.builder().role(ChatMessageRole.CHATBOT).message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build())).build());

System.out.println(response);
}
}
```

### Handling Errors
Expand Down Expand Up @@ -83,4 +95,4 @@ be overwritten upon the next generated release. Feel free to open a PR as a
proof of concept, but know that we will not be able to merge it as-is.
We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
On the other hand, contributions to the README are always very welcome!

0 comments on commit 82f0a28

Please sign in to comment.