¿Ha solicitado el acceso a la API GPT-4 pero OpenAI está demasiado ocupado para responder ? Yo también, por eso creé este paquete. Utiliza Selenium WebDriver para emular la interacción del usuario en chat.openai.com. Si la cuenta tiene ChatGPT Plus
, el controlador usará GPT-4 , de lo contrario usará el GPT-3.5 predeterminado.
Admite tanto el navegador GPT4, Dall-E 3 como los complementos seleccionando el modelo a través de GPT4OpenAI(token=token, model='gpt-4')
o model='gpt-4-plugins'
.
Nota: Esta biblioteca de API no oficial no está respaldada por OpenAI y viola sus términos de servicio. Úselo bajo su propio riesgo; El creador no asume ninguna responsabilidad por ninguna consecuencia. Adhiérase a TOS de Plataforma y tenga precaución con recursos no oficiales.
La lógica central fue tomada del 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 se usó para el Demo GIF anterior.
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
en realidad extiende la clase LLM
desde langchain.llms.base
. Por lo tanto, puede usar fácilmente esta biblioteca dentro del ecosistema Langchain. Ejemplo:
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." ))
La salida será:
AI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!
F12
.__Secure-next-auth.session-token
en Application
> Storage
> Cookies
> https://chat.openai.com
.Cookie Value
. Inicialmente, probé Poe.com (API privada implementada en GPT4Free), pero noté que la ventana de contexto de entrada es más pequeña que una de OpenAI CHATGPT. Y lo mismo ocurre con Bing's GPT4.
Para instalar este paquete Python, ejecute el siguiente comando:
pip install gpt4-openai-api
Estas dependencias se descargan directamente:
undetected-chromedriver
(navegador de selenio)markdownify
langchain