Development Status :: 5 - Production/Stable
The python package that returns response of Google Bard through value of cookie.
Please exercise caution and use this package responsibly.
The alpha releases of bardapi are version 0.1.18 and version 0.1.23a. This lightweight package focuses on the functionality of text generation and prevents any issues caused by the dependency packages used to add various methods.
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 Warning Do not expose the
__Secure-1PSID
- Visit https://bard.google.com/
- F12 for console
- Session: Application β Cookies β Copy the value of
__Secure-1PSIDcookie.
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
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']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']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']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.
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.
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.
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)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)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.
I would like to express my sincere gratitude for the contributions made by all the contributors.
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. Sincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.
- Core maintainer: Daniel Park, South Korea
- E-mail: parkminwoo1991@gmail.com
[1] https://github.com/acheong08/Bard
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.
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
