Coder Social home page Coder Social logo

codenze / bard-api-node Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 9.0 36 KB

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.

Home Page: https://bard.google.com

License: Other

JavaScript 100.00%
ai api bard bard-ai bard-api chatbot google javascript lamda llm

bard-api-node's Introduction

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.
    • Screenshot 2024-03-01 at 10 15 19 PM
  3. Visit Google Ai Studio for API Key:

    • After creating the project, navigate to API Key creation page.
    • Screenshot 2024-03-01 at 10 16 25 PM
    • Click on "Create API key".
    • Choose the project you just created from the dropdown menu labeled "Search Google Cloud projects".
    • Screenshot 2024-03-01 at 10 17 05 PM
    • Click on "Create API key in exsisting project".
    • Copy the API key.
    • Screenshot 2024-03-01 at 10 17 27 PM
  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.

bard-api-node's People

Contributors

codenze avatar tilak-puli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bard-api-node's Issues

Error: TypeError: Cannot read properties of null (reading '0')

I keep getting this issue related to this line in bardAPI.js

Error: TypeError: Cannot read properties of null (reading '0')

This appears to be affecting this line: parsed_answer[2][0] - (textQuery parameter);

I didn't find where the package uses this parameter and the content with the response is not being affected.

I removed the object line to avoid the problem here, but perhaps a solution for this was needed directly in the package.

Library Encounters CAPTCHA and Fails to Proceed

I am encountering an issue with your library when using it. While I can use the BARD website normally through a browser, your library seems to encounter CAPTCHA challenges and fails to proceed. I would appreciate assistance in finding a solution or workaround to this problem.

Answer on both cookies - ...

'<b>About this page</b><br><br>\n' +
      '\n' +
      `Our systems have detected unusual traffic from your computer network.  This page checks to see if it&#39;s really you sending the requests, and not a robot.  <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>\n` +
      '\n' +
      '<div id="infoDiv" style="display:none; background-color:#eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;">\n' +
      'This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service</a>. The block will expire shortly after those requests stop.  In the meantime, solving the above CAPTCHA will let you continue to use our services.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests.  If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible.  <a href="//support.google.com/websearch/answer/86640">Learn more</a><br><br>Sometimes you may be asked to solve the CAPTCHA if you are using advanced terms that robots are known to use, or sending requests very quickly.\n' +
      '</div>\n' +

Does this still work? Error: Failed to retrieve SNlM0e pattern.

I've tried several go, python, and your library and all seem to have this type of issue.
I've rechecked all my 1P and 3P values and they're correct. I even tweaked the conversation ID
constant you have hardcoded to my own in case that was issue.

Error: Failed to retrieve SNlM0e pattern. Please ensure you provide a valid __Secure-1PSID or __Secure-3PSID value.
at BardAPI.setSnim0e (/root/node_modules/bard-api-node/src/bardAPI.js:113:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BardAPI.setSession (/root/node_modules/bard-api-node/src/bardAPI.js:36:5)
at async testAssistant (/root/test.js:7:5)
Bard: Authentication Error! Please make sure to initialize with the correct __Secure-1PSID or __Secure-3PSID value.

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.