1.第一步是打开一个梯子,让你的电脑连接到国际互联网。
2.安装axios
3.使用axios向openai发送post请求,最重要的是,在请求中指定你的梯子。
const axios = require('axios');
const itRealyFuckedMe= async (input) => {
try {
let data = {
model: "gpt-3.5-turbo",
messages: [
{ "role": "user", "content": input }
]
};
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.openai.com/v1/chat/completions',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${openAIKeys}`
},
data: data,
proxy: {
/*
It depends on your real proxy configuration,
Open your proxy client and view the configuration information.
*/
host: "127.0.0.1",
port: 7890,
protocol: "http"
}
};
let completion = await axios(config)
.then((response) => {
console.log("response.data:", JSON.stringify(response.data));
return response.data.choices[0].message
})
.catch((error) => {
console.log(error);
});
return completion
} catch (error) {
console.log(error);
}
};
暂无评论