Bard Project Overview
The Bard project centers around reverse engineering the API of Google's Bard chatbot. This project aims to provide developers with the tools necessary to interact directly with Bard, Google's conversational AI, through a Python interface.
Installation
To get started, users need to install the Bard package using the command line. Installation is straightforward and requires the following command:
$ pip3 install --upgrade GoogleBard
Authentication
Before users can make use of Bard, they need to authenticate their session. This requires obtaining two specific cookies from the Bard website. Here's how to do it:
- Visit the Bard website at bard.google.com.
- Open the browser's console by pressing F12.
- Navigate to
Application
and thenCookies
. - Copy the values of
__Secure-1PSID
and__Secure-1PSIDTS
cookies.
These cookies are necessary to establish a session with the Bard API.
Usage
Once authentication is set up, users can run the Bard script via the command line. Here's the basic usage:
$ python3 -m Bard -h
usage: Bard.py [-h] --session <__Secure-1PSID> --session_ts <__Secure-1PSIDTS>
options:
-h, --help show this help message and exit
--session --session_ts pass two cookies
Quick Mode
For ease of use, Bard offers a quick mode which simplifies commands by using environment variables:
$ export BARD_QUICK="true"
$ export BARD__Secure_1PSID="<__Secure-1PSID>"
$ export BARD__Secure_1PSIDTS="<__Secure-1PSIDTS>"
$ python3 -m Bard
To make repetitive usage easier, these variables can be added to the .zshrc
file, and a bash shortcut can be created as shown:
# USAGE1: bard QUESTION
# USAGE2: echo "QUESTION" | bard
bard () {
export BARD_QUICK=true
export BARD__Secure_1PSID=<__Secure-1PSID>
export BARD__Secure_1PSIDTS=<__Secure-1PSIDTS>
python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7
}
Implementation
For developers looking to integrate Bard into applications, the project provides example implementations:
Synchronous Implementation:
from os import environ
from Bard import Chatbot
Secure_1PSID = environ.get("BARD__Secure_1PSID")
Secure_1PSIDTS = environ.get("BARD__Secure_1PSIDTS")
chatbot = Chatbot(Secure_1PSID, Secure_1PSIDTS)
answer = chatbot.ask("Hello, how are you?")
print(answer['content'])
Asynchronous Implementation:
import asyncio
from os import environ
from Bard import AsyncChatbot
Secure_1PSID = environ.get("BARD__Secure_1PSID")
Secure_1PSIDTS = environ.get("BARD__Secure_1PSIDTS")
async def main():
chatbot = await AsyncChatbot.create(Secure_1PSID, Secure_1PSIDTS)
response = await chatbot.ask("Hello, how are you?")
print(response['content'])
asyncio.run(main())
Additional Resources
Developers can access further information through the Developer Documentation.
Credits
The Bard project builds upon the foundational work of discordtehe, who originally conducted reverse engineering to provide access to Bard's capabilities.
In summary, the Bard project leverages cutting-edge reverse engineering techniques to offer a Python interface for Google's Bard, empowering developers to create innovative applications using conversational AI. The project's simplicity in usage and robust documentation make it accessible for developers aiming to explore the potentials of chatbot technologies.