Google Bard

How to Invoke Google Bard through Python script

Introduction : A large language model (LLM) from Google AI called Google Bard was trained using a sizable dataset of text and code. It can generate text, translate languages, write various types of creative content, and provide you with informed answers to your queries.

How can one invoke Bard from a python script for a specific task is what we are going to learn today.

Getting Started : First thing first ,

To get started, we will need to install the Bard-API Python package. we can do this with the following command: 

Note : All thanks to the package owner from where I installed Bard API package as Officially it is still not published from google ( till date), so use it with caution same is emphasized on the git hub page for this package.

Command pip install git+https://github.com/dsdanielpark/Bard-API.git

Output : Above command should install Bard- API library and should show something like below.

Installing Google Bard API from Git Hub

Once we have installed the Bard-API package, we shall need to obtain

__Secure-1PSID cookie.

We can do this by opening the Google Bard website in the web browser and pressing F12 to open the developer tools. Then, select the Application tab and click on the Cookies section. In the Cookies list, find the accounts cookie and copy the value of the __Secure-1PSID key.

Here are some images for reference :

Sample image of the cookie in the browser.

Getting Cookie for Google Bard

Sending a Request to Google Bard and getting the response.

Now moment of truth has arrived , as we have our __Secure-1PSID cookie fetched, we can send a request to Google Bard. To do this, we will need to import the Bard-API module and create a new BardClient object. Now go ahead and send your query and mighty Bard will answer !!!

You can do this with the following code:

Invoking Google Bard in Python Script.

Wasn’t it fun to learn this 😊

Conclusion : To able to invoke Bard API can help us getting many things done in our script. Like one can implement a GK (General Knowledge) prompt using this without having to store any data or do any data chandelling . Similarly there can be many use cases of this , all it needs is a stretch of imagination , it can be done using #AI, #GPTs.

This article is supported by free web hosting provider https://hostingcloud9.com

Related Posts

Leave a Reply