pyChatGPT
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_chromedriverto bypass Cloudflare's anti-bot protection.requestsmodule 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_idandconversation_idparameters) but you can still reset the conversation by callingreset_conversation().
Installation
pip install -U pyChatGPT
Usage
Obtaining session_token
- Go to https://chat.openai.com/chat and open the developer tools by
F12. - Find the
__Secure-next-auth.session-tokencookie inApplication>Storage>Cookies>https://chat.openai.com. - Copy the value in the
Cookie Valuefield.
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.
Metadata
Release files for pyChatGPT 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyChatGPT-0.3.0.tar.gz | 17.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyChatGPT-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.8 kB
Release files / pyChatGPT-0.3.0.tar.gz
| Download URL | pyChatGPT-0.3.0.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9635562443ce2722082ee0936bcac3bd22e978c6532f4c07e7547526c8d2a18
|
|
BLAKE2b-256 checksum How to use checksums |
b2c3ea9d3040fa3a01418c2584af5b022ec54985f2e5ddfefb19d57ff397c4b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Release files / pyChatGPT-0.3.0-py3-none-any.whl
| Download URL | pyChatGPT-0.3.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
704c6e8e5b84077da60713d09c9d9a531ffeb7cd239f9940bf0e79e76cb66022
|
|
BLAKE2b-256 checksum How to use checksums |
c73b4502ac7fc9d07934ab592a6243ad1a96c42f24eadc2b41fa35687d75cd7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|