[X] I verified that the issue exists in the latest chatgpt release
Verify webapp is working
[X] I verify that the ChatGPT webapp is working properly for this account.
Environment details
Node.js version: v14.21.3 (I can't upgrade due to old OS)
Browser version: Chrome Version 114.0.5735.199
OS version: CentOS 7
Describe the Bug
I am using Node v14 (I can't upgrade to 18 for other reasons) so I am trying to follow the guide to install a polyfill to get fetch to work but I am not sure how to do that.
What I have so far in chat.mjs,
import { ChatGPTUnofficialProxyAPI } from 'chatgpt'
async function example() {
const api = new ChatGPTUnofficialProxyAPI({
accessToken: process.env.OPENAI_ACCESS_TOKEN
})
const res = await api.sendMessage('Hello World!')
console.log(res.text)
}
example();
I try to run with node --unhandled-rejections=strict chat.mjs but I end up with this
file:///home/jguirgis/node_modules/chatgpt/build/index.js:503
throw new Error("Invalid environment; fetch is not defined");
^
Error: Invalid environment; fetch is not defined
at new ChatGPTUnofficialProxyAPI (file:///home/jguirgis/node_modules/chatgpt/build/index.js:503:13)
at example (file:///home/jguirgis/chat.mjs:4:15)
at file:///home/jguirgis/chat.mjs:12:1
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
at async handleMainPromise (internal/modules/run_main.js:59:12)
I tried adding import 'unfetch/polyfill' but that produces a different error,
/home/jguirgis/node_modules/unfetch/polyfill/index.js:1
self.fetch||(self.fetch=function(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u={},a=function e(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:e,headers:{keys:function(){return o},entries:function(){return o.map(function(e){return[e,s.getResponseHeader(e)]})},get:function(e){return s.getResponseHeader(e)},has:function(e){return null!=s.getResponseHeader(e)}}}};for(var i in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm,function(e,n){u[n]||o.push(u[n]=n)}),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(i,n.headers[i]);s.send(n.body||null)})});
^
ReferenceError: self is not defined
at Object.<anonymous> (/home/jguirgis/node_modules/unfetch/polyfill/index.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:1114:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:979:32)
at Function.Module._load (internal/modules/cjs/loader.js:819:12)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:203:29)
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
at async handleMainPromise (internal/modules/run_main.js:59:12)
Verify latest release
chatgpt
releaseVerify webapp is working
Environment details
Node.js version: v14.21.3 (I can't upgrade due to old OS) Browser version: Chrome Version 114.0.5735.199 OS version: CentOS 7
Describe the Bug
I am using Node v14 (I can't upgrade to 18 for other reasons) so I am trying to follow the guide to install a polyfill to get fetch to work but I am not sure how to do that. What I have so far in
chat.mjs
,I try to run with
node --unhandled-rejections=strict chat.mjs
but I end up with thisI tried adding
import 'unfetch/polyfill'
but that produces a different error,I am quite lost, any help would be appreciated.