gpt4 openai api
1.0.0
您是否已申请GPT-4 API访问,但OpenAI太忙而无法回复?我也是,这就是我创建此软件包的原因。它使用Selenium WebDriver在chat.openai.com上模仿用户互动。如果帐户具有ChatGPT Plus ,则驱动程序将使用GPT-4 ,否则将使用默认的GPT-3.5。
它通过通过GPT4OpenAI(token=token, model='gpt-4')或model='gpt-4-plugins'选择模型来支持GPT4浏览器,DALL-E 3和插件。
注意:这个非正式的API库不受OpenAI的认可,违反了他们的服务条款。以您自己的风险使用它;创作者对任何后果都不承担任何责任。请遵守平台的TOS,并以非正式资源的方式谨慎行事。
核心逻辑取自IntelligenzaaTificiale/自由式gpt。

from gpt4_openai import GPT4OpenAI
# Token is the __Secure-next-auth.session-token from chat.openai.com
llm = GPT4OpenAI ( token = my_session_token , headless = False , model = 'gpt-4' )
# GPT3.5 will answer 8, while GPT4 should be smart enough to answer 10
response = llm ( 'If there are 10 books in a room and I read 2, how many books are still in the room?' )
print ( response )此代码用于上面的演示GIF。
from gpt4_openai import GPT4OpenAI
llm = 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' ) from gpt4_openai import GPT4OpenAI
# Token is the __Secure-next-auth.session-token from chat.openai.com
llm = 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 answer
response = llm ( 'What is the age difference between Dua Lipa and her boyfriend?' )
print ( response )GPT4OpenAI实际上从langchain.llms.base扩展了LLM类。因此,您可以轻松地在Langchain生态系统中使用此库。例子:
from gpt4_openai import GPT4OpenAI
from langchain import LLMChain
from langchain . prompts . chat import ( 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.com
llm = 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." ))输出将是:
AI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!
F12打开开发人员工具。Application > Storage > Cookies > https://chat.openai.com中找到__Secure-next-auth.session-token cookie。Cookie Value字段中复制值。 
最初,我尝试了POE.com(在GPT4Free上实施的私有API),但注意到输入上下文窗口小于Openai Chatgpt之一。 Bing的GPT4也是如此。
要安装此Python软件包,请运行以下命令:
pip install gpt4-openai-api这些依赖项直接下载:
undetected-chromedriver (硒浏览器)markdownifylangchain