Skip to main content

Reverse Engineering of ChatGPT Web-Version

Project description

WebChatGPT

Python Test License PyPi Black Passing coverage Progress Downloads Latest release release date wakatime

Reverse Engineering of ChatGPT in Python.

Unlike the official Openai library, this library makes REST-API calls to ChatGPT via the browser endpoints. No API-KEY required

from WebChatGPT import ChatGPT
bot = ChatGPT(
    "<path-to-openai-cookies.json>"
)
response = bot.chat('<Your prompt>')

print(response)
#Ouput : What can I do for you today?

Prerequisites

Installation & usage

Installation

Either of the following ways will get you ready :

  1. From pypi:
pip install --upgrade webchatgpt
  1. From source
pip install git+https://github.com/Simatwa/WebChatGPT.git

Usage

The script utilizes HTTP Cookies and OAuth to justify the REST-API requests at Openai.

In order to do that, we will use the export-cookie-for-puppeteer extension to extract the cookies which will later on used to retrieve the OAuth.

Procedure

  1. Login to https://chat.openai.com
  2. Upon successfull login, use Export cookie JSON File Puppeteer to export cookies. If you haven't installed the extension, here are the quick installation links for you.

By doing that you are good to go.

  • Converse Interactively:
$ webchatgpt interactive -C <path-to-openai-cookie-file.json> "<your startup prompt though not a must>"
  • Have a quick response
$ webchatgpt generate -C <path-to-openai-cookie-file.json> "<your prompt here>"
  • Since generate is the default option so something like this will this workout. $ webchatgpt -C <path-to-openai-cookie-file.json> "<your prompt>"

Alternatives to -C <path-to-openai-cookie-file.json> :

On the current directory of your terminal,create a .env file and save path to the cookie-file in the format :

openai_cookie_file=<path-to-cookie-file>

Or simply make path to the cookie file an environment variable identified by openai_cookie_file. By that you'll just have to use less commands to get your work done e.g webchatgpt "Nmap command for scanning SMB vulnerabilty on 192.168.0.1" -q | grep '$' > scan_smb.sh

For more info; append --help to the command

$ webchatgpt --help

Usage: webchatgpt [OPTIONS] COMMAND [ARGS]...

  Reverse Engineered ChatGPT Web-version

Options:
  --help  Show this message and exit.

Commands:
  generate     Generate a quick response with ChatGPT
  interactive  Chat with ChatGPT interactively

$ webchatgpt generate --help

Usage: webchatgpt generate [OPTIONS]

  Generate a quick response with ChatGPT

Options:
  -C, --cookie-path PATH  Path to .json file containing cookies for
                          `chat.openai.com`
  -M, --model TEXT        ChatGPT's model to be used
  -I, --index INTEGER     Conversation index to resume from
  -P, --prompt TEXT       Start conversation with this messsage
  --help                  Show this message and exit.

$ webchatgpt interactive --help

Usage: webchatgpt interactive [OPTIONS]

  Chat with ChatGPT interactively

Options:
  -C, --cookie-path PATH          Path to .json file containing cookies for
                                  `chat.openai.com`
  -M, --model TEXT                ChatGPT's model to be used
  -I, --index INTEGER             Conversation index to resume from
  -P, --prompt TEXT               Start conversation with this messsage
  -B, --busy-bar-index INTEGER RANGE
                                  Busy bar index [0:/, 1:■█■■■]  [0<=x<=1]
  --help                          Show this message and exit.

Running h while in interactive prompt:

╒════╤════════════════════════╤═══════════════════════════════════════╕
│    │ Command                │ Action                                │
╞════╪════════════════════════╪═══════════════════════════════════════╡
│  0 │ h                      │ Show this help info                   │
├────┼────────────────────────┼───────────────────────────────────────┤
│  1 │ history                │ Show conversation history             │
├────┼────────────────────────┼───────────────────────────────────────┤
│  2 │ share                  │ Share conversation by link            │
├────┼────────────────────────┼───────────────────────────────────────┤
│  3 │ stop_share             │ Revoke shared conversation link       │
├────┼────────────────────────┼───────────────────────────────────────┤
│  4 │ rename                 │ Rename conversation title             │
├────┼────────────────────────┼───────────────────────────────────────┤
│  5 │ archive                │ Archive or unarchive a conversation   │
├────┼────────────────────────┼───────────────────────────────────────┤
│  6 │ shared_conversations   │ Show shared conversations             │
├────┼────────────────────────┼───────────────────────────────────────┤
│  7 │ previous_conversations │ Show previous conversations           │
├────┼────────────────────────┼───────────────────────────────────────┤
│  8 │ delete_conversation    │ Delete a particular conversation      │
├────┼────────────────────────┼───────────────────────────────────────┤
│  9 │ prompts                │ Generate random prompts               │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 10 │ account_info           │ ChatGPT account info/setings          │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 11 │ ask                    │ Show raw response from ChatGPT        │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 12 │ auth                   │ Show current user auth info           │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 13 │ migrate                │ Shift to another conversation         │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 14 │ set_theme              │ Set theme for displaying codes        │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 15 │ copy_this              │ Copy last response                    │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 16 │ with_copied            │ Attach last copied text to the prompt │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 17 │ clear                  │ Clear console                         │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 18 │ ./<command>            │ Run system command                    │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 19 │ <any other>            │ Interact with ChatGPT                 │
├────┼────────────────────────┼───────────────────────────────────────┤
│ 20 │ exit                   │ Quit Program                          │
╘════╧════════════════════════╧═══════════════════════════════════════╛

If $ webchatgpt doesn't look cool on you, there's this workaround python -m WebChatGPT

Starting from v0.2.4 onwards, shortcut to $ webchatgpt is $ wbc.

Developer Documentation

ToDo

  • Stream Response
  • Create new conversation
  • Implement Your idea
  • Fix my bad code.

Contributions

Anyone is free to fork, submit pull request as well as submitting issues.

Consider taking a look at the flow of events info for the case of a pull request.

Acknowledgements

  1. Http-Tracker.
  2. export-cookie-for-puppeteer

Special Thanks

  • You

If you don't want to follow all those steps; there this script that works out of the box. No API key needed at all, not even the cookies. Just installation and you're good to go. Check out tgpt2.

To those wishing to use the Official Openai API endpoints + GoogleBard at console environment; purpose to check out GPT-CLI

Disclaimer

This project is a reverse-engineered implementation of the ChatGPT web version and is intended for educational and research purposes only. It is not affiliated with or endorsed by OpenAI. The code in this repository is based on reverse engineering efforts and may not perfectly replicate the functionalities or behavior of the original ChatGPT web version. Usage of this code is at your own risk, and the maintainers of this repository are not responsible for any misuse or unintended use of the generated content. Please refer to OpenAI's policies and terms of service regarding the use of their services and models. By using this repository, you agree to comply with all relevant laws and OpenAI's terms of service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webchatgpt-0.3.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

webchatgpt-0.3.0-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file webchatgpt-0.3.0.tar.gz.

File metadata

  • Download URL: webchatgpt-0.3.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for webchatgpt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 71906b31917e9b1ffb0a0762a3ca7b9c8fbb3a8fe72cd57a941906f7f17ac6c6
MD5 81bb956a92b6c63a3911ee7b82678cbf
BLAKE2b-256 4d9079e2ca5d0325ba77bb1f2fb4a6283e78c979944d10bb2f95ca128f55fb7e

See more details on using hashes here.

File details

Details for the file webchatgpt-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: webchatgpt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for webchatgpt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c55584ee253c7d6a9efd4ca5331bde828a9ba95faa9539a84173ae4e32f36268
MD5 cf299e647def05062fcfd6f1d77126b6
BLAKE2b-256 c7fb16611f06e814fbdd9bd4ca7f3b72bbd8e3bfe423be68fd57ca0ddd47e56c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page