Package: gpt4-openai-api
GPT4 OpenAI unofficial APIUnofficial GPT-4 API access via chat.openai.com using SeleniumHave youapplied to GPT-4 API accessbutOpenAI is too busy to reply? Me too, that's why I created this package. It usesselenium webdriverto emulate user interaction onchat.openai.com. If the account hasChatGPT Plus, the driverwill use GPT-4, otherwise it will use the default GPT-3.5.It supports bothGPT4 browser, DALL-E 3, and pluginsby selecting model viaGPT4OpenAI(token=token, model='gpt-4'), ormodel='gpt-4-plugins'.Note:This unofficial API library is not endorsed by OpenAI and violates their Terms of Service. Use it at your own risk; the creator assumes no liability for any consequences. Please adhere to platform's ToS and exercise caution with unofficial resources.The core logic was taken from theIntelligenzaArtificiale/Free-Auto-GPT.DemoDemo scriptfromgpt4_openaiimportGPT4OpenAI# Token is the __Secure-next-auth.session-token from chat.openai.comllm=GPT4OpenAI(token=my_session_token,headless=False,model='gpt-4')# GPT3.5 will answer 8, while GPT4 should be smart enough to answer 10response=llm('If there are 10 books in a room and I read 2, how many books are still in the room?')print(response)DALL-E 3 supportThis code was used for the demo gif above.fromgpt4_openaiimportGPT4OpenAIllm=GPT4OpenAI(token=my_session_token,headless=False,model='gpt-4'# DALL-E 3 only works with gpt-4)img_bytes=llm.generate_image('Generate an isometric image of a cute doggo inside a house.',image_path='./img_save_path.png')Browsing supportfromgpt4_openaiimportGPT4OpenAI# Token is the __Secure-next-auth.session-token from chat.openai.comllm=GPT4OpenAI(token=my_session_token,headless=False,model='gpt-4-browsing')# ChatGPT will first browse the web for the name/age of her boyfriend, then return the answerresponse=llm('What is the age difference between Dua Lipa and her boyfriend?')print(response)Langchain supportGPT4OpenAIactually extendsLLMclass fromlangchain.llms.base. So you can easily use this library inside langchain ecosystem. Example:fromgpt4_openaiimportGPT4OpenAIfromlangchainimportLLMChainfromlangchain.prompts.chatimport(ChatPromptTemplate,SystemMessagePromptTemplate,AIMessagePromptTemplate,HumanMessagePromptTemplate)template="You are a helpful assistant that translates english to pirate."system_message_prompt=SystemMessagePromptTemplate.from_template(template)example_human=HumanMessagePromptTemplate.from_template("Hi")example_ai=AIMessagePromptTemplate.from_template("Argh me mateys")human_message_prompt=HumanMessagePromptTemplate.from_template("{text}")chat_prompt=ChatPromptTemplate.from_messages([system_message_prompt,example_human,example_ai,human_message_prompt])# Token is the __Secure-next-auth.session-token from chat.openai.comllm=GPT4OpenAI(token=my_session_token)chain=LLMChain(llm=llm,prompt=chat_prompt)print(chain.run("My name is John and I like to eat pizza."))Output will be:AI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!How to get the session tokenGo tohttps://chat.openai.comand 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.OpenAI's GPT4 vs other providersInitially, I triedpoe.com(private API implemented atgpt4free), but noticed that input context window is smaller than one of OpenAI ChatGPT. And the same goes for Bing's GPT4.InstallationTo install this Python package, run the following command:pipinstallgpt4-openai-apiDependenciesThese dependencies get downloaded directly:undetected-chromedriver(selenium browser)markdownifylangchain