This project provides a FastAPI wrapper for interacting with Google Bard, a conversational AI by Google. It includes a library for sending requests to Google Bard, and a simple API server for interacting with Bard through a REST API. This allows users to integrate Bard with their own applications or services through a single API endpoint.
These instructions will help you set up and run the project on your local machine for development and testing purposes.
- Python 3.9 or higher
- Docker
- Clone the repository:
git clone https://github.com/ra83205/google-bard-api.git
cd google-bard-api
- Create a virtual environment and install the required packages:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Run the application using Uvicorn:
uvicorn main:app --reload --port 8000
The application should now be running at https://localhost:8000
.
Please obtain the cookies mentioned here from an authorized session on bard.google.com. The cookies can be used to send POST requests to the /ask endpoint along with a message in a JSON payload. It is important that the session_id, which is your __Secure-1PSID cookie, is included in the request.
Example request using cURL:
curl -X POST "https://localhost:8000/ask" -H "accept: application/json" -H "Content-Type: application/json" -d '{"session_id":"your-session-id","message":"What is the meaning of life?"}'
Example request using Postman:
-
Open Postman and select the "POST" method
-
Enter the URL:
https://localhost:8000/ask
-
Select the "Headers" tab and add a new key-value pair:
Content-Type: application/json
-
Select the "Body" tab, choose the "raw" option, and input the following JSON payload:
{ "session_id": "your-session-id", "message": "What is the meaning of life?" }
-
Click "Send" to submit the request.
You should receive a JSON response from Google Bard containing the response message.
Note: If you want to protect the /ask
endpoint with an authentication key, you can set the USER_AUTH_KEY
environment variable to a string value of your choice. The authentication key will be compared against the Authorization
header of incoming requests.
To deploy this application using Docker, follow these steps:
- Build the Docker image:
docker build -t your-image-name .
- Run the Docker container:
docker run -p 8000:80 your-image-name
The application should now be running at https://localhost:8000
.
I'm open to collaborating with other developers who want to help expand the functionality of this project. Feel free to fork the repository and submit a pull request with your proposed changes. I'd be happy to review them and merge them in if they're a good fit.
The code provided in this project is available for anyone to use for any purpose without any restrictions or warranties.
- Google for creating Google Bard
- FastAPI for providing a simple and efficient web framework