Ifyouhaveaccesstothegpt-4model,youcanrunthefollowingtotestouttheCLIwithGPT-4:
WestillsupportboththeofficialChatGPTAPIandtheunofficialproxyAPI,butwenowrecommendusingtheofficialAPIsinceit'ssignificantlymorerobustandsupportsGPT-4.
Note:WestronglyrecommendusingChatGPTAPIsinceitusestheofficiallysupportedAPIfromOpenAI.WewilllikelyremovesupportforChatGPTUnofficialProxyAPIinafuturerelease.
Note:WestronglyrecommendusingChatGPTAPIsinceitusestheofficiallysupportedAPIfromOpenAI.WemayremovesupportforChatGPTUnofficialProxyAPIinafuturerelease.
WenowprovidethreewaysofaccessingtheunofficialChatGPTAPI,allofwhichhavetradeoffs:
Note:IrecommendthatyouuseeitherChatGPTAPIorChatGPTUnofficialProxyAPI.
OpenAIhasdisabledtheleakedchatmodelwewerepreviouslyusing,sowe'renowdefaultingtotext-davinci-003,whichisnotfree.
We'vefoundseveralotherhidden,fine-tunedchatmodels,butOpenAIkeepsdisablingthem,sowe'researchingforalternativeworkarounds.
exportOPENAI_API_KEY="sk-TODO"npxchatgpt"yourprompthere"Bydefault,theresponseisstreamedtostdout,theresultsarestoredinalocalconfigfile,andeveryinvocationstartsanewconversation.Youcanuse-ctocontinuethepreviousconversationand--no-streamtodisablestreaming.
Usage:$chatgpt
TousethismodulefromNode.js,youneedtopickbetweentwomethods:
BothapproacheshaveverysimilarAPIs,soitshouldbesimpletoswapbetweenthem.
Note:WestronglyrecommendusingChatGPTAPIsinceitusestheofficiallysupportedAPIfromOpenAIanditalsosupportsgpt-4.WewilllikelyremovesupportforChatGPTUnofficialProxyAPIinafuturerelease.
constapi=newChatGPTAPI({apiKey:process.env.OPENAI_API_KEY,completionParams:{model:'gpt-4',temperature:0.5,top_p:0.8}})Ifyouwanttotracktheconversation,you'llneedtopasstheparentMessageIdlikethis:
constapi=newChatGPTAPI({apiKey:process.env.OPENAI_API_KEY})//sendamessageandwaitfortheresponseletres=awaitapi.sendMessage('WhatisOpenAI')console.log(res.text)//sendafollow-upres=awaitapi.sendMessage('Canyouexpandonthat',{parentMessageId:res.id})console.log(res.text)//sendanotherfollow-upres=awaitapi.sendMessage('Whatwerewetalkingabout',{parentMessageId:res.id})console.log(res.text)YoucanaddstreamingviatheonProgresshandler:
constres=awaitapi.sendMessage('Writea500wordessayonfrogs.',{//printthepartialresponseastheAIis"typing"onProgress:(partialResponse)=>console.log(partialResponse.text)})//printthefulltextattheendconsole.log(res.text)YoucanaddatimeoutusingthetimeoutMsoption:
constapi=newChatGPTAPI({apiKey:process.env.OPENAI_API_KEY,debug:true})WedefaulttoabasicsystemMessage.YoucanoverridethisineithertheChatGPTAPIconstructororsendMessage:
constres=awaitapi.sendMessage('whatistheanswertotheuniverse',{systemMessage:`YouareChatGPT,alargelanguagemodeltrainedbyOpenAI.YouanswerasconciselyaspossibleforeachresponseIfyouaregeneratingalist,donothavetoomanyitems.Currentdate:${newDate().toISOString()}\n\n`})Notethatweautomaticallyhandleappendingthepreviousmessagestothepromptandattempttooptimizefortheavailabletokens(whichdefaultsto4096).
npxtsxdemos/demo-reverse-proxy.tsChatGPTUnofficialProxyAPImessagesalsocontainaconversationidinadditiontoparentMessageId,sincetheChatGPTwebappcan'treferencemessagesacrossdifferentaccounts&conversations.
YoucanoverridethereverseproxybypassingapiReverseProxyUrl:
Note:infoonhowthereverseproxiesworkisnotbeingpublishedatthistimeinordertopreventOpenAIfromdisablingaccess.
TouseChatGPTUnofficialProxyAPI,you'llneedanOpenAIaccesstokenfromtheChatGPTwebapp.Todothis,youcanuseanyofthefollowingmethodswhichtakeanemailandpasswordandreturnanaccesstoken:
Theselibrariesworkwithemail+passwordaccounts(e.g.,theydonotsupportaccountswhereyouauthviaMicrosoft/Google).
Accesstokenslastfordays.
Note:usingareverseproxywillexposeyouraccesstokentoathird-party.Thereshouldn'tbeanyadverseeffectspossiblefromthis,butpleaseconsidertherisksbeforeusingthismethod.
MostofthedemosuseChatGPTAPI.ItshouldbeprettyeasytoconvertthemtouseChatGPTUnofficialProxyAPIifyou'dratherusethatapproach.TheonlythingthatneedstochangeishowyouinitializetheapiwithanaccessTokeninsteadofanapiKey.
Toruntheincludeddemos:
npxtsxdemos/demo-on-progress.tsTheonprogressdemousestheoptionalonProgressparametertosendMessagetoreceiveintermediaryresultsasChatGPTis"typing".
Note:PersistenceishandledautomaticallywhenusingChatGPTUnofficialProxyAPIbecauseitisconnectingindirectlytoChatGPT.
Ifyoucreateacoolintegration,feelfreetoopenaPRandaddittothelist.