هل تقدمت بطلب للوصول إلى GPT-4 API ولكن Openai مشغول جدًا بالرد ؟ أنا أيضًا ، لهذا السبب قمت بإنشاء هذه الحزمة. يستخدم Selenium WebDriver لمحاكاة تفاعل المستخدم على chat.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 للمنصة وتوخي الحذر بموارد غير رسمية.
تم أخذ المنطق الأساسي من 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 )
تم استخدام هذا الرمز للتجريبي 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 (API الخاص الذي تم تنفيذه في GPT4Free) ، لكن لاحظت أن نافذة سياق الإدخال أصغر من Openai ChatGpt. والنفس ينطبق على Bing's GPT4.
لتثبيت حزمة Python هذه ، قم بتشغيل الأمر التالي:
pip install gpt4-openai-api
يتم تنزيل هذه التبعيات مباشرة:
undetected-chromedriver
(متصفح السيلينيوم)markdownify
langchain