Você se inscreveu no acesso da API GPT-4, mas o OpenAI está muito ocupado para responder ? Eu também, é por isso que criei este pacote. Ele usa o Selenium WebDriver para imitar a interação do usuário no chat.openai.com. Se a conta tiver ChatGPT Plus
, o driver usará o GPT-4 , caso contrário, ele usará o GPT-3.5 padrão.
Ele suporta o navegador GPT4, o Dall-E 3 e os plugins selecionando o modelo via GPT4OpenAI(token=token, model='gpt-4')
ou model='gpt-4-plugins'
.
Nota: Esta biblioteca de API não oficial não é endossada pelo OpenAI e viola seus Termos de Serviço. Use -o por sua conta e risco; O Criador não se responsabiliza por nenhuma conseqüência. Avance os TOs da plataforma e tenha cuidado com recursos não oficiais.
A lógica central foi retirada da Intelligenzaartificiale/Free-Auto-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 )
Este código foi usado para o gif de demonstração acima.
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
na verdade estende a classe LLM
de langchain.llms.base
. Portanto, você pode usar facilmente esta biblioteca dentro do ecossistema Langchain. Exemplo:
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." ))
A saída será:
AI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!
F12
.__Secure-next-auth.session-token
em Application
> Storage
> Cookies
> https://chat.openai.com
.Cookie Value
. Inicialmente, experimentei o Poe.com (API privada implementada no GPT4Free), mas notei que a janela de contexto de entrada é menor que uma do OpenAi chatgpt. E o mesmo vale para o GPT4 do Bing.
Para instalar este pacote Python, execute o seguinte comando:
pip install gpt4-openai-api
Essas dependências são baixadas diretamente:
undetected-chromedriver
(navegador de selênio)markdownify
langchain