This is a simple wrapper for Google Bard, written in TypeScript. It allows you to easily send messages to Google Bard and receive responses in a structured format.
To install this package, simply run:
npm install google-bard-api
To use this package, you will need to provide a valid __Secure-1PSID
cookie for Google Bard. Once you have this, you can create a new instance of the Bard
class and use the query
method to send messages to Google Bard and receive responses.
Here's an example of how to use this package:
import Bard from "google-bard-api";
// Replace this with a valid __Secure-1PSID cookie for Google Bard
const sessionId = "your-session-id-here";
const bard = new Bard(sessionId);
bard.query("What is the meaning of life?")
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});
// Using async-await
async function getResponse() {
try {
const response = await bard.query("Who is the current CEO of Twitter?");
console.log(response);
} catch (error) {
console.error(error);
}
}
getResponse();
The query
method returns a ChatData
object, which contains the following properties:
-
content
: The response text from Google Bard. -
conversationId
: The conversation ID for this message. -
responseId
: The response ID for this message. -
factualityQueries
: An array of factuality queries for this message. -
textQuery
: The text query for this message. -
choices
: An array of choices for this message, if any.