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
(硒瀏覽器)markdownify
langchain