npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bard-api-node

v2.1.0

Published

A Node.js library harnessing the power of Bard's Large Language Model (LLM) for seamless chat experiences and streamlined accessibility to Google's Gemini. Empower your applications with advanced conversational AI, leveraging Bard's LLM to answer question

Downloads

393

Readme

Bard-API-Node (Updated for Gemini API)

Bard-API-Node

Description

bard-api-node is a Node.js library for interacting with Bard, an AI Chatbot developed by Google. Bard is based on Google's Large language model (LLM), LaMDA, which is designed to generate human-like text and images in response to prompts. This updated version of the library is aligned with the launch of Gemini API, the successor to Bard, and integrates with the official Google API services.

What is Bard (Gemini)?

Bard, now known as Gemini, is an AI Chatbot developed by Google, based on Google’s Large language model (LLM), LaMDA. Similar to how ChatGPT is based on GPT, Gemini utilizes neural networks to mimic the underlying architecture of the brain in the form of a computer. Gemini is conversational and allows users to write a prompt and receive human-like text and images generated by artificial intelligence.

Getting Started with BardAPI

To begin using BardAPI in your project, follow these steps:

Installation

To use the Bard-API-Node library in your project, you can install it via npm directly:

npm install bard-api-node

or can install it via npm from Github:

npm install git+https://github.com/codenze/bard-api-node.git

Obtaining API Key

To get started with the Bard API, you need to obtain an API key from the Google AI Studio. Follow the steps below to acquire your API key:

  1. Sign in to Google Account:

    • Make sure you are signed in to your Google account.
  2. Create a New Project:

    • Visit Google Cloud Console.
    • Enter a project name of your choice.
    • Click on "Create" to create the project.
  3. Visit Google Ai Studio for API Key:

    • After creating the project, navigate to API Key creation page.
    • Click on "Create API key".
    • Choose the project you just created from the dropdown menu labeled "Search Google Cloud projects".
    • Click on "Create API key in exsisting project".
    • Copy the API key.
  4. Paste API Key into Code:

    • Paste the API key into your code to initialize the BardAPI object.

Usage

javascript const { BardAPI } = require('bard-api-node');

async function testAssistant() {
  try { // Initialize BardAPI object const bard = new BardAPI();

  // Set API key
  const apiKey = 'YOUR_API_KEY'; // Replace 'YOUR_API_KEY' with the obtained API key
  // Initialize chat with API key
  await bard.initilizeChat(apiKey);
  // Send a query to Bard
  const response = await bard.getBardResponse("Greetings! What can you do for me?");
  console.log(response);
  } catch (error) {
    console.error('Error:', error);
  }
}

testAssistant();

Make sure to replace YOUR_API_KEY with the actual API key obtained from Google AI Studio.

Advanced Settings

Content Generation Settings

The setResponseGenerationConfig() method allows you to customize the generation configuration for generating responses. This method enables you to fine-tune parameters related to the content generation process.

Usage

const bard = new BardAPI();

const generationConfig = {
  temperature: 0.7,
  topK: 5,
  topP: 0.9,
  maxOutputTokens: 1024,
};

bard.setResponseGenerationConfig(generationConfig);

In the above example, we set a custom generation configuration with specific values for temperature, top-K sampling, top-p sampling, and maximum output tokens.

Safety Settings

The setSafetySettings() method allows you to configure safety settings to filter out sensitive or harmful content from the generated responses. This method enables you to specify thresholds for different categories of harmful content.

Usage

const bard = new BardAPI();

const safetySettings = [
  {
    category: HarmCategory.HARM_CATEGORY_HARASSMENT,
    threshold: HarmBlockThreshold.BLOCK_STRICT,
  },
  {
    category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
    threshold: HarmBlockThreshold.BLOCK_LOW,
  },
  // Add more security settings as needed
];

bard.setSafetySettings(safetySettings);

In the above example, we set custom safety settings to filter out harassment with a strict threshold and hate speech with a low threshold. You can customize these settings based on your application's requirements.

Acknowledgements

This Node.js library for interacting with the Bard chat assistant is powered by the official Google AI Studio API and utilizes the @google/generative-ai npm library. The integration with Google's Gemini AI and the use of the @google/generative-ai library serve as the foundation for this implementation.

I extend my gratitude to the Google AI team for providing access to their advanced AI capabilities and for the comprehensive documentation that facilitated the development of this library.

Feedback

I welcome any feedback, bug reports, or problems you may encounter while using this library. If you have any issues or suggestions, please don't hesitate to reach out. You can send your reports to [email protected].

Thank you for your support and feedback!

License

This project is licensed under the MIT License. If you find this project helpful in your own work, I would appreciate a star or acknowledgment in your projects.