GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cohere-ai/cohere-java: Cohere's Java SDK

BranchesTags
Open more actions menu

Latest commit

 

History

58 Commits
58 Commits

Folders and files

NameName
Last commit message
Last commit date
.fern
.fern
 
 
.github/workflows
.github/workflows
 
 
.publish
.publish
 
 
gradle/wrapper
gradle/wrapper
 
 
sample-app
sample-app
 
 
src
src
 
 
.fernignore
.fernignore
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CODEOWNERS
CODEOWNERS
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
banner.png
banner.png
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
reference.md
reference.md
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

Cohere Java Library

Maven Central fern shield

✨🪩✨ Announcing Cohere's new Java SDK ✨🪩✨

We are very excited to publish this brand new Java SDK. We now officially support Java and will continuously update this library with all of the latest features in our API. Please create issues where you have feedback so that we can continue to improve the developer experience!

Documentation

API reference documentation is available here.

Installation

Gradle

Add the dependency in your build.gradle:

dependencies {
    implementation 'com.cohere:cohere-java:+'
}

Maven

Add the dependency in your pom.xml:

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

Usage

import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.Message;
import com.cohere.api.types.NonStreamedChatResponse;

import java.util.List;


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(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
                                        Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());

        System.out.println(response);
    }
}

Handling Errors

When the API returns a non-success status code (4xx or 5xx response), a subclass of ApiError will be thrown:

import com.cohere.api.core.ApiError;

try {
  cohere.generate(/* ... */);
} catch (ApiError error) {
  System.out.println(error.getBody());
  System.out.println(error.getStatusCode());
}

Beta status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your build.gradle file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would 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!

About

Cohere's Java SDK

Resources

Readme
MIT license
Activity
Custom properties

Stars

30 stars

Watchers

8 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.