Skip to content

llmjava/bard4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bard4j

build Jitpack License

A Java and Retrofit2 based Client Library that you can use to interact with Google Bard. It can be used in Android or any Java and Kotlin Project.

Add Dependency

Gradle

To use library in your gradle project follow the steps below:

  1. Add this in your root build.gradle at the end of repositories:
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the dependency
    dependencies {
        def BARD4J_VERSION = "..."
        implementation "com.github.llmjava:bard4j:$BARD4J_VERSION"
    }

Maven

To use the library in your Maven project, follow the steps below:

  1. Add the JitPack repository to your build file:
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
  2. Add the dependency
    <dependency>
        <groupId>com.github.llmjava</groupId>
        <artifactId>bard4j</artifactId>
        <version>${BARD4J_VERSION}</version>
    </dependency>

Usage

Example code to use the Bard API:

Create a configuration file

# Set API key using env variable or put actual value
bard.apiKey=${env:BARD_API_KEY}

Create an instance of BardClient and submit text generation requests

import com.github.llmjava.bard.*;

public class Main {
   public static void main(String[] args) {
       BardConfig config = BardConfig.fromProperties("bard4j.properties");
       BardClient client = new BardClient.Builder().withConfig(config).build();

       String input = "tell me a joke";

       System.out.println(client.generate(input));
   }
}

Build Project

Clone the repository and import as Maven project in IntelliJ IDEA or Eclipse

Before building the project, make sure you have the following things installed.

  • Maven
  • Java 8

To install the API client library to your local Maven repository, simply execute:

mvn install

To build the library using Gradle, execute the following command

./gradlew build

Refer to the official documentation for more information.

About

Unofficial java client for Google Bard

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages