Вы подали заявку на API GPT-4, но OpenAI слишком занят, чтобы ответить ? Я тоже, поэтому я создал этот пакет. Он использует Selenium Webdriver для эмуляции взаимодействия с пользователем на чате.openai.com. Если у учетной записи есть ChatGPT Plus
, драйвер будет использовать GPT-4 , в противном случае она будет использовать GPT-3.5 по умолчанию.
Он поддерживает как браузер GPT4, Dall-E 3, так и плагины , выбирая модель через GPT4OpenAI(token=token, model='gpt-4')
или model='gpt-4-plugins'
.
Примечание: эта неофициальная библиотека API не одобрена OpenAI и нарушает их условия обслуживания. Используйте его на свой собственный риск; Создатель не несет ответственности за какие -либо последствия. Пожалуйста, придерживайтесь TOS платформы и проявляйте осторожность с неофициальными ресурсами.
Основная логика была взята из Intellenzaartificiale/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 )
Этот код был использован для демонстрационного 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
фактически расширяет класс LLM
от langchain.llms.base
. Таким образом, вы можете легко использовать эту библиотеку в экосистеме 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
.__Secure-next-auth.session-token
в Application
> Storage
> Cookies
> https://chat.openai.com
.Cookie Value
. Первоначально я попробовал POE.com (Private API, реализованный на GPT4Free), но заметил, что окно ввода контекста меньше, чем у Openai Catgpt. И то же самое относится и к GPT4 Bing.
Чтобы установить этот пакет Python, запустите следующую команду:
pip install gpt4-openai-api
Эти зависимости загружаются напрямую:
undetected-chromedriver
(браузер селена)markdownify
langchain