Package: pyChatGPTLoop
pyChatGPTLoopAdded backtracking chat on the basis ofterry3041/pyChatGPTExtra FeaturesImplement asynchronous usecan go back to a conversational moment in the pastincrease the function of initializing personalityset local chromedriveroptimized the output, removing two newlinesadded reply failure handlingadded GPT-ToolBoxGPT-ToolBoxbacktracking chatinitializing personalityGetting StartedThis library is using only theundetected_chromedriverto bypass Cloudflare's anti-bot protection.Please make sure you haveGoogle Chrome/Chromiumbefore using this wrapper.Installationgitclonehttps://github.com/nek0us/pyChatGPTLoop.git
pipinstall.# orpipinstallpyChatGPTLoop--upgradeUsageObtaining session_tokenGo tohttps://chat.openai.com/chatand open the developer tools byF12.Find the__Secure-next-auth.session-tokencookie inApplication>Storage>Cookies>https://chat.openai.com.Copy the value in theCookie Valuefield.Interactive modepython3-mpyChatGPTLoopImport as a modulefrompyChatGPTLoop.pyChatGPTLoopimportChatGPTimportasynciosession_token='abc123'# `__Secure-next-auth.session-token` cookie from https://chat.openai.com/chatapi=ChatGPT(session_token)# auth with session tokenapi=ChatGPT(session_token,conversation_id='some-random-uuid')# specify conversation idapi=ChatGPT(session_token,proxy='https://proxy.example.com:8080')# specify proxyapi=ChatGPT(session_token,chrome_args=['--window-size=1920,768'])# specify chrome argsapi=ChatGPT(session_token,moderation=False)# disable moderationapi=ChatGPT(session_token,verbose=True)# verbose mode (print debug messages)api=ChatGPT(session_token,driver_path="C:\\yourdriverpath\\chromedriver.exe")# set local chromedriver if you don't wish it update in windowsapi=ChatGPT(session_token,driver_path="/yourpath/chromedriver")# set local chromedriver if you don't wish it update in linuxapi=ChatGPT(session_token,personality_definition=yourList)# the words list of init personalityapi=ChatGPT(session_token,toolbox=True)# use GPT-ToolBox# auth with google loginapi=ChatGPT(auth_type='google',email='example@gmail.com',password='password')# auth with microsoft loginapi=ChatGPT(auth_type='microsoft',email='example@gmail.com',password='password')# auth with openai login (captcha solving using speech-to-text engine)api=ChatGPT(auth_type='openai',email='example@gmail.com',password='password')# auth with openai login (manual captcha solving)api=ChatGPT(auth_type='openai',captcha_solver=None,email='example@gmail.com',password='password')# auth with openai login (2captcha for captcha solving)api=ChatGPT(auth_type='openai',captcha_solver='2captcha',solver_apikey='abc',email='example@gmail.com',password='password')# reuse cookies generated by successful login before login,# if `login_cookies_path` does not exist, it will process logining  with `auth_type`, and save cookies to `login_cookies_path`# only works when `auth_type` is `openai` or `google`api=ChatGPT(auth_type='openai',email='example@xxx.com',password='password',login_cookies_path='your_cookies_path',)api.reset_conversation()# reset the conversationapi.clear_conversations()# clear all conversations# send messageresp=asyncio(api.async_send_message('Hello, world!'))print(resp['message'])# if in an async functionresp=awaitapi.async_send_message('Hello, world!',msg_type="loop")print(resp['message'])# refresh the chat pageawaitapi.refresh_chat_page()# return the loop_text conversationloop_text="some words"resp=awaitapi.async_send_message(loop_text,msg_type="loop")#You can pass the conversation id to the rightresp=awaitapi.async_send_message('Hello, world!',conversation_id,msg_type="msg")personality_definition=[{"content":r'Now you are going to pretend to be a math teacher called "nothing" to help me with my math',"AI_verify":True}]awaitapi.init_personality(True,"",personality_definition)#orresp=awaitapi.async_send_message(personality_definition,conversation_id,msg_type="init")#update session_toekn when chrome runningresp=awaitapi.async_send_message(new_cookie,conversation_id,msg_type="update_cookie")#all of resp:resp:dict=={"status":bool,any}Frequently Asked QuestionsHow do i initializing personality?# An example of initializing the vocabulary format, the vocabulary content is not representativepersonality_definition=[{"content":r'Now you are going to pretend to be a math teacher called "nothing" to help me with my math',"AI_verify":True},{"content":r"You will be very strict in pointing out my mistakes","AI_verify":False}]new_conversation=True
awaitapi.backtrack_chat(new_conversation,"",personality_definition)# new_conversation : Whether to open a new session for personality initialization, the default is true# personality_definition: Personality initialization phrase is a list, a single element is a dict,# content is the content of the phrase, and AI_verify is a successful detection of personality# returns a boolean resultHow do i go back to the conversation i had?# You said some words to chatGPTloop_text='some words'# Go back to the dialogue where these words last appearedawaitapi.backtrack_chat(loop_text)#You can pass the conversation id to the right of loop_text#return an boolen result# if you use an async methodresp=awaitapi.async_send_message(loop_text,msg_type="loop")How do I get it to work on headless linux server?# install chromium & X virtual framebuffersudoaptinstallchromium-browserxvfb# start your scriptpython3your_script.pyHow 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!aptinstallchromium-browserxvfb!pipinstall-Uselenium_profilespyChatGPT# install chromedriverfromselenium_profiles.utils.installerimportinstall_chromedriverinstall_chromedriver()# start your script as normal!python3-mpyChatGPTLoopInsiprationThis project is inspired bypyChatGPTChatGPTchatgpt-apiDisclaimerThis 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 theOpenAI Terms of Servicebefore using this project.LicenseThis project is licensed under the GPLv3 License - see theLICENSEfile for details.