Giter Club home page Giter Club logo

jarvisbot-java's Introduction

JarvisBot Java API library

Access Token

Important

JarvisBot SDK is currently undergoing rapid development, which may lead to stability and compatibility issues. You can email [email protected] to request an access token. We will periodically open up trials.

Import dependencies

Gradle

implementation("io.github.jarvisbot-ai:jarvisbot-java:latest")

Maven

<dependency>
    <groupId>io.github.jarvisbot-ai</groupId>
    <artifactId>jarvisbot-java</artifactId>
    <version>latest</version>
</dependency>

How to Use

The sample way to use

import com.jarvisbot.sdk.JarvisBot;
import base.com.jarvisbot.sdk.IJarvisBot;
import res.entity.com.jarvisbot.sdk.ChatRes;

try{
IJarvisBot jarvisBot = new JarvisBot("you token").baseBlock();
ChatRes result = jarvisBot.chat(Chat.defaultChat("hi")).blockingGet();
    System.out.

println(result);
}catch(
Exception exception){
        // TODO: created failed or chat failed
        }

1. create JarvisBot by you token

  • create default
import com.jarvisbot.sdk.JarvisBot;

JarvisBot jarvisBot = new JarvisBot("you token");
  • Create with custom ExecutorService
import com.jarvisbot.sdk.JarvisBot;

JarvisBot jarvisBot = new JarvisBot("you token", customExecutorService);
  • Or you can get error when JarvisBot create failed
import com.jarvisbot.sdk.JarvisBot;
import interfaces.common.com.jarvisbot.sdk.I1;

I1<Throwable> errorCallback = System.out::println;
JarvisBot jarvisBot = new JarvisBot("you token", errorCallback);
JarvisBot jarvisBot = new JarvisBot("you token", customExecutorService, errorCallback);

2. use base or baseBlock

if you use base , you may be got null or Error when the JarvisBot have not been created or created failed

if you use baseBlock , you may be blocked because JarvisBot have not been created or throw an exception when created failed

   JarvisBot jarvisBot =  jarvisBot.base();
   JarvisBot jarvisBot =  jarvisBot.baseBlock();

3. chat

you can default to chat or custom your param ChatReq.

Also, you can get result by block current thread or asynchronous execution

ChatReq chatReq = Chat.defaultChat("");
// TODO chatReq.set...
JarvisFuture<ChatRes> future = jarvisBot.chat(chatReq);
future.blockingGet();
// or
future.async(new Consumer<ChatRes>{
    @Override
    public void apply(ChatRes param) {
        // handle param
    }

//    @Override
//    public void onError(Throwable e) {
//    do something
//    }

//    @Override
//    public void completed() {
//    do something
//    }
})

4.txt2img

Txt2imgReq req = Txt2Img.default2Img("");
// TODO req.set...
JarvisFuture<ImgRes> future = jarvisBot.txt2img(req);
//future.blockingGet();
// or
//future.async(new Consumer<ImgRes>{/*...*/})

5.img2img

Img2imgReq req = Img2Img.default2Img("",/*list of `img_url` or `img_base64_string`*/);
// TODO req.set...
JarvisFuture<ImgRes> future = jarvisBot.img2img(req);
//future.blockingGet();
// or
//future.async(new Consumer<ImgRes>{/*...*/})

6.tts

TtsReq req = Tts.defaultTts("some words");
// TODO req.set...
// mp3 raw data
JarvisFuture<byte[]> future = jarvisBot.tts(req);
//future.blockingGet();
// or
//future.async(new Consumer<ImgRes>{/*...*/})

7.chat by sse

observeBlock can block current thread

import observe.common.com.jarvisbot.sdk.Observer;

ChatReq req = Chat.defaultChat("");
// TODO chatReq.set...
Observer<ChatRes> future = jarvisBot.chatSee(req);
//future.observe(new Consumer<ChatRes>() {/*...*/})
//future.observeBlock(new Consumer<ChatRes>() {/*...*/})

8.asr

AsrReq req = Asr.defaultAsr(/*base64 string, mp3 raw data*/);
// TODO req.set...
JarvisFuture<AsrRes> future = jarvisBot.asr(req);
//future.blockingGet();
// or
//future.async(new Consumer<AsrRes>{/*...*/})

jarvisbot-java's People

Contributors

hariag avatar longqingzhao 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.