使用selenium webdriver
和undetectable chromedriver
進行 OpenAI GPT API 複製。
注意:使用 Chrome。
與官方 ChatGPT 網站互動並將回應傳送回呼叫者,完全免費(與官方 API 相對)。
不使用任何端點( forefront
、 theb
等)
該程序僅用於教育目的。使用者對使用本程式採取的任何行動承擔全部責任。對於任何濫用本程序或因使用本程序可能導致的任何損害,本程序的創建者不承擔任何責任或義務。
本節介紹SlymeGPT
的設定流程。
(請務必先使用https://github.com/mache102/SlymeGPT.git
複製儲存庫並下載軟體套件pip install -r requirements.txt
)
開啟Chrome -> Settings -> About Chrome
尋找您的 Chrome 版本(如果可用,請更新至最新版本)。
然後前往https://chromedriver.chromium.org/downloads下載對應的版本。
將 Chrome WebDriver 新增至系統的 PATH 變數。
1. Move the downloaded Chrome WebDriver executable to a folder of your choice.
2. Open your computer's "System Properties" settings.
3. Click on the "Advanced" tab and then click on the "Environment Variables" button.
4. Under "System Variables", find the "Path" variable and click "Edit".
5. Click "New" and add the folder path where the Chrome WebDriver executable is located.
6. Click "OK" on all open windows to save the changes.
將目錄更改為SlymeGPT
。在open_browser.py
中,將profile_name
變更為您選擇的 Chrome 設定文件,或保持原樣以使用預設設定檔。
這些設定檔可以在 Chrome 目錄中找到。
C:/Users/[username]/AppData/Local/Google/Chrome/User Data/
~/.config/google-chrome/
~/Library/Application Support/Google/Chrome/
選擇設定檔後,執行python open_browser.py
開啟 Selenium 控制的瀏覽器。
您應該看到以下畫面:
從那裡登入 ChatGPT(確保啟用「保持登入狀態」)並點擊任何首次登入通知。
完成後,關閉視窗並在 CLI 中按 ENTER 鍵(或直接終止open_browser.py
)。
設定完成。
現在,您可以透過匯入from slyme import SlymeDriver
在程式中使用該模組。有關演示,請參閱example.py
,這是一個簡單的程序,它獲取用戶的輸入,將其轉發到 ChatGPT,然後將回應發送回用戶。
請使用可見的 UI(而非無頭)運行該模組。瀏覽器視窗將在幾秒鐘後自動最小化。
嘗試在無頭模式下執行模組或手動最小化瀏覽器視窗可能會導致問題(可能是 Selenium/UC 問題)。
建議打開網頁後稍等片刻,具體取決於互聯網/加載速度。
from slyme import SlymeDriver
import time
def main ():
slyme = SlymeDriver ( pfname = 'Default' )
time . sleep ( 5 )
# driver.implicitly_wait() doesn't account for element loading
# - attempting to instantly access elements may result in a StaleElement error
# perform actions
slyme . select_latest_chat ()
#...
下面是一個程式碼片段,展示並解釋了該模組附帶的每個功能:
from slyme import SlymeDriver
import time
def main ():
slyme = SlymeDriver ( pfname = 'Default' )
time . sleep ( 5 )
# 1.
# Selects the latest accessed chat from the user's chat history.
slyme . select_latest_chat ()
# 2.
# Sends a prompt to ChatGPT and returns its response.
output = slyme . completion ( prompt = 'What does shutil.rmdir("C:/") do?' )
print ( output )
# 3.
# Renames a past chat.
slyme . rename_chat ( chat_name = 'Arch Linux' , new_name = 'I use Arch btw' )
# 4.
# Selects the chat with a matching name.
slyme . select_chat ( chat_name = 'I use Arch btw' )
# 5.
# Create a new chat.
slyme . new_chat ()
# 6.
# End the driver session.
slyme . end_session ()
if __name__ == "__main__" :
main ()