Skip to main content

The python package that returns Response of Google Bard through API.

Project description

Development Status :: 5 - Production/Stable

Google Bard API

PyPI package Code style: black PyPI

The python package that returns response of Google Bard through API.

I referred to this github repository(github.com/acheong08/Bard) where inference process of Bard was reverse engineered. Using __Secure-1PSID, you can ask questions and get answers from Google Bard. This package is designed for application to the Python package ExceptNotifier and Co-Coder.


Do not expose the __Secure-1PSID

Note that while I referred to __Secure-1PSID value as an API KEY for convenience, it is not an officially provided API KEY.


Amazing Bard Prompts Is All You Need!

  • Helpful prompts for Google Bard

Install

The latest stable release (and required dependencies) can be installed from PyPI:

pip install bardapi

You may instead want to use the development version from Github:

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

Authentication

  1. Visit https://bard.google.com/
  2. F12 for console
  3. Session: Application → Cookies → Copy the value of __Secure-1PSID cookie.

Usage

Open In Colab

Simple Usage

from bardapi import Bard

token = 'xxxxxxxxxx'
bard = Bard(token=token)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']

Or you can use this

from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

Bard().get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']

To get reponse dictionary

import bardapi
import os

# set your __Secure-1PSID value to key
token = 'xxxxxxxxxx'

# set your input text
input_text = "나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘"

# Send an API request and get a response.
response = bardapi.core.Bard(token).get_answer(input_text)

Addressing errors caused by delayed responses in environments like Google Colab and containers. If an error occurs despite following the proper procedure, utilize the timeout argument.

from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

bard = Bard(timeout=30) # Set timeout in seconds
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']

Futher

Behind a proxy

If you are working behind a proxy, use the following.

from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxxx"

# Change 'http://127.0.0.1:1080' to your http proxy
# timeout in seconds
bard = Bard(proxies={'http':'http://127.0.0.1:1080', 'https':'http://127.0.0.1:1080'}, timeout=10)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']

Reusable session object

from bardapi import Bard
import os
import requests
os.environ['_BARD_API_KEY'] = 'xxxxxxxxxxx'
# token='xxxxxxxxxxx'

session = requests.Session()
session.headers = {
            "Host": "bard.google.com",
            "X-Same-Domain": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
            "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            "Origin": "https://bard.google.com",
            "Referer": "https://bard.google.com/",
        }
session.cookies.set("__Secure-1PSID", os.getenv("_BARD_API_KEY")) 
# session.cookies.set("__Secure-1PSID", token) 

bard = Bard(session=session, timeout=30)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']

Simple Example


Scripts

In the scripts folder, I have released a script to help you compare OpenAI-ChatGPT and Google-Bard. I hope they will help more developers.

License

MIT
I hold no legal responsibility; for more information, please refer to the bottom of the readme file. I just want you to give me and them a star.

Bugs and Issues

Sincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.

Contacts

Reference

[1] https://github.com/acheong08/Bard

Important Notice

The user assumes all legal responsibilities associated with using the BardAPI package. This Python package merely facilitates easy access to Google Bard for developers. Users are solely responsible for managing data and using the package appropriately. For further information, please consult the Google Bard Official Document.

Could you kindly add this badge to your repository?

markdown

![BardAPI](https://img.shields.io/badge/pypi-BardAPI-black)

html

<a href="https://github.com/dsdanielpark/Bard-API"><img alt="PyPI package" src="https://img.shields.io/badge/pypi-BardAPI-black"></a>

Thank you for your interest.

Copyright (c) 2023 MinWoo Park, South Korea

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

googlebardapi-0.1.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

googlebardapi-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file googlebardapi-0.1.2.tar.gz.

File metadata

  • Download URL: googlebardapi-0.1.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for googlebardapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6bde6f1242984064d449b5af933ca4f0748ce014ca9f997cd42571e32762e9ff
MD5 9950dd1e6d12a2a5257574996119e0e9
BLAKE2b-256 a9bf8274fd44f79fc7ca12590b3318debe73c8f7d348387b32c79fa2b326baec

See more details on using hashes here.

File details

Details for the file googlebardapi-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for googlebardapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dbca27d750837a9f5cac456aac7c75ff135b541867d87cd34975489ae70e3e1a
MD5 8ea0bcdbaa2c0817b1915c7ef764910f
BLAKE2b-256 8949e60f4f5274fc76acd690fa9032ca358c9ad9beeb84737b2b15f53fbd6a45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page