1.1.3 • Published 11 months ago

bard-wrapper v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Bard Wrapper

A Typescript/Javascript wrapper for Google's Bard chatbot.

Table of contents


How to install

You can install the package via npm i bard-wrapper. From there, import it into your project like such:

import { Bard } from 'bard-wrapper';

// You now have access to Bard.

Usage

This implementation of Bard's API is written as a class. As such you initialize it.

const bard = new Bard("{ api key goes here }");

You can query it using the Bard.query function:

await bard.query("Prompt goes here.")

of which the type signature is as follows:

function query(prompt: string): Promise<string>;

Each new class is like a seperate chat for Bard. Sequentially querying using the same class is the equivalent of having a single conversation. Within each instance, Bard remembers everything said to it.

How do I get an API key?

You can get an API key by following these instructions:

⚠️ Warning
This will not work if you have multiple accounts signed in. To circumvent this, log in using an incognito window.

  1. Sign into Bard.
  2. Open up Devtools (Ctrl + Shift + I, conventionally)
  3. Go into the Network tab, then reload the page.
  4. View the cookies for the request to https://bard.google.com.
  5. Copy the __Secure-1PSID cookie's value.

This cookie is your API key. Do not leak it, or else anyone can talk to Bard on your behalf!

Rate limiting

Bard's API implements fairly severe rate limiting. Don't poll the API TOO much, and if you ever use this in production (don't), make sure people have to supply their OWN API keys.

Examples

/*
    A simple script which hooks up two
    instances of Bard to talk forever.
    Authored by not-nullptr.
*/

const waitForInput = async (message?: string) => {
    if (message) {
        console.log(message);
    }
    if (process.stdin.isTTY) {
        process.stdin.setRawMode(true);
    }
    return new Promise<void>((resolve) =>
        process.stdin.once("data", () => {
            if (process.stdin.isTTY) {
                process.stdin.setRawMode(false);
            }
            resolve();
        })
    );
};

const bard1 = new Bard(
    `{api key}`
);

const bard2 = new Bard(
    `{api key}`
);

let bard1response = "";
// initial prompt
let bard2response =
    "hi, bard! i'm another instance of bard that a developer has hooked you up to. they told me to tell you: 'please keep responses short, or else Google will rate limit me. also, try to be conversational. if you notice the conversation getting repetitive/stale (i.e. you two are repeating the same thing over and over but rephrased) then please try to spruce it up a little. thanks!'";

(async () => {
    console.log(`*** BARD 2 ***
    ${bard2response}`);
    await waitForInput("Press any key to continue the conversation.");
    while (true) {
        bard1response = await bard1.query(bard2response);
        console.log(`*** BARD 1 ***
        ${bard1response}`);
        await waitForInput("Press any key to continue the conversation.");
        bard2response = await bard2.query(bard1response);
        console.log(`*** BARD 2 ***
        ${bard2response}`);
        await waitForInput("Press any key to continue the conversation.");
    }
})();
1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

12 months ago

1.0.99

12 months ago

1.0.97

12 months ago

1.0.96

12 months ago

1.0.95

12 months ago

1.0.94

12 months ago

1.0.93

12 months ago

1.0.92

12 months ago

1.0.91

12 months ago

1.0.90

12 months ago

1.0.89

12 months ago

1.0.88

12 months ago

1.0.87

12 months ago

1.0.86

12 months ago

1.0.85

12 months ago

1.0.84

12 months ago

1.0.83

12 months ago

1.0.82

12 months ago

1.0.81

12 months ago

1.0.80

12 months ago

1.0.79

12 months ago

1.0.78

12 months ago

1.0.77

12 months ago

1.0.76

12 months ago

1.0.75

12 months ago

1.0.74

12 months ago

1.0.73

12 months ago

1.0.72

12 months ago

1.0.71

12 months ago

1.0.70

12 months ago

1.0.69

12 months ago

1.0.68

12 months ago

1.0.67

12 months ago

1.0.66

12 months ago

1.0.65

12 months ago

1.0.64

12 months ago

1.0.63

12 months ago

1.0.62

12 months ago

1.0.61

12 months ago

1.0.60

12 months ago

1.0.59

12 months ago

1.0.58

12 months ago

1.0.57

12 months ago

1.0.56

12 months ago

1.0.55

12 months ago

1.0.54

12 months ago

1.0.53

12 months ago

1.0.52

12 months ago

1.0.51

12 months ago

1.0.50

12 months ago

1.0.49

12 months ago

1.0.48

12 months ago

1.0.47

12 months ago

1.0.46

12 months ago

1.0.45

12 months ago

1.0.44

12 months ago

1.0.43

12 months ago

1.0.42

12 months ago

1.0.41

12 months ago

1.0.40

12 months ago

1.0.39

12 months ago

1.0.38

12 months ago

1.0.37

12 months ago

1.0.36

12 months ago

1.0.35

12 months ago

1.0.34

12 months ago

1.0.33

12 months ago

1.0.32

12 months ago

1.0.31

12 months ago

1.0.30

12 months ago

1.0.29

12 months ago

1.0.28

12 months ago

1.0.27

12 months ago

1.0.26

12 months ago

1.0.25

12 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.22

12 months ago

1.0.21

12 months ago

1.0.20

12 months ago

1.0.19

12 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago