import OpenAI from 'openai';
const openai = new OpenAI({apiKey: 'sk-*******'});
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: 'system', content: 'You are a helpful assistant.' }],
model: 'gpt-3.5-turbo',
});
console.log(completion.choices[0]);
}
main();
PermissionDeniedError: 403 Country, region, or territory not supported
at APIError.generate (file:///K:/JS/openai2/node_modules/openai/error.mjs:46:20)
at OpenAI.makeStatusError (file:///K:/JS/openai2/node_modules/openai/core.mjs:256:25)
at OpenAI.makeRequest (file:///K:/JS/openai2/node_modules/openai/core.mjs:299:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getGptResponse (file:///K:/JS/openai2/index.js:27:24) {
status: 403,
headers: {
'alt-svc': 'h3=":443"; ma=86400',
'cf-ray': '86fa96c54af49d56-DME',
connection: 'keep-alive',
'content-encoding': 'gzip',
'content-type': 'application/json',
date: 'Fri, 05 Apr 2024 15:32:06 GMT',
server: 'cloudflare',
'set-cookie': '__cf_bm=KPvuJkpFci9jxNT.zxe35R4nZRXh6Mp_RAQekc8JXFw-1712331126-1.0.1.1-oGOdyNmDoixQ4J2cBAJbAVfIHckBOo6yV_DmpvxlRCvSGUuN_pQcxnR2BuIhseEgv_DtYw.Kj0h4YO7gOrPKZg; path=/; expires=Fri, 05-Apr-24 16:02:06 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding'
},
error: {
message: 'Country, region, or territory not supported',
type: 'request_forbidden',
param: null,
code: 'unsupported_country_region_territory'
},
code: 'unsupported_country_region_territory',
param: null,
type: 'request_forbidden'
}
我有一个代理,但我不知道如何在代码中连接它们。告诉。
如果您正在使用此openai库,则文档页面明确说明如何使用代理(在配置 HTTP(S) 代理(例如,用于代理)标题下):
使用之前,不要忘记安装https-proxy-agent:
并替换
http://168.63.76.32:3128
为您的代理的地址和端口