Package: re-gpt
Reverse EngineeredChatGPTAPIUse OpenAI ChatGPT in your Python code without an API keyReport Bug|Request FeatureTable of ContentsAbout The ProjectInspirationHow it worksBuilt usingGetting StartedPrerequisitesInstallationObtaining Session TokenUsageExample UsageRoadmapContributingLicenseContactAcknowledgmentsAbout The ProjectThis project can be used to integrate OpenAI's ChatGPT services into your python code. You can use this project to prompt ChatGPT for responses directly from python, without using an official API key.This can be useful if you want to use ChatGPT API without aChatGPT Plusaccount.InspirationChatGPT has an official API which can be used to interface your Python code to it, but it needs to be used with an API key. This API key can only be obtained if you have aChatGPT Plusaccount, which requires $20/month (as of 05/11/2023). But you can use ChatGPT for free, using theChatGPT web interface. This project aims to interface your code to ChatGPT web version so you can use ChatGPT in your Python code without using an API key.How it worksChatGPTweb interface's requests have been reverse engineered, and directly integrated into Python requests. Hence, any requests made using this script is a simulated as a request made by a user directly on the website. Hence, it is free and needs no API key.Built UsingGetting StartedPrerequisitesPython >= 3.9Installationpipinstallre-gptUsageBasic examplefromre_gptimportSyncChatGPTsession_token="__Secure-next-auth.session-token here"conversation_id=None# conversation ID herewithSyncChatGPT(session_token=session_token)aschatgpt:prompt=input("Enter your prompt: ")ifconversation_id:conversation=chatgpt.get_conversation(conversation_id)else:conversation=chatgpt.create_new_conversation()formessageinconversation.chat(prompt):print(message["content"],flush=True,end="")Basic async exampleimportasyncioimportsysfromre_gptimportAsyncChatGPTsession_token="__Secure-next-auth.session-token here"conversation_id=conversation_id=None# conversation ID hereifsys.version_info>=(3,8)andsys.platform.lower().startswith("win"):asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())asyncdefmain():asyncwithAsyncChatGPT(session_token=session_token)aschatgpt:prompt=input("Enter your prompt: ")ifconversation_id:conversation=chatgpt.get_conversation(conversation_id)else:conversation=chatgpt.create_new_conversation()asyncformessageinconversation.chat(prompt):print(message["content"],flush=True,end="")if__name__=="__main__":asyncio.run(main())More ExamplesFor a more complex example, check out theexamplesfolder in the repository.Obtaining The Session TokenGo tohttps://chat.openai.com/chatand log in or sign up.Open the developer tools in your browser.Go to theApplicationtab and open theCookiessection.Copy the value for__Secure-next-auth.session-tokenand save it.TODOAdd more examplesAdd better error handlingImplement a function to retrieve all ChatGPT chatsImprove documentationContributingContributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make aregreatly appreciated.If you have a suggestion that would make this better, please fork the repo and create a pull request.
Don't forget to give the project a star! Thanks again!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestLicenseDistributed under the Apache License 2.0. SeeLICENSEfor more information.Contact/Bug reportZai-Kun -Discord ServerRepo Link:https://github.com/Zai-Kun/reverse-engineered-chatgptAcknowledgmentssudoAlphaXyifeikong (curl-cffi module)acheong08 (implementation to obtain arkose_token)pyca (cryptography module)Legrandin (pycryptodome module)othneildrew (README Template)