An unofficial Python wrapper for OpenAI's ChatGPT API
Project description
pyChatGPT
An unofficial Python wrapper for OpenAI's ChatGPT API
Getting Started
On 2022/12/11, OpenAI has implemented Cloudflare's anti-bot protection on the ChatGPT API. This wrapper is now using
undetected_chromedriver
to bypass the protection. Please make sure you have Google Chrome before using this wrapper.
Installation
pip install 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-token
cookie inApplication
>Storage
>Cookies
>https://chat.openai.com
. - Copy the value in the
Cookie Value
field.
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
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyChatGPT-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbe64c6982c30f31889a76639acb448511d70b1cc8976c5467f3492732b2e961 |
|
MD5 | c745adadd6b63139a7f0f8f3722a6a39 |
|
BLAKE2b-256 | 0cc54de93ae3a511aa9d5b90847cba42264533f8191caa964497e8ad4a1aef33 |