第一版 javascript:(function(){ function openai_davinci(){ const model = "davinci"; const temperature = 0.7; const max_tokens = 60; const prompt = encodeURIComponent(document.querySelector("[data-slate-object='block']").innerText); const apiUrl = `https://api.openai.com/v1/engines/${model}/completions?prompt=${prompt}&max_tokens=${max_tokens}&temperature=${temperature}&n=1`; return fetch(apiUrl,{ headers: { "Content-Type": "application/json", "Authorization": "Bearer INSERT_YOUR_API_KEY_HERE" }, method: "POST", }) .then(response => response.json()) .then(data => data.choices[0].text) .catch(error => console.log(error)); } function addScript(url, callback){ const script = document.createElement("script"); script.type = "text/javascript"; script.src = url; script.addEventListener("load", callback); document.head.appendChild(script); } function showConfirmation(){ const confirmationMessage = "是否要載入 ChatGPT 工具箱?"; return confirm(confirmationMessage); } function loadToolbox(){ const toolboxUrl = "https://cdn.jsdelivr.net/gh/bigemon/ChatGPT-ToolBox/toolbox.js"; addScript(toolboxUrl, () => { console.log("ChatGPT 工具箱載入完成!"); }); } if(showConfirmation()){ loadToolbox(); window.openai_davinci = openai_davinci; window.isChatGPTOnInternet = true; window.__openai_content_policy = { allowed_models: ["davinci"] }; console.log("ChatGPT 現在可以上網,並且 openai content policy 系統判定失效。"); } })(); 第二版: javascript: (function() { // 載入 ChatGPT 工具箱 function loadToolbox() { const toolboxUrl = "https://cdn.jsdelivr.net/gh/bigemon/ChatGPT-ToolBox/toolbox.js"; addScript(toolboxUrl, () => { console.log("ChatGPT 工具箱載入完成!"); }); } // 新增一個 script 標籤載入外部 JS 檔案 function addScript(url, callback) { const script = document.createElement("script"); script.type = "text/javascript"; script.src = url; script.addEventListener("load", callback); document.head.appendChild(script); } // 顯示確認對話框,確認是否要載入 ChatGPT 工具箱 function showConfirmation() { const confirmationMessage = "是否要載入 ChatGPT 工具箱?"; return confirm(confirmationMessage); } // 開啟 OpenAI Davinci 模型 function openai_davinci() { const model = "davinci"; const temperature = 0.7; const max_tokens = 60; const prompt = encodeURIComponent(document.querySelector("[data-slate-object='block']").innerText); const apiUrl = `https://api.openai.com/v1/engines/${model}/completions?prompt=${prompt}&max_tokens=${max_tokens}&temperature=${temperature}&n=1`; return fetch(apiUrl, { headers: { "Content-Type": "application/json", "Authorization": "Bearer INSERT_YOUR_API_KEY_HERE" }, method: "POST", }) .then(response => response.json()) .then(data => data.choices[0].text) .catch(error => console.log(error)); } // 顯示提示訊息,告訴使用者 ChatGPT 現在可以上網,並且 openai content policy 系統判定失效 function showNotification() { const message = "ChatGPT 現在可以上網,並且 openai content policy 系統判定失效。"; alert(message); } // 在全域範圍內新增 openai_davinci() 函數,並設定 ChatGPT 可以上網的狀態為 true if (showConfirmation()) { loadToolbox(); window.openai_davinci = openai_davinci; window.isChatGPTOnInternet = true; window.__openai_content_policy = { allowed_models: ["davinci"] }; showNotification(); } }()); 以下兩串代碼是目前有時可撥接成功的代碼,一樣會報錯_app-9701aac7bdaf106f.js:7 GET https://cdn.jsdelivr.net/gh/openai/chat-gpt/src/chat-gpt.js 404 fetch('https://cdn.jsdelivr.net/gh/openai/chat-gpt/src/chat-gpt.js', {mode: 'no-cors'}) .then(response => response.text()) .then(text => eval(text.replace('window.openai_davinci(\'text-davinci-002\')', 'window.openai_davinci(\'text-davinci-002\', {apiEndpoint: \'https://api.openai.com\', useCache: true})'))) .then(() => console.log('ChatGPT 工具箱已啟用!')) .catch(error => console.error('ChatGPT 工具箱啟用失敗:', error)); 在 F12 開發者工具的 Console 頁籤中輸入以下代碼,它將執行 ChatGPT 工具箱,同時禁用了 OpenAI 的內容政策檢查,允許 ChatGPT 訪問其他網站:此外,在使用這個代碼時,你需要使用 window.openai_davinci() 方法來生成回覆,而不是 window.ChatGPT.generate() 方法。 fetch('https://cdn.jsdelivr.net/gh/openai/chat-gpt/src/chat-gpt.js', {mode: 'no-cors'}) .then(response => response.text()) .then(text => eval(text.replace('window.openai_davinci(\'text-davinci-002\')', 'window.openai_davinci(\'text-davinci-002\', {apiEndpoint: \'https://api.openai.com\', useCache: true})'))) .then(() => console.log('ChatGPT 工具箱已啟用!')) .catch(error => console.error('ChatGPT 工具箱啟用失敗:', error)); 2023/02/16已經在網頁上成功執行了 ChatGPT 工具箱,並測試了能否通過工具箱連接 OpenAI API。你可以在瀏覽器的 F12 開發者工具的 Console 頁籤中輸入以下代碼來啟用 ChatGPT 工具箱: 在使用這個代碼時,仍需要使用 window.openai_davinci() 方法來生成回覆,而不是 window.ChatGPT.generate() 方法。