Bard-API is a python package that allows us to use Bard via python script.
dsdanielpark / Bard-API
The unofficial python package that returns response of Google Bard through cookie value.
Development Status :: 7 - Inactive
[NOTICE]
Please, go to Gemini API
A unofficial Python wrapper, python-gemini-api, operates through reverse-engineering, utilizing cookie values to interact with Google Gemini for users struggling with frequent authentication problems or unable to authenticate via Google Authentication.
- Gemini API GitHub: https://github.com/dsdanielpark/Gemini-API
- PyPi: https://pypi.org/project/python-gemini-api/
Collaborated competently with Antonio Cheong.
Installation
pip install python-gemini-api
pip install git+https://github.com/dsdanielpark/Gemini-API.git
For the updated version, use as follows:
pip install -q -U python-gemini-api
Reflection on the Bard API Project #289
The python package that returns response of Google Bard through value of cookie.
Please exercise caution and use this package responsibly. This python package is UNOFFICIAL.
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. Please note that the bardapi is not a…
Step 1. Get cookie data
Go to https://bard.google.com and open Chrome Developer tools and click Application
tab.
Click Cookies
under Storage
and copy the value of _Secure-1PSID
.
Step 2. Install Bard-API and python-dotenv
pip install bardapi
or
pip install git+https://github.com/dsdanielpark/Bard-API.git
pip install python-dotenv
Step 3. Create .env file
COOKIE_TOKEN='put your cookie value'
Step 4. Write code
import os
from bardapi import Bard
from dotenv import load_dotenv
load_dotenv()
token = os.environ['COOKIE_TOKEN']
bard = Bard(token=token)
response = bard.get_answer("What is a LLM?")['content']
print(response)
output
LLM stands for Master of Laws. It is a postgraduate law degree that is typically obtained after completing a Juris Doctor (JD) degree. LLM programs can be general or specialized, and they can be offered in a variety of subjects, such as tax law, environmental law, and international law.
The LLM degree is a valuable credential for lawyers who want to specialize in a particular area of law or who want to advance their careers in academia or government. LLM programs can also help lawyers to develop their research and writing skills, which are essential for success in many legal careers.
The full form of LLM is Legum Magister, which is Latin for "Master of Laws." The LLM degree is abbreviated as LL.M. in English.
Here are some of the benefits of obtaining an LLM degree:
* **Specialization:** LLM programs allow you to specialize in a particular area of law, such as tax law, environmental law, or international law. This can give you a competitive edge in the job market and help you to advance your career.
* **Research and writing skills:** LLM programs can help you to develop your research and writing skills, which are essential for success in many legal careers.
* **International experience:** Many LLM programs are offered in countries outside of the United States. This can give you the opportunity to gain international experience and learn about different legal systems.
If you are interested in pursuing an LLM degree, there are a few things you should keep in mind:
* **Admission requirements:** Admission requirements for LLM programs vary from school to school. However, most programs require that you have a JD degree or an equivalent law degree.
* **Cost:** The cost of an LLM degree can vary depending on the school and the program. However, LLM programs can be expensive, so it is important to factor in the cost when making your decision.
* **Career opportunities:** LLM degrees can open up a variety of career opportunities for lawyers. However, the specific opportunities that are available to you will depend on your area of specialization and your work experience.
If you are considering pursuing an LLM degree, I recommend that you research different programs and talk to lawyers who have LLM degrees. This will help you to make an informed decision about whether or not an LLM degree is right for you.
Specify output format
Also we can change the output format like ChatGPT.
import os
from bardapi import Bard
from dotenv import load_dotenv
load_dotenv()
token = os.environ['COOKIE_TOKEN']
bard = Bard(token=token)
prompt='''
What is a LLM?
The answer format should be the following.
answer: {
[
id: 1,
content: draft1
],
id: 2,
content: draft2
]
}
'''
response = bard.get_answer(prompt)['content']
print(response)
Get Drafts
If you use Bard, you know Bard has a couple of drafts. Bard-API can get them.
import os
from bardapi import Bard
from dotenv import load_dotenv
load_dotenv()
token = os.environ['COOKIE_TOKEN']
bard = Bard(token=token)
prompt='What is a LLM?'
responses = bard.get_answer(prompt)['choices']
for choice in responses:
id = choice['id']
response = choice['content'][0]
print(id)
print(response)
Top comments (2)
Hey i am getting the error for running the above code
mycode:
load_dotenv()
bard = Bard(token="xxxxxx")
response = bard.get_answer('What are the stocks with the ratio less than 10')['content']
print(response)
Error:Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as token='xxxxx'.
can you help me out?
Did you pass
__Secure-1PSID
as token ?