Package: chatgptpy
🔥 PyChatGPT😶‍🌫️ [Confirmed] OpenAI shadow-bans requests throughbots/scrapers. This applies to all current scrapers/bots out there, but not with this script! 😎Read More - How OpenAI filters requests made by bots/scrapers⭐️ Like this repo? please star & consider donating to keep it maintained💡 If OpenAI change their API, I will fix it as soon as possible, so Watch the repo if you want to be notifiedFeaturesSave Conversations to a fileResume conversations even after closing the programProxy SupportAutomatically login without involving a browserAutomatically grab Access TokenGet around the logincaptcha(If you try to log in subsequently, you will be prompted to solve a captcha)Saves the access token to a file, so you don't have to log in againAutomatically refreshes the access token when it expiresUses colorama to colorize the output, because why not?Smart Conversation TrackingWeb DemoIntegrated intoHuggingface Spaces 🤗usingGradio. Try out the Web DemoChattingCreating a tokenYou: Hi there, My name is Rawa
Chat GPT: Hello Rawa, nice to meet you. Is there something you would like to talk about or ask me? I'm here to help with any questions you may have.
You: great, now say my name like Heisenberg
Chat GPT: Sure, Rawa like Heisenberg. Is there anything else you would like to talk about? I'm here to help with any questions you may have.
You: Sorry I meant like the episode of Breaking Bad where Walter White says Heisenberg
Chat GPT: Ah, I see. In that case, you could try saying it like this: "My name is Rawa, like Heisenberg." This is a reference to the character Walter White from the TV show Breaking Bad, who often used the pseudonym "Heisenberg" when conducting illegal activities. The character was known for his cool and calculated demeanor, so saying your name like Heisenberg in this context would mean saying it with confidence and authority.Installpip install chatgptpy --upgradeUsage[NEW] Pass aoptions()object to theChatGPT()constructor to customize the session[NEW] You can now save your conversations to a filefrompychatgptimportChat,Optionsoptions=Options()# [New] Pass Moderation. https://github.com/rawandahmad698/PyChatGPT/discussions/103# options.pass_moderation = False# [New] Enable, Disable logsoptions.log=True# Track conversationoptions.track=True# Use a proxyoptions.proxies='http://localhost:8080'# Optionally, you can pass a file path to save the conversation# They're created if they don't exist# options.chat_log = "chat_log.txt"# options.id_log = "id_log.txt"# Create a Chat objectchat=Chat(email="email",password="password",options=options)answer=chat.ask("How are you?")print(answer)[NEW] Resume a conversationfrompychatgptimportChat# Create a Chat objectchat=Chat(email="email",password="password",conversation_id="Parent Conversation ID",previous_convo_id="Previous Conversation ID")answer,parent_conversation_id,conversation_id=chat.ask("How are you?")print(answer)# Or change the conversation id lateranswer,_,_=chat.ask("How are you?",previous_convo_id="Parent Conversation ID",conversation_id="Previous Conversation ID")print(answer)Start a CLI SessionfrompychatgptimportChatchat=Chat(email="email",password="password")chat.cli_chat()Ask a one time questionfrompychatgptimportChat# Initializing the chat class will automatically log you in, check access_tokenschat=Chat(email="email",password="password")answer,parent_conversation_id,conversation_id=chat.ask("Hello!")You could also manually set, get the tokenimporttimefrompychatgptimportOpenAI# Manually set the tokenOpenAI.Auth(email_address="email",password="password").save_access_token(access_token="",expiry=time.time()+3600)# Get the token, expiryaccess_token,expiry=OpenAI.get_access_token()# Check if the token is validis_expired=OpenAI.token_expired()# Returns True or FalseChange LogUpdate usingpip install chatgptpy --upgrade1.0.8Fixes an issue when reading from id_log.txtIntroduces a newpass_moderationparameter to theoptions()class, defaults toFalseAdds proxies to moderation.Ifpass_moderationis True, the function is invoked in another thread, so it doesn't block the main thread.1.0.7Make a request to the mod endpoint first, otherwise a crippled version of the response is returned1.0.6New option to turn off logs.Better Error handling.Enhanced conversation trackingAsk now returns a tuple ofanswer, previous_convo, convo_idBetter docs1.0.5Pull requests/minor fixes1.0.4Fixes for part 8 of token authentication1.0.3a newoptions()class method to set the options for the chat sessionsave the conversation to a fileresume the conversation even after closing the program1.0.2ChatGPT API switches fromaction=nexttoaction=variant, frequently. This library is now usingaction=variantinstead ofaction=nextto get the next response from the API.Sometimes when the server is overloaded, the API returns a502 Bad Gatewayerror.Added Error handling if the auth.json file is not found/corrupt1.0.0Initial Release via PyPiOther notesIf the token creation process is failing:Try to use a proxy (I recommend using this always)Don't try to log in too fast. At least wait 10 minutes if you're being rate limited.If you're still having issues, try to use a VPN. On a VPN, the script should work fine.What's next?I'm planning to add a few more features, such as:A python module that can be imported and used in other projectsA way to save the conversationBetter error handlingMulti-user chattingThe whole processI have been looking for a way to interact with the new Chat GPT API, but most of the sources here on GitHub
require you to have a Chromium instance running in the background. or by using the Web Inspector to grab Access Token manually.No more. I have been able to reverse engineer the API and use a TLS client to mimic a real user, allowing the script to login without setting off any bot detection techniques by Auth0Basically, the script logs in on your behalf, using a TLS client, then grabs the Access Token. It's pretty fast.First, I'd like to tell you that "just making http" requests is not going to be enough, Auth0 is smart, each process is guarded by astatetoken, which is a JWT token. This token is used to prevent CSRF attacks, and it's also used to prevent bots from logging in.
If you look at theauth.pyfile, there are over nine functions, each one of them is responsible for a different task, and they all
work together to create a token for you.allow-redirectsplayed a huge role in this, as it allowed to navigate through the login processI work at MeshMonitors.io, We make amazing tools (Check it out yo!). I decided not to spend too much time on this, but here we are.Why did I do this?No one has been able to do this, and I wanted to see if I could.CreditsOpenAIfor creating the ChatGPT APIFlorianREGAZfor the TLS Client