I keep getting a 404 Error.
[0] Error: Request failed with status code 404
[0] at createError (/Users/user/Documents/Collabs/ChatGPT/ChatGPT-SCRPT/server/node_modules/openai/node_modules/axios/lib/core/createError.js:16:15)
[0] at settle (/Users/user/Documents/Collabs/ChatGPT/ChatGPT-SCRPT/server/node_modules/openai/node_modules/axios/lib/core/settle.js:17:12)
[0] at IncomingMessage.handleStreamEnd (/Users/user/Documents/Collabs/ChatGPT/ChatGPT-SCRPT/server/node_modules/openai/node_modules/axios/lib/adapters/http.js:322:11)
[0] at IncomingMessage.emit (node:events:524:35)
[0] at endReadableNT (node:internal/streams/readable:1359:12)
[0] at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[0] config: {
[0] transitional: {
[0] silentJSONParsing: true,
[0] forcedJSONParsing: true,
[0] clarifyTimeoutError: false
[0] },
[0] adapter: [Function: httpAdapter],
[0] transformRequest: [ [Function: transformRequest] ],
[0] transformResponse: [ [Function: transformResponse] ],
[0] timeout: 0,
[0] xsrfCookieName: ‘XSRF-TOKEN’,
[0] xsrfHeaderName: ‘X-XSRF-TOKEN’,
[0] maxContentLength: -1,
[0] maxBodyLength: -1,
[0] validateStatus: [Function: validateStatus],
[0] headers: {
[0] Accept: ‘application/json, text/plain, /’,
[0] ‘Content-Type’: ‘application/json’,
[0] ‘User-Agent’: ‘OpenAI/NodeJS/3.2.1’,
[0] Authorization: ’
[0] ‘OpenAI-Organization’:
[0] ‘Content-Length’: 869
[0] },
This is my code (sorry maybe a little extra as I am not a coder, but simply a user of the code)
const openai = new OpenAIApi(configuration);
const { backOff } = require(“exponential-backoff”);
const BackOffOptions = {
};
router.post(‘/’, async (req, res) => {
const { message } = req.body;
const response = await backOff(() => openai.ChatCompletion.create({
model: “gpt-4-1106-preview”,
message: [
{“role”: “system”, “content”: “You are a creative writer.”},
{“role”: “user”, “content”: “Who won the world series in 2020?”}
],
max_tokens: 1000,
temperature: 0.7,
}));
res.json({ botResponse: response.data.choices[0].text });
});
router.post(‘/task’, (req, res) => {
try {
const {doc, sheet, type} = req.body;
let workbook = new Excel.Workbook();
workbook.xlsx.readFile(doc).then(async () => {
let worksheet = workbook.getWorksheet(sheet);
let roles = {};
for (let i = 1; i < 21; i ++) {
if(worksheet.getCell('A' + i).value) {
roles[worksheet.getCell('A' + i).value] = worksheet.getCell('B' + i).value;
}
if(worksheet.getCell('D' + i).value) {
roles[worksheet.getCell('D' + i).value] = worksheet.getCell('E' + i).value;
}
}
if(type === 'Build') {
let colCount = worksheet.columnCount;
let row1 = worksheet.getRow(21);
for(let i = 22; i <= worksheet.rowCount; i ++) {
let row = worksheet.getRow(i);
let lastAnswer = '';
for (let j = 3; j <= colCount; j ++) {
let prompt = row1.getCell(j).value;
if(prompt !== null && row.getCell('B').value !== null && row.getCell(j).value === null) {
prompt = replaceCells(worksheet, row, roles, prompt);
let response = {
status: 0,
data: {
error: null
}
};
while(response.data.error || response.status !== 200) {
console.log('sending prompt...............');
console.log(prompt + '\n');
try {
response = await backOff(() => openai.createChatCompletion({
model: "gpt-4-1106-preview",
messages: [
{role: "system", content: roles['SystemRole']},
{role: "user", content: prompt}
],
temperature: 0.7,
max_tokens: 1000,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
}));
} catch (err) {
//workbook.xlsx.writeFile(doc);
console.log(err);
continue;
//return res.status(500).json({error: 'Server Error'});
}
}
lastAnswer = response.data.choices[0].message.content.trim();
console.log('result-----------------------------------------');
console.log(lastAnswer + '\n');