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、およびプラグインの両方をサポート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
、実際に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
で開発者ツールを開きます。__Secure-next-auth.session-token
cookieをApplication
> Storage
> Cookies
> https://chat.openai.com
見つけます。Cookie Value
フィールドの値をコピーします。 最初は、POE.com(GPT4Freeで実装されたプライベートAPI)を試しましたが、入力コンテキストウィンドウがOpenai ChatGPTの1つよりも小さいことに気付きました。また、BingのGPT4にも同じことが言えます。
このPythonパッケージをインストールするには、次のコマンドを実行します。
pip install gpt4-openai-api
これらの依存関係は直接ダウンロードされます:
undetected-chromedriver
(セレンブラウザ)markdownify
langchain