Giter VIP home page Giter VIP logo

aleph-alpha-client-java's Introduction

Java client library for Aleph Alpha

Aleph Alpha Java Client Image

This is an unofficial Java client library that helps to connect your Java applications to Aleph Alpha API.

Current capabilities

We support the API version 1.16.0 completely for Java 8+.

Tell us about any issue you face or new feature here.

What's coming

  • Asynchronous communication

Start using

Maven:

<dependency>
    <groupId>io.github.heezer</groupId>
    <artifactId>aleph-alpha-client-java</artifactId>
    <version>0.1.2</version>
</dependency>

Gradle:

implementation 'io.github.heezer:aleph-alpha-client-java:0.1.2'

Code examples

Create an Aleph Alpha Client

Simple way:

Client client = Client.builder()
  .apiKey(System.getenv("ALEPH_ALPHA_API_KEY"))
  .build();

Customizable way:

Client client = Client.builder()
  .apiKey(System.getenv("ALEPH_ALPHA_API_KEY"))
  .callTimeout(ofSeconds(60))
  .connectTimeout(ofSeconds(60))
  .readTimeout(ofSeconds(60))
  .writeTimeout(ofSeconds(60))
  .proxy(HTTP, "XXX.XXX.XXX.XXX", 8080)
  .logRequests(true)
  .logResponses(true)
  .build();

Completions

Simple way:

CompletionResponse response = client.complete(CompletionRequest.builder().prompt("An apple a day").build());

Customizable way:

CompletionResponse response = client.complete(
  CompletionRequest
    .builder()
    .model("luminous-supreme-control")
    .prompt(
      "### Instruction:\n" +
      "Identify the topic of the text.\n" +
      "Reply like this: \"The topic is: <topic>\"\n" +
      "\n" +
      "### Input:\n" +
      "Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. " +
      "Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.\n" +
      "\n" +
      "### Response:"
    )
    .maximumTokens(16)
    .rawCompletion(true)
    .build()
);

Image Completions

String base64Image = <your image as Base64>;

CompletionResponse response = client.complete(
  CompletionRequest
    .builder()
    .prompt(Collections.singletonList(MultimodalImage.builder().data(base64Image).build()))
    .build()
);

response.getCompletions().get(0).getCompletion(); // image completion/description is here

Embeddings

EmbeddingsResponse response = client.embed(
  EmbeddingsRequest
    .builder()
    .prompt("An apple a day keeps the doctor away.")
    .layers(Collections.singletonList(INPUT_LAYER_MINUS_ONE))
    .pooling(Arrays.asList(POOLING_MAX, POOLING_WEIGHTED_MEAN))
    .build()
);

Semantic Embeddings

SemanticEmbeddingsResponse response = client.semanticEmbed(
  SemanticEmbeddingsRequest.builder().prompt("An apple a day keeps the doctor away.").compressToSize(128).build()
);

Tokenization & Detokenization

List<Integer> tokens = client
  .tokenize(
    TokenizationRequest
      .builder()
      .prompt("An apple a day keeps the doctor away.")
      .tokens(false)
      .tokenIds(true)
      .build()
  )
  .getTokenIds();

DetokenizationResponse response = client.detokenize(DetokenizationRequest.builder().tokenIds(tokens).build());

response.getResult(); // An apple a day keeps the doctor away.

Retrieving Available Models

List<Model> response = client.models();

Useful Links

aleph-alpha-client-java's People

Contributors

heezer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.