Skip to content

Amm1rr/WebAI-to-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Free Chatbot API

This project implements a Python web API that offers free access to three leading AI chatbots ChatGPT, Google Bard, and Claude through a single interface.

Key features:

  • Unified API endpoints allow seamlessly querying ChatGPT, Google Bard, and Claude from one integration.
  • Leverages the free web/browser versions of each AI service by managing cookies and sessions. Avoid costs of paid API access.
  • Simple API for text completion, question answering, and conversational queries. Integrate AI capabilities easily.
  • Lightweight Python server using FastAPI. Easily self-host locally or on your own infrastructure.
  • Full support for streaming responses.

  • Google Bard integration available now.
  • Claude-2 integration is also fully implemented and available.
  • ChatGPT integration is fully complete and available now.

Image



NOTE: This is a personal project involving the use of tools such as ShellGPT , ChatGPT Code Review and...
Please use them responsibly.

This repository is up-to-date.

Python version: >= 3.10


Usage

How to Find Your Tokens

Note: Claude and Bard offer two authentication options - you can either log in through your browser and skip this step, or you can follow the instructions below to configure the authentication.


First you need to add your tokens to the Config.conf file (see Configuration section).


Google Bard

Image

Google Bard: 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 /bard 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. (Screenshot)

  1. Login to bard.google.com
  2. Open Developer Tools (Press F12)
  3. Go to Application Tab
  4. Go to Cookies Tab
  5. Copy the content of __Secure-1PSID and __Secure-1PSIDTS. Copy the value of those cookie.
  6. Set in Config.conf file.



Claude 2

Image

Method 1:
For Claude, all you need to do is login to your account using your web browser. (Firefox, Chrome, Safari)

Method 2:
Claude: You can get cookie from the browser's developer tools network tab ( see for any claude.ai requests check out cookie ,copy whole value ) or storage tab ( You can find cookie of claude.ai ,there will be four values ) (Screenshot)

  1. Login to claude.ai
  2. Open Developer Tools (Press F12)
  3. Go to Network Tab
  4. Select an ajax request (like step 3 in picture)
  5. Copy the content of Cookie
  6. Set in Config.conf file.




ChatGPT

Image

ChatGPT: Please obtain the sessions mentioned here from an authorized session on chat.openai.com. The sessions can be used to send POST requests to the /chatgpt endpoint along with a message in a JSON payload. It is important that the session_id, which is your Authorization header session, is included in the request. (Screenshot)

  1. Login to chat.openai.com
  2. at least ask any question.
  3. Open Developer Tools (Press F12)
  4. Go to Network Tab
  5. Select an ajax request (like step 4 in picture)
  6. Copy the content of Authorization
  7. Set in Config.conf file.



Prerequisites

Before using the APIs, sign up for free accounts to get access credentials if you don't already have them:

Then, add your token(s) to the Config.conf file. (see Configuration section).

Note: Claude and Bard offer two authentication options - you can either log in through your browser and skip this step.

Installation


Step 1. Clone Repository

git clone https://github.com/Amm1rr/Free-Chatbot-API.git && cd Free-Chatbot-API

python -m venv .venv

source .venv/bin/activate  # Linux or macOS
.venv\Scripts\activate  # Windows


pip install -r requirements.txt

Step 2. Start Web Server

Navigate into the src directory, and run the web server using one of the methods below:

cd src/

python main.py

Available Endpoints:

#---------- Google Bard

http://128.0.0.1:8000/bard


#---------- Claude

http://128.0.0.1:8000/claude


#---------- ChatGPT

http://128.0.0.1:8000/chatgpt




#---------- ChatGPT JSON Response

http://128.0.0.1:8000/v1/chat/completions/




#---------- ChatGPT for ShellGPT

http://128.0.0.1:8000/v1/chat/completions/ShellGPT




#---------- ChatGPT for Code Review

http://128.0.0.1:8000/v1/chat/completions/CodeReview

1- ShellGPT | 2- ChatGPT Code Review


Input / Output

# Input:
_____

    {
      "session_id": "your-session-id",
      "message": "Hi, Who are you?",
      "stream": True
    }

--------------------

# Output:
_____

    {
      I'm a Chatbot assistant :)
    }

Example

try Claude with cURL

Once you have launched the webserver using uvicorn main:app --reload --port 8000 , run this cURL command in a terminal window:

curl -X 'POST' \
  'http://localhost:8000/claude' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "message": "who are you?",
  "session_id": "",
  "stream": true
}'

Note: The session_id is configured in the Config.conf file. If you send this variable empty, it will use the Config.conf



Configuration

How to Find Your Tokens

Note: Claude and Bard presents two authentication options - logging in through your browser or configuring Claude using the provided config file.

Config File Path:

  • Free-Chatbot-API\src\Config.conf
# Case-Sensative

[Claude]
COOKIE=[YOURS]

[Bard]
SESSION_ID=[YOURS]

[ChatGPT]
ACCESS_TOKEN=[YOURS]


Sources

Google Bard API | Claude API | revChatGPT


Licensing

This project is licensed under the MIT License. Feel free to use it however you like.