Skip to main content

An unofficial Python wrapper for OpenAI's ChatGPT API

Project description

pyChatGPT

PyPi License PyPi

An unofficial Python wrapper for OpenAI's ChatGPT API

Features

  • Bypass Cloudflare's anti-bot protection using undetected_chromedriver
  • Captcha solver when auth with login credentials (experimental)
  • Support headless machines
  • Proxy support (only without basic auth)

Getting Started

On version 0.3.0, this library is using only the undetected_chromedriver to bypass Cloudflare's anti-bot protection. requests module is no longer used due to the complexity of the protection. Please make sure you have Google Chrome before using this wrapper. From now on, this library will not support specifying a conversation (i.e. parent_id and conversation_id parameters) but you can still reset the conversation by calling reset_conversation().

Installation

pip install -U pyChatGPT

Usage

Obtaining session_token

  1. Go to https://chat.openai.com/chat and open the developer tools by F12.
  2. Find the __Secure-next-auth.session-token cookie in Application > Storage > Cookies > https://chat.openai.com.
  3. Copy the value in the Cookie Value field.

image

Interactive mode

python -m pyChatGPT

Import as a module

from pyChatGPT import ChatGPT

session_token = 'abc123'  # `__Secure-next-auth.session-token` cookie from https://chat.openai.com/chat
api = ChatGPT(session_token)  # auth with session token
api2 = ChatGPT(email='example@domain.com', password='password')  # auth with email and password (unreliable)
api3 = ChatGPT(session_token, conversation_id='some-random-uuid', parent_id='another-random-uuid')  # specify a conversation
api4 = ChatGPT(session_token, proxy='http://proxy.example.com:8080')  # specify proxy
api5 = ChatGPT(session_token, cf_refresh_interval=30)  # specify the interval to refresh the cf cookies (in minutes)

resp = api.send_message('Hello, world!')
print(resp['message'])

api.reset_conversation()  # reset the conversation

Frequently Asked Questions

How do I get it to work on headless linux server?

# install chromium & X virtual framebuffer
sudo apt install chromium xvfb

# start your script
python3 your_script.py

Insipration

This project is inspired by

Disclaimer

This project is not affiliated with OpenAI in any way. Use at your own risk. I am not responsible for any damage caused by this project. Please read the OpenAI Terms of Service before using this project.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details.

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

pyChatGPT-0.3.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

pyChatGPT-0.3.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyChatGPT-0.3.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pyChatGPT-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f9635562443ce2722082ee0936bcac3bd22e978c6532f4c07e7547526c8d2a18
MD5 4f1c9f3003174a0eb73e6a14d1d7bbf4
BLAKE2b-256 b2c3ea9d3040fa3a01418c2584af5b022ec54985f2e5ddfefb19d57ff397c4b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyChatGPT-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pyChatGPT-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 704c6e8e5b84077da60713d09c9d9a531ffeb7cd239f9940bf0e79e76cb66022
MD5 45bfd04e7608674249e71bf629a22551
BLAKE2b-256 c73b4502ac7fc9d07934ab592a6243ad1a96c42f24eadc2b41fa35687d75cd7a

See more details on using hashes here.

Supported by

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