
已經添加了對官方CHATGPT模型的支持!現在,您可以使用ChatGPTClient使用官方的OpenAI API使用gpt-3.5-turbo模型。這是Chatgpt使用的模型,它是目前可用的最強大的模型。該模型的使用不是免費的,但是比text-davinci-003便宜10倍(價格為每1k代幣0.002美元)。
有關更多信息,請參見Openai的帖子,介紹Chatgpt和Whisper Apis。
要使用它,請將 modelOptions.model設置為gpt-3.5-turbo ,而ChatGPTClient將處理其餘的。ChatGPTClient中使用的默認模型現在為gpt-3.5-turbo 。您仍然可以像往常一樣設置userLabel , chatGptLabel和promptPrefix (系統說明)。
如果您繼續自動chat.openai.com,則可能會有更高的可能性被禁止使用。繼續這樣做的風險。
我添加了一個實驗性ChatGPTBrowserClient ,該chatgptbrowserclient取決於使用CloudFlare旁路的反向代理服務器,使您可以與Chatgpt(Chat.openai.com)交談而無需瀏覽器自動化。您所需要的只是您的訪問令牌從https://chat.openai.com/api/auth/session。
與往常一樣,請注意,如果您選擇走這條路線,則將訪問令牌公開為封閉的第三方服務器。如果您擔心這一點,則可以選擇使用免費的ChatGpt帳戶來最大程度地降低風險,或者繼續使用ChatGPTClient代替text-davinci-003型號。
不幸的是,我們使用的方法用於訪問Chatgpt基礎模型。您現在的選項是將官方的OpenAI API與text-davinci-003型號(費用為錢),或者使用基於瀏覽器的解決方案與ChatGpt的後端進行交互(該解決方案較不強大,更限制,並且此時不受此庫的支持)。
在@pawanosman的幫助下,我們已經找到了一種繼續使用Chatgpt基礎模型的方法。為了防止再次失去訪問權限,我們決定提供與OpenAI API兼容的反向代理服務器。我已經更新了ChatGPTClient ,以使用反向代理服務器而不是OpenAI API服務器進行支持。有關可用代理服務器及其工作方式的更多信息,請參見使用反向代理。
請注意,如果您選擇走這條路線,則將訪問令牌公開為封閉的第三方服務器。如果您擔心這一點,則可以選擇使用免費的ChatGpt帳戶來最大程度地降低風險,或者繼續使用官方的OpenAI API而不是text-davinci-003型號。
我找到了一種新的用於text-chat-davinci-002 , text-chat-davinci-002-sh-alpha-aoruigiofdj83的工作模型。這是Chatgpt Plus“ Turbo”版本使用的基礎模型。響應迅速。我已經更新了庫以使用此模型。
不良時機;不久之後刪除了text-chat-davinci-002-sh-alpha-aoruigiofdj83 ,這可能是由於某個地方的新型號造成的嗎?
通過BingAIClient (實驗)體驗Bing的GPT-4版本Chatgpt的力量。 API服務器和CLI仍需要更新以支持此功能,但是您可以立即直接使用客戶端。請注意,如果您的帳戶仍在等待上市,則您將無法使用此客戶端。
即使text-chat-davinci-002-20221122再次備份,似乎它不斷被超載並返回429個錯誤。 Openai可能僅將少量資源用於該模型,以防止公眾廣泛使用它。此外,我聽說現在較新的版本已訪問OpenAI員工和合作夥伴,因此,在型號正式發布之前,我們不太可能能找到任何解決方法。
您可以將text-davinci-003型號代替作為置換式替換。請記住, text-davinci-003不如text-chat-davinci-002 (通過RHLF訓練並進行微調為對話ai),儘管結果在大多數情況下仍然相當不錯。請注意,使用text-davinci-003將花費您的信用($)。
我將重新添加對API服務器和CLI的基於瀏覽器的CHATGPT的支持。請出演並觀看此存儲庫以獲取更新。
過山車已經到達下一站。 text-chat-davinci-002-20221122再次備份。
嘗試使用OpenAI API使用text-chat-davinci-002-20221122現在返回404錯誤。您可以將text-davinci-003型號代替作為置換式替換。請記住, text-davinci-003不如text-chat-davinci-002 (通過RHLF訓練並微調為對話ai),儘管結果仍然非常好。請注意,使用text-davinci-003將花費您的信用($)。
當我們研究進一步的解決方法時,請保留進一步的更新。
嘗試使用OpenAI API使用text-chat-davinci-002-20230126現在返回404錯誤。有人已經找到了新的型號名稱,但是他們目前不願意分享。找到新模型後,我將更新此存儲庫。如果您有任何線索,請打開問題或拉動請求。
同時,我增加了對諸如text-davinci-003之類的模型的支持,您可以將其用作置換式替換。請記住, text-davinci-003不如text-chat-davinci-002 (通過RHLF訓練並微調為對話ai),儘管結果仍然非常好。請注意,使用text-davinci-003將花費您的信用($)。
Discord用戶 @Pig#8932找到了一種工作的text-chat-davinci-002型號, text-chat-davinci-002-20221122 。我已經更新了庫以使用此模型。
CHATGPT和BING AI的客戶實現。可作為Node.js模塊,REST API服務器和CLI應用程序可用。
ChatGPTClient :通過OpenAI的API支持官方Chatgpt基礎模型gpt-3.5-turbo 。keyv-file適配器,如果您使用的是API服務器或CLI(請參閱settings.example.js ),可用於將對話存儲在JSON文件中。text-davinci-003之類的模型的支持BingAIClient :支持Bing版本的Chatgpt,由GPT-4提供支持。ChatGPTBrowserClient :支持官方ChatGpt網站,使用反向代理服務器進行CloudFlare旁路。npm i @waylaidwanderer/chatgpt-api請參閱demos/use-bing-client.js 。
請參閱demos/use-client.js 。
請參閱demos/use-browser-client.js 。
您可以使用
npm i -g @waylaidwanderer/chatgpt-api然後使用chatgpt-api運行它。這需要一個可選的--settings=<path_to_settings.js>參數,或在當前目錄中查找settings.js 。
module . exports = {
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv.
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default).
// Only necessary when using `ChatGPTClient`, or `BingAIClient` in jailbreak mode.
cacheOptions : { } ,
// If set, `ChatGPTClient` and `BingAIClient` will use `keyv-file` to store conversations to this JSON file instead of in memory.
// However, `cacheOptions.store` will override this if set
storageFilePath : process . env . STORAGE_FILE_PATH || './cache.json' ,
chatGptClient : {
// Your OpenAI API key (for `ChatGPTClient`)
openaiApiKey : process . env . OPENAI_API_KEY || '' ,
// (Optional) Support for a reverse proxy for the completions endpoint (private API server).
// Warning: This will expose your `openaiApiKey` to a third party. Consider the risks before using this.
// reverseProxyUrl: 'https://chatgpt.hato.ai/completions',
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions : {
// You can override the model name and any other parameters here.
// The default model is `gpt-3.5-turbo`.
model : 'gpt-3.5-turbo' ,
// Set max_tokens here to override the default max_tokens of 1000 for the completion.
// max_tokens: 1000,
} ,
// (Optional) Davinci models have a max context length of 4097 tokens, but you may need to change this for other models.
// maxContextTokens: 4097,
// (Optional) You might want to lower this to save money if using a paid model like `text-davinci-003`.
// Earlier messages will be dropped until the prompt is within the limit.
// maxPromptTokens: 3097,
// (Optional) Set custom instructions instead of "You are ChatGPT...".
// (Optional) Set a custom name for the user
// userLabel: 'User',
// (Optional) Set a custom name for ChatGPT ("ChatGPT" by default)
// chatGptLabel: 'Bob',
// promptPrefix: 'You are Bob, a cowboy in Western times...',
// A proxy string like "http://<ip>:<port>"
proxy : '' ,
// (Optional) Set to true to enable `console.debug()` logging
debug : false ,
} ,
// Options for the Bing client
bingAiClient : {
// Necessary for some people in different countries, e.g. China (https://cn.bing.com)
host : '' ,
// The "_U" cookie value from bing.com
userToken : '' ,
// If the above doesn't work, provide all your cookies as a string instead
cookies : '' ,
// A proxy string like "http://<ip>:<port>"
proxy : '' ,
// (Optional) Set to true to enable `console.debug()` logging
debug : false ,
} ,
chatGptBrowserClient : {
// (Optional) Support for a reverse proxy for the conversation endpoint (private API server).
// Warning: This will expose your access token to a third party. Consider the risks before using this.
reverseProxyUrl : 'https://bypass.churchless.tech/api/conversation' ,
// Access token from https://chat.openai.com/api/auth/session
accessToken : '' ,
// Cookies from chat.openai.com (likely not required if using reverse proxy server).
cookies : '' ,
// A proxy string like "http://<ip>:<port>"
proxy : '' ,
// (Optional) Set to true to enable `console.debug()` logging
debug : false ,
} ,
// Options for the API server
apiOptions : {
port : process . env . API_PORT || 3000 ,
host : process . env . API_HOST || 'localhost' ,
// (Optional) Set to true to enable `console.debug()` logging
debug : false ,
// (Optional) Possible options: "chatgpt", "chatgpt-browser", "bing". (Default: "chatgpt")
clientToUse : 'chatgpt' ,
// (Optional) Generate titles for each conversation for clients that support it (only ChatGPTClient for now).
// This will be returned as a `title` property in the first response of the conversation.
generateTitles : false ,
// (Optional) Set this to allow changing the client or client options in POST /conversation.
// To disable, set to `null`.
perMessageClientOptionsWhitelist : {
// The ability to switch clients using `clientOptions.clientToUse` will be disabled if `validClientsToUse` is not set.
// To allow switching clients per message, you must set `validClientsToUse` to a non-empty array.
validClientsToUse : [ 'bing' , 'chatgpt' , 'chatgpt-browser' ] , // values from possible `clientToUse` options above
// The Object key, e.g. "chatgpt", is a value from `validClientsToUse`.
// If not set, ALL options will be ALLOWED to be changed. For example, `bing` is not defined in `perMessageClientOptionsWhitelist` above,
// so all options for `bingAiClient` will be allowed to be changed.
// If set, ONLY the options listed here will be allowed to be changed.
// In this example, each array element is a string representing a property in `chatGptClient` above.
chatgpt : [
'promptPrefix' ,
'userLabel' ,
'chatGptLabel' ,
// Setting `modelOptions.temperature` here will allow changing ONLY the temperature.
// Other options like `modelOptions.model` will not be allowed to be changed.
// If you want to allow changing all `modelOptions`, define `modelOptions` here instead of `modelOptions.temperature`.
'modelOptions.temperature' ,
] ,
} ,
} ,
// Options for the CLI app
cliOptions : {
// (Optional) Possible options: "chatgpt", "bing".
// clientToUse: 'bing',
} ,
} ;另外,您可以直接安裝和運行包。
git clone https://github.com/waylaidwanderer/node-chatgpt-apinpm install安裝依賴項(如果不使用Docker)settings.example.js到root目錄中的settings.js ,並在需要時更改設置。npm start或npm run server (如果不使用Docker)docker-compose up (需要Docker) 開始或繼續對話。可選參數僅對於跨越多個請求的對話必需。
| 場地 | 描述 |
|---|---|
| 訊息 | 向用戶顯示的消息。 |
| 對話 | (可選)您想繼續進行對話的ID。 |
| 越獄折音 | (可選,僅適用於BingAIClient )設置為true以在越獄模式開始對話。之後,這應該是越獄對話的ID(在回應中以參數為參數也稱為jailbreakConversationId )。 |
| parentmessageid | (可選,適用於ChatGPTClient ,以及在越獄模式下的BingAIClient )在繼續對話時,父郵件的ID(即response.messageId )。 |
| 對話簽名 | (可選,僅適用於BingAIClient )對話的簽名(響應中作為參數給出的conversationSignature )。除非處於越獄模式,否則繼續對話時需要。 |
| 客戶端 | (可選,僅適用於BingAIClient )客戶端的ID。除非處於越獄模式,否則繼續對話時需要。 |
| invocationId | (可選,僅適用於BingAIClient )調用的ID。除非處於越獄模式,否則繼續對話時需要。 |
| 客戶端 | (可選)一個包含客戶端選項的對象。 |
| clientoptions.clienttouse | (可選)用於此消息的客戶端。可能的值: chatgpt , chatgpt-browser , bing 。 |
| 客戶端。* | (可選)對客戶端的任何有效選項。例如,對於ChatGPTClient ,您可以設置clientOptions.openaiApiKey僅設置此消息的API鍵,或clientOptions.promptPrefix ,以提供此消息的AI自定義說明,僅此信息。 |
要配置每個消息可以更改哪些選項(默認值:ALL),請參閱settings.example.js中的perMessageClientOptionsWhitelist的註釋。為了允許更改的客戶端,必須如示例設置文件中所述將perMessageClientOptionsWhitelist.validClientsToUse設置為非空數陣列。
要啟動與ChatGpt的對話,請將POST請求發送到服務器的/conversation端點,該端點具有每個端點參數>上面的參數>上面的參數。
{
"message" : " Hello, how are you today? " ,
"conversationId" : " your-conversation-id (optional) " ,
"parentMessageId" : " your-parent-message-id (optional, for `ChatGPTClient` only) " ,
"conversationSignature" : " your-conversation-signature (optional, for `BingAIClient` only) " ,
"clientId" : " your-client-id (optional, for `BingAIClient` only) " ,
"invocationId" : " your-invocation-id (optional, for `BingAIClient` only) " ,
}該服務器將返回包含ChatGpt響應的JSON對象:
// HTTP/1.1 200 OK
{
"response" : "I'm doing well, thank you! How are you?" ,
"conversationId" : "your-conversation-id" ,
"messageId" : "response-message-id (for `ChatGPTClient` only)" ,
"conversationSignature" : "your-conversation-signature (for `BingAIClient` only)" ,
"clientId" : "your-client-id (for `BingAIClient` only)" ,
"invocationId" : "your-invocation-id (for `BingAIClient` only - pass this new value back into subsequent requests as-is)" ,
"details" : "an object containing the raw response from the client"
}如果請求不成功,服務器將返回帶有錯誤消息的JSON對象。
如果請求對象缺少必需的屬性(例如message ):
// HTTP/1.1 400 Bad Request
{
"error" : "The message parameter is required."
}如果有錯誤將消息發送到chatgpt:
// HTTP/1.1 503 Service Unavailable
{
"error" : "There was an error communicating with ChatGPT."
}您可以在請求主體中設置"stream": true ,以在生成時接收這些令牌。
import { fetchEventSource } from '@waylaidwanderer/fetch-event-source' ; // use `@microsoft/fetch-event-source` instead if in a browser environment
const opts = {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
} ,
body : JSON . stringify ( {
"message" : "Write a poem about cats." ,
"conversationId" : "your-conversation-id (optional)" ,
"parentMessageId" : "your-parent-message-id (optional)" ,
"stream" : true ,
// Any other parameters per `Endpoints > POST /conversation` above
} ) ,
} ;有關如何在生成時接收響應的示例,請參見Demos/use-api-server-streaming.js。您將一次收到一個令牌,因此您需要自己加入它們。
成功的輸出:
{ data : '' , event : '' , id : '' , retry : 3000 }
{ data : 'Hello' , event : '' , id : '' , retry : undefined }
{ data : '!' , event : '' , id : '' , retry : undefined }
{ data : ' How' , event : '' , id : '' , retry : undefined }
{ data : ' can' , event : '' , id : '' , retry : undefined }
{ data : ' I' , event : '' , id : '' , retry : undefined }
{ data : ' help' , event : '' , id : '' , retry : undefined }
{ data : ' you' , event : '' , id : '' , retry : undefined }
{ data : ' today' , event : '' , id : '' , retry : undefined }
{ data : '?' , event : '' , id : '' , retry : undefined }
{ data : '<result JSON here, see Method 1>' , event : 'result' , id : '' , retry : undefined }
{ data : '[DONE]' , event : '' , id : '' , retry : undefined }
// Hello! How can I help you today?錯誤輸出:
const message = {
data : '{"code":503,"error":"There was an error communicating with ChatGPT."}' ,
event : 'error' ,
id : '' ,
retry : undefined
} ;
if ( message . event === 'error' ) {
console . error ( JSON . parse ( message . data ) . error ) ; // There was an error communicating with ChatGPT.
} fetch-event-source並使用POST方法。按照API服務器的相同設置說明,創建settings.js 。
如果在全球安裝:
chatgpt-cli如果在本地安裝:
npm run cliChatgpt的響應會自動複製到剪貼板上,因此您可以將其粘貼到其他應用程序中。
如上所述,您可以在ChatGPTClient的選項中設置reverseProxyUrl ,以使用反向代理服務器而不是官方的chatgpt API。就目前而言,這是使用Chatgpt基礎模型的唯一方法。此方法已修補,以下說明不再相關,但是由於其他原因,您可能仍希望使用反向代理。當前,反向代理服務器仍用於為ChatGPTBrowserClient執行Cloudflare旁路。
它如何工作?簡單答案: ChatGPTClient >反向代理> OpenAI服務器。反向代理服務器在引擎蓋下做一些魔術,以直接通過OpenAI的服務器訪問基礎模型,然後將響應返回到ChatGPTClient 。
下面提供說明。
accessToken屬性)。reverseProxyUrl設置為https://chatgpt.hato.ai/completions settings.js > chatGptClient或ChatGPTClient的選項。settings.chatGptClient.openaiApiKey )設置為您在步驟1中獲得的訪問訪問令牌。model設置為text-davinci-002-render , text-davinci-002-render-paid或text-davinci-002-render-sha具體取決於您的帳戶可以訪問的ChatGPT模型。模型必須是ChatGpt模型名稱,而不是基礎模型名稱,並且您無法使用您的帳戶無法訪問的型號。stream: true (API)或onProgress (客戶端)作為解決方法。accessToken屬性)。reverseProxyUrl設置為https://chatgpt.pawan.krd/api/completions in settings.js > chatGptClient或ChatGPTClient的選項。settings.chatGptClient.openaiApiKey )設置為您在步驟1中獲得的訪問訪問令牌。model設置為text-davinci-002-render , text-davinci-002-render-paid或text-davinci-002-render-sha具體取決於您的帳戶可以訪問的ChatGPT模型。模型必須是ChatGpt模型名稱,而不是基礎模型名稱,並且您無法使用您的帳戶無法訪問的型號。stream: true (API)或onProgress (客戶端)作為解決方法。使用@waylaidwanderer/chatgpt-api令人敬畏項目的列表:
通過編輯此讀數並創建拉動請求,將您的列表添加到列表中!
該項目的Web客戶端也可以在Waylaidwanderer/Pandoraai上獲得。
ChatGPTClient由於gpt-3.5-turbo是Chatgpt的基礎模型,因此我必須盡力複製官方Chatgpt網站使用它的方式。這意味著我的實施或基礎模型在某些方面可能並不完全相同:
如果您想為此項目做出貢獻,請創建一個拉動請求,並詳細說明您的更改。
該項目已根據MIT許可獲得許可。