bardapi


Namebardapi JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/dsdanielpark/Bard-API
SummaryThe python package that returns Response of Google Bard through API.
upload_time2024-03-20 07:19:23
maintainerNone
docs_urlNone
authordaniel park
requires_python>=3.6
licenseNone
keywords python api bard google bard large language model chatbot api google api chatbot
VCS
bugtrack_url
requirements requests colorama httpx langdetect deep_translator google-cloud-translate browser_cookie3 python-gemini-api
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Development Status :: 7 - Inactive

<br>




[NOTICE] 
# Please, go to <img src="https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg" width="35px" alt="Gemini Icon" /> [Gemini API](https://github.com/dsdanielpark/Gemini-API)



A *unofficial* Python wrapper, [python-gemini-api](https://pypi.org/project/python-gemini-api/), operates through reverse-engineering, utilizing cookie values to interact with [Google Gemini](https://gemini.google.com) for users struggling with frequent authentication problems or unable to authenticate via [Google Authentication](https://developers.google.com/identity/protocols/oauth2?hl=en).

- Gemini API GitHub: https://github.com/dsdanielpark/Gemini-API
- PyPi: https://pypi.org/project/python-gemini-api/

Collaborated competently with [Antonio Cheong](https://github.com/acheong08).


## Installation
```bash
pip install python-gemini-api
```
```bash
pip install git+https://github.com/dsdanielpark/Gemini-API.git
```
For the updated version, use as follows:
```
pip install -q -U python-gemini-api
```
<br><br><br>

***

<br>
Reflection on the Bard API Project https://github.com/dsdanielpark/Bard-API/issues/289
<br>

# <img src="https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg" width="35px" alt="Gemini Icon" /> Google - Bard API

<p align="left">
<a href="https://github.com/dsdanielpark/Bard-API"><img alt="PyPI package" src="https://img.shields.io/badge/pypi-BardAPI-black"></a>
<!-- <a href="https://img.shields.io/pepy/dt/bardapi?logoColor=black"><img alt="Downloads" src="https://pepy.tech/badge/bardapi"></a> -->
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/%20downloads-379k-000000.svg"></a>
<!-- <a><img alt="commit update" src="https://img.shields.io/github/last-commit/dsdanielpark/Bard-API?color=black"></a> -->
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/dsdanielpark/Bard-API"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdsdanielpark%2FBARD_API&count_bg=%23000000&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=BardAPI&edge_flat=false"/></a>
<a href="https://github.com/dsdanielpark/Bard-API/stargazers"><img src="https://img.shields.io/github/stars/dsdanielpark/Bard-API?style=social"></a>
<a href="https://pypi.org/project/bardapi/"><img alt="PyPI" src="https://img.shields.io/pypi/v/bardapi"></a>
<!-- <a href="https://www.buymeacoffee.com/parkminwoo"><img src="https://cdn.buymeacoffee.com/buttons/v2/arial-orange.png" height="20px"></a> -->
  
</p>


> The python package that returns response of [Google Bard](https://gemini.google.com/) through value of cookie.

![](./assets/bard_api.gif)


**Please exercise caution and use this package responsibly. This python package is _UNOFFICIAL_.**

I referred to this github repository([github.com/acheong08/Bard](https://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 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. If you have access to reliable official [PaLM-2 API](https://blog.google/technology/ai/google-palm-2-ai-large-language-model/) or [Google Generative AI API](https://github.com/GoogleCloudPlatform/generative-ai), replace the provided response with the corresponding official code. Check out https://github.com/dsdanielpark/Bard-API/issues/262.

<br>

- [Google Bard API](#google--bard-api)
  - [What is Google Bard?](#what-is-google-gemini)
  - [Install](#install)
  - [Authentication](#authentication)
  - [Usage](#usage)
  - [Further](#further)
    - [Behind a proxy](#behind-a-proxy)
    - [Use rotating proxies](#use-rotating-proxies)
    - [Reusable session object](#reusable-session-object)
    - [Auto Cookie Bard](#auto-cookie-bard)
    - [Bard `ask_about_image` method](#bard-ask_about_image-method)
    - [Text To Speech(TTS) from Bard](#text-to-speechtts-from-bard)
  - [More features](#more-features)
  - [Amazing Bard Prompts Is All You Need!](#amazing-bard-prompts-is-all-you-need)
  - [The Python package hf-transllm](#the-python-package-hf-transllm)
  - [What is Google ~~Bard~~ Gemini?](#what-is-google-gemini)
  - [Google PaLM](#google-palm)
  - [FAQ](#faq)




<br>

## What is Google [Bard](https://gemini.google.com/chat)?
Bard is a conversational generative artificial intelligence chatbot developed by Google, based initially on the LaMDA family of LLMs(Large Language Models) and later the PaLM LLM. Please check official documents for [updates](https://gemini.google.com/updates) on Bard, including [available regions and languages](https://support.google.com/bard/answer/13575153?hl=en).


## Install
```
$ pip install bardapi
```
```
$ 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](https://github.com/dsdanielpark/Bard-API/tree/alpha-release) for more details.
```
$ pip install bardapi==0.1.23a
```

<br>

## Authentication
> **Warning** Do not expose the `__Secure-1PSID`. For testing purposes only; avoid direct application use. Cookie values change periodically (every 15-20 minutes). Frequent session changes may briefly block access; headless mode is challenging. Rate limiting applies and changes often. If the cookie changes, log out of your Google account, close the browser, and enter the new cookie value. Or manually reset the cookie for a new value. See FAQ and issue pages for details.
1. Visit https://gemini.google.com/
2. F12 for console
3. Session: Application → Cookies → Copy the value of  `__Secure-1PSID` cookie. Or try to use `SIDCC` as token.

Note that while I referred to `__Secure-1PSID` or `SIDCC` 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.

<br>

If you need to set multiple cookie values:

- [Multi-cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard) - 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.


<br>

## Usage 
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zzzlTIh0kt2MdjLzvXRby1rWbHzmog8t?usp=sharing) 


Simple Usage

```python
from bardapi import Bard

token = 'xxxxxxx'
bard = Bard(token=token)
bard.get_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")['content']
```
Or you can use this
```python
from bardapi import Bard
import os
os.environ['_BARD_API_KEY'] = "xxxxxxx"

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

To get reponse dictionary
```python
import bardapi

# 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.
```python
from bardapi import Bard
import os
os.environ['_BARD_API_KEY']="xxxxxxx"

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

<br>

## Further
### Behind a proxy
If you are working behind a proxy, use the following.
```python
from bardapi import Bard

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

### Use rotating proxies

If you want to **avoid blocked requests** and bans, then use [Smart Proxy by Crawlbase](https://crawlbase.com/docs/smart-proxy/?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api). It forwards your connection requests to a **randomly rotating IP address** in a pool of proxies before reaching the target website. The combination of AI and ML make it more effective to **avoid CAPTCHAs and blocks**.

```python
from bardapi import Bard
import requests

# Get your proxy url at crawlbase https://crawlbase.com/docs/smart-proxy/get/
proxy_url = "http://xxxxxxxxxxxxxx:@smartproxy.crawlbase.com:8012" 
proxies = {"http": proxy_url, "https": proxy_url}

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


### Reusable session object
You can continue the conversation using a reusable session. However, this feature is limited, and it is difficult for a package-level feature to perfectly maintain conversation_id and context. You can try to maintain the consistency of conversations same way as other LLM services, such as passing some sort of summary of past conversations to the DB.
```python
from bardapi import Bard
import requests
# import os
# os.environ['_BARD_API_KEY'] = 'xxxxxxx'
token = 'xxxxxxx'

session = requests.Session()
session.headers = {
            "Host": "gemini.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://gemini.google.com",
            "Referer": "https://gemini.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']
```

<details>
<summary>Async Bard Code (Click to expand)</summary>

```python
from httpx import AsyncClient
from bardapi import BardAsync
import os

# Uncomment and set your API key as needed
# os.environ['_BARD_API_KEY'] = 'xxxxxxx'
token = 'xxxxxxx'  # Replace with your actual token

SESSION_HEADERS = {
    "Host": "gemini.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://gemini.google.com",
    "Referer": "https://gemini.google.com/",
}
timeout = 30  # Example timeout
proxies = {}  # Replace with your proxies if needed

client = AsyncClient(
    http2=True,
    headers=SESSION_HEADERS,
    cookies={"__Secure-1PSID": token},
    timeout=timeout,
    proxies=proxies,
)

bard_async = BardAsync(token=token, client=client)

# Asynchronous function to get the answer
async def get_bard_answer(question):
    await bard_async.async_setup()  # Ensure async setup is done
    return await bard_async.get_answer(question)

response = await get_bard_answer("나와 내 동년배들이 좋아하는 뉴진스에 대해서 알려줘")
print(response['content'])
```

</details>


### Auto Cookie Bard
Using [browser_cookie3](https://github.com/borisbabic/browser_cookie3) we extract the `__Secure-1PSID` cookie from all browsers, and then we can use the API without passing the token. However, there are still incomplete dependency packages and various variables, so please seek assistance in the following [GitHub Issues](https://github.com/borisbabic/browser_cookie3/issues) or adjust your browser's version.
- Visit https://gemini.google.com/ in your browser and execute the following command while in the chat-enabled state. Refer to browser_cookie3 for details on how it works. If any issues arise, please restart the browser or log in to your Google account again. 
*Recommended to keep the browser open.*
```python
from bardapi import Bard

bard = Bard(token_from_browser=True)
response = bard.get_answer("Do you like cookies?")
print(response['content'])
```

### Bard `ask_about_image` method 
*It may not work as it is only available for certain accounts, regions, and other restrictions.*
As an experimental feature, it is possible to ask questions with an image. However, this functionality is only available for accounts with image upload capability in Bard's web UI. 

```python
from bardapi import Bard

bard = Bard(token='xxxxxxx')
image = open('image.jpg', 'rb').read() # (jpeg, png, webp) are supported.
bard_answer = bard.ask_about_image('What is in the image?', image)
print(bard_answer['content'])
```

### [Text To Speech(TTS)](https://cloud.google.com/text-to-speech?hl=ko) from Bard
Business users and high traffic volume may be subject to account restrictions according to Google's policies. Please use the [Official Google Cloud API](https://cloud.google.com/text-to-speech) for any other purpose. 
The user is solely responsible for all code, and it is imperative to consult Google's official services and policies. Furthermore, the code in this repository is provided under the MIT license, and it disclaims any liability, including explicit or implied legal responsibilities.
```python
from bardapi import Bard

bard = Bard(token='xxxxxxx')
audio = bard.speech('Hello, I am Bard! How can I help you today?')
with open("speech.ogg", "wb") as f:
  f.write(bytes(audio['audio']))
```

<br>

## [More features](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md)
Starting from version `0.1.18`, the GitHub version of BardAPI will be synchronized with the PyPI version and released simultaneously. However, the version undergoing QA can still be used from the GitHub repository.<br>
```
$ pip install git+https://github.com/dsdanielpark/Bard-API.git
```

- [Multi-cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard)
- [Auto Cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#auto-cookie-bard)
- [TTS from Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#text-to-speechtts)
- [Multi-language Bard API](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-language-bard-api)
- [Get image links](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#get-image-links)
- [ChatBard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#chatbard)
- [Export Conversation](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#export-conversation)
- [Export Code to Repl.it](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#export-code-to-replit)
- [Executing Python code received as a response from Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#chatbard)
- [Using Bard Asynchronously](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#using-bard-asynchronously)
- [Bard Cookies](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#bard-which-can-get-cookies)
- [Fix Coversation ID (Fix Context)](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#fix-conversation-id-fix-context)
- [Max_token, Max_sentences](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#max_token-max_sentence)
- [Translation to another programming language](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#translation-to-another-programming-language)


<br>



##  [Amazing Bard Prompts](https://github.com/dsdanielpark/amazing-bard-prompts) Is All You Need!
- Helpful prompts for Google Bard

<br>

## [The Python package hf-transllm](https://github.com/dsdanielpark/hf-transllm)
If you want to comfortably use the open-source LLM models in your native language, which are `released under the Apache License (allowing free commercial use)` in `various languages`, you can try using the [hf-transllm](https://github.com/dsdanielpark/hf-transllm) package. hf-transllm also supports multilingual inference for various LLMs stored in hugging face repository.

### Example code of [hf-transllm](https://github.com/dsdanielpark/hf-transllm)
<details>
<summary>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.</summary>

<br>

### 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](https://huggingface.co/models). Through the ranking information from [Open LLM Leader Board Report repository](https://github.com/dsdanielpark/Open-LLM-Leaderboard-Report), you can find information about good models.

#### For LLM that use languages `other than English`
```python
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:
```python
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)
```

</details>

<br>

## What is Google [Gemini](https://deepmind.google/technologies/gemini/#introduction)?
[Gemini](https://deepmind.google/technologies/gemini/#introduction) or formerly knowns as Bard is an advanced, multimodal AI model by [Google DeepMind](https://deepmind.google/), capable of understanding and integrating various information types like text, code, audio, images, and video.

- Paper: https://storage.googleapis.com/deepmind-media/gemini/gemini_1_report.pdf
- Web: https://blog.google/technology/ai/google-gemini-ai/#capabilities
- Code Guide: https://ai.google.dev/tutorials/python_quickstart
- Official API On [Google AI Studio](https://makersuite.google.com/app/apikey).

### Google AI Studio
Google AI Studio creates a new Google Cloud project for each new API key. You also can create an API key in an existing Google Cloud project. All projects are subject to the [Google Cloud Platform Terms of Service](https://cloud.google.com/terms).
- Web: https://makersuite.google.com/app/apikey
- Note: The Gemini API is currently in public preview. Production applications are not supported yet.

### Access to Gemini Pro in Bard API package
The Bard API, sourcing responses from [Google ~~Bard~~Gemini's official website](https://gemini.google.com/chat), allows you to receive the same responses as the website. So, if Gemini answers are available on the web, you can also accessed Gemini through the Bard API. However, it's important to note that responses might also come from other models, not exclusively Gemini Pro or Ultra. 
- There is no official Bard API or early access/waiting list for Gemini, although the [PaLM2 API](https://github.com/dsdanielpark/Bard-API#google-palm-api) is available.
  - Google's PaLM2 API differs from Bard, with some aspects of Bard being superior.
  - It's speculated that after expert review, Bard Advanced lineup will likely provide an official API in 2024.
- Gemini and previous generative AI model responses are provided randomly on Bard Web.
- The Bard API, with its imperfect extension features(e.g, `ask_about_image`), occasionally demonstrates Gemini's capabilities. This behavior may vary by region, language, or Google account.
- More information in the [FAQ](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_FAQ.md).

For more on Gemini:
- [Official API](https://makersuite.google.com/app/apikey)
- [Introducing Gemini: our largest and most capable AI model](https://blog.google/technology/ai/google-gemini-ai/)
- [How it's made: multimodal prompting](https://developers.googleblog.com/2023/12/how-its-made-gemini-multimodal-prompting.html)
- [YouTube Demo](https://www.youtube.com/watch?v=UIZAiXYceBI)

<br>



## Google PaLM
Try demo at https://makersuite.google.com/app/prompts/new_text.
```
who are you?
>> I am powered by PaLM 2, which stands for Pathways Language Model 2, a large language model from Google AI.
```

Google Generative AI
- Official Page: https://blog.google/technology/ai/google-palm-2-ai-large-language-model/
- GitHub: https://github.com/GoogleCloudPlatform/generative-ai
- Try Demo: https://makersuite.google.com/app/prompts/new_text.
- Official Library: https://makersuite.google.com/app/library
- Get API Key: https://makersuite.google.com/app/apikey
- Quick Start Tutorial: https://developers.generativeai.google/tutorials/text_quickstart

### Quick Start
```
$ pip install -q google-generativeai
```

```python
import pprint
import google.generativeai as palm

palm.configure(api_key='YOUR_API_KEY')

models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
model = models[0].name
print(model)

prompt = "Who are you?"

completion = palm.generate_text(
    model=model,
    prompt=prompt,
    temperature=0,
    # The maximum length of the response
    max_output_tokens=800,
)
print(completion.result)
```

<br>

<br>

## Sponsor

<a href="https://crawlbase.com/?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api"><img src="./assets/sponsor_ad.png"></a>
 
**Use data scraping to train your AI models.** 

- Easy to use **API to crawl and scrape** millions of websites
- Use crawlbase for efficient [data extraction](https://crawlbase.com/generative-ai-data?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api) for your **LLMs**
- Average **success rate: 98%**
- Uptime guarantee: **99.9%**
- [Simple docs](https://crawlbase.com/docs?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api) to get started in minutes
- **Asynchronous** Crawling **API** if you need massive amounts of data
- **GDPR** and **CCPA** compliant

Used by **70k+** developers. 


## [FAQ](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_FAQ.md)
Please check the FAQ and open issues for similar questions before creating a new issue. Repeated questions will be kept as open issues. Too many requests can trigger a temporary account block (HTTP 429). Maintain proper intervals, using functions like sleep to avoid rate limits. Policies may vary by country and language, so all users could face temporary or permanent errors via the API.

## Scripts
In the scripts [folder](./scripts/), I have released a script to help you compare [OpenAI-ChatGPT](./scripts/openai_api.ipynb), [Microsoft-EdgeGPT](./scripts/microsoft_api.ipynb) and [Google-Bard](./scripts/google_api.ipynb). I hope they will help more developers.

## Contributors
We would like to express our sincere gratitude to all the contributors.

<a href="https://github.com/dsdanielpark/Bard_API/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=dsdanielpark/Bard_API" />
</a>


<br>

## License
[MIT](https://opensource.org/license/mit/) <br>
We hold no legal responsibility; for more information, please refer to the bottom of the readme file. We just want you to give me and [them](https://github.com/acheong08/Bard) a star. This project is a personal initiative and is not affiliated with or endorsed by Google. It is recommended to use Google's official API.
```
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
- Core maintainer:
  - [Antonio Cheong](https://github.com/acheong08) / teapotv8@proton.me <br>
  - [Daniel Park](https://github.com/DSDanielPark) / parkminwoo1991@gmail.com

## Reference 
[1] https://github.com/acheong08/Bard <br>
            
> **Warning** 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.
    
> **Warning** 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.
  
<br><br>
  
*Copyright (c) 2023 MinWoo Park, South Korea*<br>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dsdanielpark/Bard-API",
    "name": "bardapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "Python, API, Bard, Google Bard, Large Language Model, Chatbot API, Google API, Chatbot",
    "author": "daniel park",
    "author_email": "parkminwoo1991@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/20/7e/4e2b8b6bd916dce889383e2e14e1de8bc3718ebc878917dafea042cbe70b/bardapi-1.0.0.tar.gz",
    "platform": null,
    "description": "Development Status :: 7 - Inactive\r\n\r\n<br>\r\n\r\n\r\n\r\n\r\n[NOTICE] \r\n# Please, go to <img src=\"https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg\" width=\"35px\" alt=\"Gemini Icon\" /> [Gemini API](https://github.com/dsdanielpark/Gemini-API)\r\n\r\n\r\n\r\nA *unofficial* Python wrapper, [python-gemini-api](https://pypi.org/project/python-gemini-api/), operates through reverse-engineering, utilizing cookie values to interact with [Google Gemini](https://gemini.google.com) for users struggling with frequent authentication problems or unable to authenticate via [Google Authentication](https://developers.google.com/identity/protocols/oauth2?hl=en).\r\n\r\n- Gemini API GitHub: https://github.com/dsdanielpark/Gemini-API\r\n- PyPi: https://pypi.org/project/python-gemini-api/\r\n\r\nCollaborated competently with [Antonio Cheong](https://github.com/acheong08).\r\n\r\n\r\n## Installation\r\n```bash\r\npip install python-gemini-api\r\n```\r\n```bash\r\npip install git+https://github.com/dsdanielpark/Gemini-API.git\r\n```\r\nFor the updated version, use as follows:\r\n```\r\npip install -q -U python-gemini-api\r\n```\r\n<br><br><br>\r\n\r\n***\r\n\r\n<br>\r\nReflection on the Bard API Project https://github.com/dsdanielpark/Bard-API/issues/289\r\n<br>\r\n\r\n# <img src=\"https://www.gstatic.com/lamda/images/favicon_v1_150160cddff7f294ce30.svg\" width=\"35px\" alt=\"Gemini Icon\" /> Google - Bard API\r\n\r\n<p align=\"left\">\r\n<a href=\"https://github.com/dsdanielpark/Bard-API\"><img alt=\"PyPI package\" src=\"https://img.shields.io/badge/pypi-BardAPI-black\"></a>\r\n<!-- <a href=\"https://img.shields.io/pepy/dt/bardapi?logoColor=black\"><img alt=\"Downloads\" src=\"https://pepy.tech/badge/bardapi\"></a> -->\r\n<a href=\"https://github.com/psf/black\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/%20downloads-379k-000000.svg\"></a>\r\n<!-- <a><img alt=\"commit update\" src=\"https://img.shields.io/github/last-commit/dsdanielpark/Bard-API?color=black\"></a> -->\r\n<a href=\"https://github.com/psf/black\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>\r\n<a href=\"https://github.com/dsdanielpark/Bard-API\"><img src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdsdanielpark%2FBARD_API&count_bg=%23000000&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=BardAPI&edge_flat=false\"/></a>\r\n<a href=\"https://github.com/dsdanielpark/Bard-API/stargazers\"><img src=\"https://img.shields.io/github/stars/dsdanielpark/Bard-API?style=social\"></a>\r\n<a href=\"https://pypi.org/project/bardapi/\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/bardapi\"></a>\r\n<!-- <a href=\"https://www.buymeacoffee.com/parkminwoo\"><img src=\"https://cdn.buymeacoffee.com/buttons/v2/arial-orange.png\" height=\"20px\"></a> -->\r\n  \r\n</p>\r\n\r\n\r\n> The python package that returns response of [Google Bard](https://gemini.google.com/) through value of cookie.\r\n\r\n![](./assets/bard_api.gif)\r\n\r\n\r\n**Please exercise caution and use this package responsibly. This python package is _UNOFFICIAL_.**\r\n\r\nI referred to this github repository([github.com/acheong08/Bard](https://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 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. If you have access to reliable official [PaLM-2 API](https://blog.google/technology/ai/google-palm-2-ai-large-language-model/) or [Google Generative AI API](https://github.com/GoogleCloudPlatform/generative-ai), replace the provided response with the corresponding official code. Check out https://github.com/dsdanielpark/Bard-API/issues/262.\r\n\r\n<br>\r\n\r\n- [Google Bard API](#google--bard-api)\r\n  - [What is Google Bard?](#what-is-google-gemini)\r\n  - [Install](#install)\r\n  - [Authentication](#authentication)\r\n  - [Usage](#usage)\r\n  - [Further](#further)\r\n    - [Behind a proxy](#behind-a-proxy)\r\n    - [Use rotating proxies](#use-rotating-proxies)\r\n    - [Reusable session object](#reusable-session-object)\r\n    - [Auto Cookie Bard](#auto-cookie-bard)\r\n    - [Bard `ask_about_image` method](#bard-ask_about_image-method)\r\n    - [Text To Speech(TTS) from Bard](#text-to-speechtts-from-bard)\r\n  - [More features](#more-features)\r\n  - [Amazing Bard Prompts Is All You Need!](#amazing-bard-prompts-is-all-you-need)\r\n  - [The Python package hf-transllm](#the-python-package-hf-transllm)\r\n  - [What is Google ~~Bard~~ Gemini?](#what-is-google-gemini)\r\n  - [Google PaLM](#google-palm)\r\n  - [FAQ](#faq)\r\n\r\n\r\n\r\n\r\n<br>\r\n\r\n## What is Google [Bard](https://gemini.google.com/chat)?\r\nBard is a conversational generative artificial intelligence chatbot developed by Google, based initially on the LaMDA family of LLMs(Large Language Models) and later the PaLM LLM. Please check official documents for [updates](https://gemini.google.com/updates) on Bard, including [available regions and languages](https://support.google.com/bard/answer/13575153?hl=en).\r\n\r\n\r\n## Install\r\n```\r\n$ pip install bardapi\r\n```\r\n```\r\n$ pip install git+https://github.com/dsdanielpark/Bard-API.git\r\n```\r\nDue 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](https://github.com/dsdanielpark/Bard-API/tree/alpha-release) for more details.\r\n```\r\n$ pip install bardapi==0.1.23a\r\n```\r\n\r\n<br>\r\n\r\n## Authentication\r\n> **Warning** Do not expose the `__Secure-1PSID`. For testing purposes only; avoid direct application use. Cookie values change periodically (every 15-20 minutes). Frequent session changes may briefly block access; headless mode is challenging. Rate limiting applies and changes often. If the cookie changes, log out of your Google account, close the browser, and enter the new cookie value. Or manually reset the cookie for a new value. See FAQ and issue pages for details.\r\n1. Visit https://gemini.google.com/\r\n2. F12 for console\r\n3. Session: Application \u2192 Cookies \u2192 Copy the value of  `__Secure-1PSID` cookie. Or try to use `SIDCC` as token.\r\n\r\nNote that while I referred to `__Secure-1PSID` or `SIDCC` value as an API key for convenience, it is not an officially provided API key. \r\nCookie value subject to frequent changes. Verify the value again if an error occurs. Most errors occur when an invalid cookie value is entered.\r\n\r\n<br>\r\n\r\nIf you need to set multiple cookie values:\r\n\r\n- [Multi-cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard) - 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.\r\n\r\n\r\n<br>\r\n\r\n## Usage \r\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zzzlTIh0kt2MdjLzvXRby1rWbHzmog8t?usp=sharing) \r\n\r\n\r\nSimple Usage\r\n\r\n```python\r\nfrom bardapi import Bard\r\n\r\ntoken = 'xxxxxxx'\r\nbard = Bard(token=token)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\nOr you can use this\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nos.environ['_BARD_API_KEY'] = \"xxxxxxx\"\r\n\r\nBard().get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\nTo get reponse dictionary\r\n```python\r\nimport bardapi\r\n\r\n# set your __Secure-1PSID value to key\r\ntoken = 'xxxxxxx'\r\n\r\n# set your input text\r\ninput_text = \"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\"\r\n\r\n# Send an API request and get a response.\r\nresponse = bardapi.core.Bard(token).get_answer(input_text)\r\n```\r\n\r\n\r\n\r\nAddressing 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.\r\n```python\r\nfrom bardapi import Bard\r\nimport os\r\nos.environ['_BARD_API_KEY']=\"xxxxxxx\"\r\n\r\nbard = Bard(timeout=30) # Set timeout in seconds\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\n<br>\r\n\r\n## Further\r\n### Behind a proxy\r\nIf you are working behind a proxy, use the following.\r\n```python\r\nfrom bardapi import Bard\r\n\r\n# Change 'http://proxy.example.com:8080' to your http proxy\r\n# timeout in seconds\r\nproxies = {\r\n    'http': 'http://proxy.example.com:8080',\r\n    'https': 'https://proxy.example.com:8080'\r\n}\r\n\r\nbard = Bard(token='xxxxxxx', proxies=proxies, timeout=30)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\n### Use rotating proxies\r\n\r\nIf you want to **avoid blocked requests** and bans, then use [Smart Proxy by Crawlbase](https://crawlbase.com/docs/smart-proxy/?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api). It forwards your connection requests to a **randomly rotating IP address** in a pool of proxies before reaching the target website. The combination of AI and ML make it more effective to **avoid CAPTCHAs and blocks**.\r\n\r\n```python\r\nfrom bardapi import Bard\r\nimport requests\r\n\r\n# Get your proxy url at crawlbase https://crawlbase.com/docs/smart-proxy/get/\r\nproxy_url = \"http://xxxxxxxxxxxxxx:@smartproxy.crawlbase.com:8012\" \r\nproxies = {\"http\": proxy_url, \"https\": proxy_url}\r\n\r\nbard = Bard(token='xxxxxxx', proxies=proxies, timeout=30)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n```\r\n\r\n\r\n### Reusable session object\r\nYou can continue the conversation using a reusable session. However, this feature is limited, and it is difficult for a package-level feature to perfectly maintain conversation_id and context. You can try to maintain the consistency of conversations same way as other LLM services, such as passing some sort of summary of past conversations to the DB.\r\n```python\r\nfrom bardapi import Bard\r\nimport requests\r\n# import os\r\n# os.environ['_BARD_API_KEY'] = 'xxxxxxx'\r\ntoken = 'xxxxxxx'\r\n\r\nsession = requests.Session()\r\nsession.headers = {\r\n            \"Host\": \"gemini.google.com\",\r\n            \"X-Same-Domain\": \"1\",\r\n            \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36\",\r\n            \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\",\r\n            \"Origin\": \"https://gemini.google.com\",\r\n            \"Referer\": \"https://gemini.google.com/\",\r\n        }\r\n# session.cookies.set(\"__Secure-1PSID\", os.getenv(\"_BARD_API_KEY\")) \r\nsession.cookies.set(\"__Secure-1PSID\", token) \r\n\r\nbard = Bard(token=token, session=session, timeout=30)\r\nbard.get_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")['content']\r\n\r\n# Continued conversation without set new session\r\nbard.get_answer(\"What is my last prompt??\")['content']\r\n```\r\n\r\n<details>\r\n<summary>Async Bard Code (Click to expand)</summary>\r\n\r\n```python\r\nfrom httpx import AsyncClient\r\nfrom bardapi import BardAsync\r\nimport os\r\n\r\n# Uncomment and set your API key as needed\r\n# os.environ['_BARD_API_KEY'] = 'xxxxxxx'\r\ntoken = 'xxxxxxx'  # Replace with your actual token\r\n\r\nSESSION_HEADERS = {\r\n    \"Host\": \"gemini.google.com\",\r\n    \"X-Same-Domain\": \"1\",\r\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36\",\r\n    \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\",\r\n    \"Origin\": \"https://gemini.google.com\",\r\n    \"Referer\": \"https://gemini.google.com/\",\r\n}\r\ntimeout = 30  # Example timeout\r\nproxies = {}  # Replace with your proxies if needed\r\n\r\nclient = AsyncClient(\r\n    http2=True,\r\n    headers=SESSION_HEADERS,\r\n    cookies={\"__Secure-1PSID\": token},\r\n    timeout=timeout,\r\n    proxies=proxies,\r\n)\r\n\r\nbard_async = BardAsync(token=token, client=client)\r\n\r\n# Asynchronous function to get the answer\r\nasync def get_bard_answer(question):\r\n    await bard_async.async_setup()  # Ensure async setup is done\r\n    return await bard_async.get_answer(question)\r\n\r\nresponse = await get_bard_answer(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")\r\nprint(response['content'])\r\n```\r\n\r\n</details>\r\n\r\n\r\n### Auto Cookie Bard\r\nUsing [browser_cookie3](https://github.com/borisbabic/browser_cookie3) we extract the `__Secure-1PSID` cookie from all browsers, and then we can use the API without passing the token. However, there are still incomplete dependency packages and various variables, so please seek assistance in the following [GitHub Issues](https://github.com/borisbabic/browser_cookie3/issues) or adjust your browser's version.\r\n- Visit https://gemini.google.com/ in your browser and execute the following command while in the chat-enabled state. Refer to browser_cookie3 for details on how it works. If any issues arise, please restart the browser or log in to your Google account again. \r\n*Recommended to keep the browser open.*\r\n```python\r\nfrom bardapi import Bard\r\n\r\nbard = Bard(token_from_browser=True)\r\nresponse = bard.get_answer(\"Do you like cookies?\")\r\nprint(response['content'])\r\n```\r\n\r\n### Bard `ask_about_image` method \r\n*It may not work as it is only available for certain accounts, regions, and other restrictions.*\r\nAs an experimental feature, it is possible to ask questions with an image. However, this functionality is only available for accounts with image upload capability in Bard's web UI. \r\n\r\n```python\r\nfrom bardapi import Bard\r\n\r\nbard = Bard(token='xxxxxxx')\r\nimage = open('image.jpg', 'rb').read() # (jpeg, png, webp) are supported.\r\nbard_answer = bard.ask_about_image('What is in the image?', image)\r\nprint(bard_answer['content'])\r\n```\r\n\r\n### [Text To Speech(TTS)](https://cloud.google.com/text-to-speech?hl=ko) from Bard\r\nBusiness users and high traffic volume may be subject to account restrictions according to Google's policies. Please use the [Official Google Cloud API](https://cloud.google.com/text-to-speech) for any other purpose. \r\nThe user is solely responsible for all code, and it is imperative to consult Google's official services and policies. Furthermore, the code in this repository is provided under the MIT license, and it disclaims any liability, including explicit or implied legal responsibilities.\r\n```python\r\nfrom bardapi import Bard\r\n\r\nbard = Bard(token='xxxxxxx')\r\naudio = bard.speech('Hello, I am Bard! How can I help you today?')\r\nwith open(\"speech.ogg\", \"wb\") as f:\r\n  f.write(bytes(audio['audio']))\r\n```\r\n\r\n<br>\r\n\r\n## [More features](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md)\r\nStarting from version `0.1.18`, the GitHub version of BardAPI will be synchronized with the PyPI version and released simultaneously. However, the version undergoing QA can still be used from the GitHub repository.<br>\r\n```\r\n$ pip install git+https://github.com/dsdanielpark/Bard-API.git\r\n```\r\n\r\n- [Multi-cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard)\r\n- [Auto Cookie Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#auto-cookie-bard)\r\n- [TTS from Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#text-to-speechtts)\r\n- [Multi-language Bard API](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-language-bard-api)\r\n- [Get image links](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#get-image-links)\r\n- [ChatBard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#chatbard)\r\n- [Export Conversation](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#export-conversation)\r\n- [Export Code to Repl.it](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#export-code-to-replit)\r\n- [Executing Python code received as a response from Bard](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#chatbard)\r\n- [Using Bard Asynchronously](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#using-bard-asynchronously)\r\n- [Bard Cookies](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#bard-which-can-get-cookies)\r\n- [Fix Coversation ID (Fix Context)](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#fix-conversation-id-fix-context)\r\n- [Max_token, Max_sentences](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#max_token-max_sentence)\r\n- [Translation to another programming language](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#translation-to-another-programming-language)\r\n\r\n\r\n<br>\r\n\r\n\r\n\r\n##  [Amazing Bard Prompts](https://github.com/dsdanielpark/amazing-bard-prompts) Is All You Need!\r\n- Helpful prompts for Google Bard\r\n\r\n<br>\r\n\r\n## [The Python package hf-transllm](https://github.com/dsdanielpark/hf-transllm)\r\nIf you want to comfortably use the open-source LLM models in your native language, which are `released under the Apache License (allowing free commercial use)` in `various languages`, you can try using the [hf-transllm](https://github.com/dsdanielpark/hf-transllm) package. hf-transllm also supports multilingual inference for various LLMs stored in hugging face repository.\r\n\r\n### Example code of [hf-transllm](https://github.com/dsdanielpark/hf-transllm)\r\n<details>\r\n<summary>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.</summary>\r\n\r\n<br>\r\n\r\n### Usage\r\nFor 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](https://huggingface.co/models). Through the ranking information from [Open LLM Leader Board Report repository](https://github.com/dsdanielpark/Open-LLM-Leaderboard-Report), you can find information about good models.\r\n\r\n#### For LLM that use languages `other than English`\r\n```python\r\nfrom transllm import LLMtranslator\r\n\r\nopen_llama3b_kor = LLMtranslator('openlm-research/open_llama_3b', target_lang='ko', translator='google') # Korean\r\n\r\ntrnaslated_answer = open_llama3b_kor.generate(\"\ub098\uc640 \ub0b4 \ub3d9\ub144\ubc30\ub4e4\uc774 \uc88b\uc544\ud558\ub294 \ub274\uc9c4\uc2a4\uc5d0 \ub300\ud574\uc11c \uc54c\ub824\uc918\")\r\nprint(trnaslated_answer)\r\n```\r\n\r\n#### For LLM that use `English`\r\nRefer https://github.com/openlm-research/open_llama or using like this:\r\n```python\r\nfrom transllm import LLMtranslator\r\n\r\nopen_llama3b = LLMtranslator('openlm-research/open_llama_3b) \r\n\r\nanswer = open_llama3b.generate(\"Tell me about the Korean girl group Newjeans.\")\r\nprint(answer)\r\n```\r\n\r\n</details>\r\n\r\n<br>\r\n\r\n## What is Google [Gemini](https://deepmind.google/technologies/gemini/#introduction)?\r\n[Gemini](https://deepmind.google/technologies/gemini/#introduction) or formerly knowns as Bard is an advanced, multimodal AI model by [Google DeepMind](https://deepmind.google/), capable of understanding and integrating various information types like text, code, audio, images, and video.\r\n\r\n- Paper: https://storage.googleapis.com/deepmind-media/gemini/gemini_1_report.pdf\r\n- Web: https://blog.google/technology/ai/google-gemini-ai/#capabilities\r\n- Code Guide: https://ai.google.dev/tutorials/python_quickstart\r\n- Official API On [Google AI Studio](https://makersuite.google.com/app/apikey).\r\n\r\n### Google AI Studio\r\nGoogle AI Studio creates a new Google Cloud project for each new API key. You also can create an API key in an existing Google Cloud project. All projects are subject to the [Google Cloud Platform Terms of Service](https://cloud.google.com/terms).\r\n- Web: https://makersuite.google.com/app/apikey\r\n- Note: The Gemini API is currently in public preview. Production applications are not supported yet.\r\n\r\n### Access to Gemini Pro in Bard API package\r\nThe Bard API, sourcing responses from [Google ~~Bard~~Gemini's official website](https://gemini.google.com/chat), allows you to receive the same responses as the website. So, if Gemini answers are available on the web, you can also accessed Gemini through the Bard API. However, it's important to note that responses might also come from other models, not exclusively Gemini Pro or Ultra. \r\n- There is no official Bard API or early access/waiting list for Gemini, although the [PaLM2 API](https://github.com/dsdanielpark/Bard-API#google-palm-api) is available.\r\n  - Google's PaLM2 API differs from Bard, with some aspects of Bard being superior.\r\n  - It's speculated that after expert review, Bard Advanced lineup will likely provide an official API in 2024.\r\n- Gemini and previous generative AI model responses are provided randomly on Bard Web.\r\n- The Bard API, with its imperfect extension features(e.g, `ask_about_image`), occasionally demonstrates Gemini's capabilities. This behavior may vary by region, language, or Google account.\r\n- More information in the [FAQ](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_FAQ.md).\r\n\r\nFor more on Gemini:\r\n- [Official API](https://makersuite.google.com/app/apikey)\r\n- [Introducing Gemini: our largest and most capable AI model](https://blog.google/technology/ai/google-gemini-ai/)\r\n- [How it's made: multimodal prompting](https://developers.googleblog.com/2023/12/how-its-made-gemini-multimodal-prompting.html)\r\n- [YouTube Demo](https://www.youtube.com/watch?v=UIZAiXYceBI)\r\n\r\n<br>\r\n\r\n\r\n\r\n## Google PaLM\r\nTry demo at https://makersuite.google.com/app/prompts/new_text.\r\n```\r\nwho are you?\r\n>> I am powered by PaLM 2, which stands for Pathways Language Model 2, a large language model from Google AI.\r\n```\r\n\r\nGoogle Generative AI\r\n- Official Page: https://blog.google/technology/ai/google-palm-2-ai-large-language-model/\r\n- GitHub: https://github.com/GoogleCloudPlatform/generative-ai\r\n- Try Demo: https://makersuite.google.com/app/prompts/new_text.\r\n- Official Library: https://makersuite.google.com/app/library\r\n- Get API Key: https://makersuite.google.com/app/apikey\r\n- Quick Start Tutorial: https://developers.generativeai.google/tutorials/text_quickstart\r\n\r\n### Quick Start\r\n```\r\n$ pip install -q google-generativeai\r\n```\r\n\r\n```python\r\nimport pprint\r\nimport google.generativeai as palm\r\n\r\npalm.configure(api_key='YOUR_API_KEY')\r\n\r\nmodels = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]\r\nmodel = models[0].name\r\nprint(model)\r\n\r\nprompt = \"Who are you?\"\r\n\r\ncompletion = palm.generate_text(\r\n    model=model,\r\n    prompt=prompt,\r\n    temperature=0,\r\n    # The maximum length of the response\r\n    max_output_tokens=800,\r\n)\r\nprint(completion.result)\r\n```\r\n\r\n<br>\r\n\r\n<br>\r\n\r\n## Sponsor\r\n\r\n<a href=\"https://crawlbase.com/?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api\"><img src=\"./assets/sponsor_ad.png\"></a>\r\n \r\n**Use data scraping to train your AI models.** \r\n\r\n- Easy to use **API to crawl and scrape** millions of websites\r\n- Use crawlbase for efficient [data extraction](https://crawlbase.com/generative-ai-data?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api) for your **LLMs**\r\n- Average **success rate: 98%**\r\n- Uptime guarantee: **99.9%**\r\n- [Simple docs](https://crawlbase.com/docs?utm_source=github_ad&utm_medium=social&utm_campaign=bard_api) to get started in minutes\r\n- **Asynchronous** Crawling **API** if you need massive amounts of data\r\n- **GDPR** and **CCPA** compliant\r\n\r\nUsed by **70k+** developers. \r\n\r\n\r\n## [FAQ](https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_FAQ.md)\r\nPlease check the FAQ and open issues for similar questions before creating a new issue. Repeated questions will be kept as open issues. Too many requests can trigger a temporary account block (HTTP 429). Maintain proper intervals, using functions like sleep to avoid rate limits. Policies may vary by country and language, so all users could face temporary or permanent errors via the API.\r\n\r\n## Scripts\r\nIn the scripts [folder](./scripts/), I have released a script to help you compare [OpenAI-ChatGPT](./scripts/openai_api.ipynb), [Microsoft-EdgeGPT](./scripts/microsoft_api.ipynb) and [Google-Bard](./scripts/google_api.ipynb). I hope they will help more developers.\r\n\r\n## Contributors\r\nWe would like to express our sincere gratitude to all the contributors.\r\n\r\n<a href=\"https://github.com/dsdanielpark/Bard_API/graphs/contributors\">\r\n  <img src=\"https://contrib.rocks/image?repo=dsdanielpark/Bard_API\" />\r\n</a>\r\n\r\n\r\n<br>\r\n\r\n## License\r\n[MIT](https://opensource.org/license/mit/) <br>\r\nWe hold no legal responsibility; for more information, please refer to the bottom of the readme file. We just want you to give me and [them](https://github.com/acheong08/Bard) a star. This project is a personal initiative and is not affiliated with or endorsed by Google. It is recommended to use Google's official API.\r\n```\r\nThe MIT License (MIT)\r\n\r\nCopyright (c) 2023 Minwoo Park\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n```\r\n\r\n## Shifting Service Policies: Bard and Google's Dynamics \r\nBard'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.\r\n            \r\n## Bugs and Issues\r\nSincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated.\r\n\r\n## Contacts\r\n- Core maintainer:\r\n  - [Antonio Cheong](https://github.com/acheong08) / teapotv8@proton.me <br>\r\n  - [Daniel Park](https://github.com/DSDanielPark) / parkminwoo1991@gmail.com\r\n\r\n## Reference \r\n[1] https://github.com/acheong08/Bard <br>\r\n            \r\n> **Warning** Important Notice\r\n  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.\r\n    \r\n> **Warning** Caution\r\nThis 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.\r\n  \r\n<br><br>\r\n  \r\n*Copyright (c) 2023 MinWoo Park, South Korea*<br>\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "The python package that returns Response of Google Bard through API.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/dsdanielpark/Bard-API"
    },
    "split_keywords": [
        "python",
        " api",
        " bard",
        " google bard",
        " large language model",
        " chatbot api",
        " google api",
        " chatbot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1fbd9b9ccda10e698064ac4dd7dda3d38091c98993833147b3c0009e9416b5a1",
                "md5": "56d8c368170baa7b3bda39831d481700",
                "sha256": "97433a15fb970940b3a54ce59429d89c86b79c63a6810c55a3086c1f86c34a6c"
            },
            "downloads": -1,
            "filename": "bardapi-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "56d8c368170baa7b3bda39831d481700",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 48522,
            "upload_time": "2024-03-20T07:19:06",
            "upload_time_iso_8601": "2024-03-20T07:19:06.985720Z",
            "url": "https://files.pythonhosted.org/packages/1f/bd/9b9ccda10e698064ac4dd7dda3d38091c98993833147b3c0009e9416b5a1/bardapi-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "207e4e2b8b6bd916dce889383e2e14e1de8bc3718ebc878917dafea042cbe70b",
                "md5": "172e14904bab6523e340fd8b293d3331",
                "sha256": "07c7ca9113979cf058f5952cf12ee173310b412f93e7c5441d21f55caff05ec6"
            },
            "downloads": -1,
            "filename": "bardapi-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "172e14904bab6523e340fd8b293d3331",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 49734,
            "upload_time": "2024-03-20T07:19:23",
            "upload_time_iso_8601": "2024-03-20T07:19:23.208507Z",
            "url": "https://files.pythonhosted.org/packages/20/7e/4e2b8b6bd916dce889383e2e14e1de8bc3718ebc878917dafea042cbe70b/bardapi-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 07:19:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dsdanielpark",
    "github_project": "Bard-API",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "colorama",
            "specs": []
        },
        {
            "name": "httpx",
            "specs": [
                [
                    ">=",
                    "0.20.0"
                ]
            ]
        },
        {
            "name": "langdetect",
            "specs": []
        },
        {
            "name": "deep_translator",
            "specs": []
        },
        {
            "name": "google-cloud-translate",
            "specs": []
        },
        {
            "name": "browser_cookie3",
            "specs": []
        },
        {
            "name": "python-gemini-api",
            "specs": [
                [
                    ">",
                    "2.3.0"
                ]
            ]
        }
    ],
    "lcname": "bardapi"
}
        
Elapsed time: 1.80784s