• This repository has been archived on 24/Apr/2024
  • Stars
    star
    5,346
  • Rank 7,727 (Top 0.2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The unofficial python package that returns response of Google Bard through cookie value.

Development Status :: 5 - Production/Stable

Google Bard API

PyPI package Code style: black PyPI

The python package that returns response of Google Bard through value of cookie.

Please exercise caution and use this package responsibly.

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. Please note that the bardapi is not a free service, but rather a tool provided to assist developers with testing certain functionalities due to the delayed development and release of Google Bard's API. It has been designed with a lightweight structure that can easily adapt to the emergence of an official API. Therefore, I strongly discourage using it for any other purposes.


hf-transllm

If you want to test the open-llama model, which is released under the Apache License (allowing free commercial use) in various languages, you can try using the hf-transllm package. hf-transllm also supports multilingual inference for various LLMs stored in hugging face repository.


Amazing Bard Prompts Is All You Need!

  • Helpful prompts for Google Bard

Install

If you will not provide the language parameter (use english, korean, japanese only as input text):

pip install bardapi

If you wish to use the Bard API, including various features:

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

Due to certain dependency packages that are not compatible with 64bit windows(OS), we are releasing a lightweight alpha release of bard that only returns responses for simple requests. This release is a continuation of the pypi 0.1.18 version, which was maintained with lightweight and simple functionality. See alpha-release github branch for more details.

pip install bardapi==0.1.23a

Authentication

Warning Do not expose the __Secure-1PSID

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

Note that while I referred to __Secure-1PSID value as an API key for convenience, it is not an officially provided API key. Cookie value subject to frequent changes. Verify the value again if an error occurs. Most errors occur when an invalid cookie value is entered.


If you need to set multiple Cookie values

  • Bard Cookies - After confirming that multiple cookie values are required to receive responses reliably in certain countries, I will deploy it for testing purposes. Please debug and create a pull request

Usage

Open In Colab

Simple Usage

from bardapi import Bard

token = 'xxxxxxx'
bard = Bard(token=token)
bard.get_answer("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")['content']

Or you can use this

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

Bard().get_answer("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")['content']

To get reponse dictionary

import bardapi
import os

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

# 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']="xxxxxxx"

bard = Bard(timeout=30) # Set timeout in seconds
bard.get_answer("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")['content']

Further

Behind a proxy

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

from bardapi import Bard
import os

# Change 'http://proxy.example.com:8080' to your http proxy
# timeout in seconds
proxies = {
    'http': 'http://proxy.example.com:8080',
    'https': 'https://proxy.example.com:8080'
}

bard = Bard(token='xxxxxxx', proxies=proxies, timeout=30)
bard.get_answer("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")['content']

Reusable session object

You can continue the conversation using a reusable session.

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

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(token=token, session=session, timeout=30)
bard.get_answer("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")['content']

# Continued conversation without set new session
bard.get_answer("What is my last prompt??")['content']



More features

Starting from version 0.1.18, the GitHub version of BardAPI will be synchronized with the PyPI version and released simultaneously.

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

Example code of hf-transllm

In case the Google package is no longer available due to policy restrictions, here's a simple example code for using open-source language models (LLMs) in both English and multiple languages.

Usage

For the decoder models provided by Hugging Face, you can easily use them by either following a simple approach or overriding the inference method. You can explore various open-source language models at this link. Through the ranking information from Open LLM Leader Board Report repository, you can find information about good models.

For LLM that use languages other than English

from transllm import LLMtranslator

open_llama3b_kor = LLMtranslator('openlm-research/open_llama_3b', target_lang='ko', translator='google') # Korean

trnaslated_answer = open_llama3b_kor.generate("๋‚˜์™€ ๋‚ด ๋™๋…„๋ฐฐ๋“ค์ด ์ข‹์•„ํ•˜๋Š” ๋‰ด์ง„์Šค์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค์ค˜")
print(trnaslated_answer)

For LLM that use English

Refer https://github.com/openlm-research/open_llama or using like this:

from transllm import LLMtranslator

open_llama3b = LLMtranslator('openlm-research/open_llama_3b) 

answer = open_llama3b.generate("Tell me about the Korean girl group Newjeans.")
print(answer)



Scripts

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

Contributors

I would like to express my sincere gratitude for the contributions made by all the contributors.


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.

The MIT License (MIT)

Copyright (c) 2023 Minwoo Park

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Shifting Service Policies: Bard and Google's Dynamics

Bard's service status and Google's API interfaces are in constant flux. The number of replies is currently limited, but certain users, such as those utilizing VPNs or proxy servers, have reported slightly higher message caps. Adaptability is crucial in navigating these dynamic service policies. Please note that the cookie values used in this package are not official API values.

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.

Caution

This Python package is not an official Google package or API service. It is not affiliated with Google and uses Google account cookies, which means that excessive or commercial usage may result in restrictions on your Google account. The package was created to support developers in testing functionalities due to delays in the official Google package. However, it should not be misused or abused. Please be cautious and refer to the Readme for more information.

Copyright (c) 2023 MinWoo Park, South Korea

More Repositories

1

Gemini-API

The unofficial python package that returns response of Google Gemini through cookie values.
Python
156
star
2

open-llm-leaderboard-report

Weekly visualization report of Open LLM model performance based on 4 metrics.
Python
88
star
3

open-llm-datasets

Repository for organizing datasets and papers used in Open LLM.
84
star
4

co-coder

Co-Coder is a Python package that streamlines error debugging from Open AI chat GPT and Google Bard by providing hints, example code, and relevant Stack Overflow links.
Jupyter Notebook
44
star
5

gpt2-bert-medical-qa-chat

Medical domain-focused GPT-2 fine-tuning, optimization, and lightweighting research repository (compared to GPT-4).
Python
31
star
6

hf-transllm

LLMtranslator translates and generates text in multiple languages.
Jupyter Notebook
31
star
7

ExceptNotifier

The Python package ExceptNotifier enhances the try-except statement, allowing you to receive detailed error messages via email or messenger apps.
Python
29
star
8

open-interview

Open Interview automates technical Q&A generation from resumes, offers document and audio outputs, and customizable settings for efficient interview prep.
Python
13
star
9

all-about-llm

dsdanielpark's curation and categorization of resources on large language models, along with documentation.
Python
13
star
10

arxiv2text

Converting PDF files to text, mainly with a focus on arXiv papers.
Jupyter Notebook
10
star
11

bard_api

A package that returns Response of Google BARD through API
Jupyter Notebook
4
star
12

CatchException

Nightly version of ExceptNotifier
Python
4
star
13

translang

Translation Service Module
Jupyter Notebook
3
star
14

multi-objective-recommender

OTTO โ€“ Multi-Objective Recommender System Build a recommender system based on real-world e-commerce sessions
3
star
15

doc-filter

Python package docfilter is used to detect and remove inappropriate information from text.
Python
2
star
16

fine-tuned-korean-BERT-news-article-classifier

Code will be open after de-identification
2
star
17

zoom-clone-coding

Zoom Clone using NodeJS, WebRTC and Websockets
JavaScript
2
star
18

smiles-featurizer

A Python package that automatically generates derived variables from a column with SMILES (Simplified Molecular-Input Line-Entry System)
Jupyter Notebook
2
star
19

fine-tuned-korean-bert-news-article-classifier

Compared BERT implementations in various frameworks and provides a model for classifying topics in Korean news articles.
Python
2
star
20

youtuber

Support tools including crawler, video editing, YouTube API, etc.
Python
2
star
21

openai-chatbot-clone

Test models served by openAI as APIs and check Python APIs for various functions. Finally, I deploy the my own trained model.
Jupyter Notebook
2
star
22

ko-llama-2-jindo

LLM Specializes in some task in Korean, aiming to generate natural language model
C++
2
star
23

airbnb-clone-coding

Create a replica of the popular home-sharing platform with custom features and design.
Python
1
star
24

util-function

Python package utilfunc wraps and distributes useful functions in an easy-to-use way.
Python
1
star
25

EDA-NIf

Tool for Exploratory Data Analysis of Neuroimaging Informatics Technology Initiative(NIfTI) format
Python
1
star
26

BardChat-SwiftApp

Swift
1
star
27

til

Today I Learned
Jupyter Notebook
1
star
28

game_evaluator

Provides a standardized quantitative indicator of a game's revenue and potential value.
1
star
29

google-driver

Python package google drive facilitates access to files uploaded to Google Drive.
Python
1
star
30

quick-show

Quick-Show provides simple but powerful insight plots.
Jupyter Notebook
1
star
31

BardAPI-for-Swift

Swift
1
star
32

todo-web-clone-coding

WebApp using VanillaJS
JavaScript
1
star
33

remix-blog

Technical blog for reserching
TypeScript
1
star
34

miccai2022-stroke-segmentation

ISCHEMIC STROKE LESION SEGMENTATION 2022 Challenge
Python
1
star
35

auto-unstar

Automatically unstar GitHub repositories with a simple Bash script
Shell
1
star
36

cost-ko

Cost efficient speach to text(STT) and text to speach(TTS) in Korean
1
star
37

edanlp

Tool for Exploratory Data Analysis of Natural language processing
1
star
38

dsdanielpark

1
star
39

nextjs

CSS
1
star
40

kmi2122-dataset

Korea Macroeconomic Indicators 2021-2022(monthly, 24 sequences)
Jupyter Notebook
1
star
41

machine-translation-using-bert

Jupyter Notebook
1
star
42

Bard-Desktop

Unofficial Google Bard Desktop App
Python
1
star
43

dsdanielpark.github.io

I enjoys learning and implementing innovative ideas while documenting and sharing my knowledge with others.
TeX
1
star
44

corpus-show

Corpus-Show helps to understand the corpus data distribution through various values generated from Sentence Transformer.
Jupyter Notebook
1
star