An unofficial Python wrapper for OpenAI's ChatGPT API
Project description
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)
- Google login support (experimental)
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
andconversation_id
parameters) 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-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
api1 = ChatGPT(session_token) # auth with session token
api2 = ChatGPT(session_token, proxy='http://proxy.example.com:8080') # specify proxy
api3 = ChatGPT(auth_type='google', email='example@gmail.com', password='password') # auth with google login
api4 = ChatGPT(session_token, verbose=True) # verbose mode (print debug messages)
resp = api1.send_message('Hello, world!')
print(resp['message'])
api1.reset_conversation() # reset the conversation
api1.close() # close the session
Frequently Asked Questions
How do I get it to work on headless linux server?
# install chromium & X virtual framebuffer
sudo apt install chromium-browser xvfb
# start your script
python3 your_script.py
How do I get it to work on Google Colab?
It is normal for the seession to be crashed when installing dependencies. Just ignore the error and run your script.
# install dependencies
!apt install chromium-browser xvfb
!pip install -U selenium_profiles pyChatGPT
# install chromedriver
from selenium_profiles.utils.installer import install_chromedriver
install_chromedriver()
# start your script as normal
!python3 -m pyChatGPT
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.3.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecf315b0907004909804317d49e5c55fe2cabe6cde7ca1cd4a9ae41c94f11677 |
|
MD5 | 43d0b06b7d1205cc38221f6a48f03b86 |
|
BLAKE2b-256 | 08bb9dc9167024d07d41fd4cc722a9b96e3a63468ecf06447b443ed89cc0796b |