Skip to content

Simatwa/Bard

 
 

Repository files navigation

Bard

Reverse engineering of Google's Gemini chatbot API, formerly BARD.

Installation

 $ pip3 install --upgrade GoogleBard1

Authentication

Go to https://bard.google.com/

  • F12 for console
  • Copy the values
    • Session: Go to Application → Cookies → __Secure-1PSID and __Secure-1PSIDTS. Copy the value of those cookie.

Usage

$ python3 -m Bard -h
usage: Bard.py [-h] --session SESSION --session_ts SESSION_TS

options:
  -h, --help            show this help message and exit
  --session SESSION     __Secure-1PSID cookie
  --session_ts SESSION_TS
                        __secure_1psidts cookie.

Quick mode

$ export BARD_QUICK="true"
$ export BARD__Secure_1PSID="<__Secure-1PSID>"
$ export BARD__Secure_1PSIDTS="<__Secure-1PSIDTS>"
$ python3 -m Bard

Environment variables can be placed in .zshrc.

Example bash shortcut:

# 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:

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']

Async 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())

Important

The cookies expire after a short period; ensure you update them as frequent as possible.

Credits:

  • discordtehe - Derivative of his original reverse engineering

About

Python SDK/API for reverse engineered Google Bard

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%