PawanOsman / chatgpt-io

ChatGPT Client API, Blazing Fast, without using browser
https://www.npmjs.com/package/chatgpt-io
MIT License
122 stars 18 forks source link

Error: Request failed with status code 400 at ChatGPT.getTokens node_modules/chatgpt-io/dist/classes/chatgpt.js:174:19 #16

Open jsugg opened 1 year ago

jsugg commented 1 year ago

Hey there!

Good idea to create this wrapper. I thought about making one myself at some point, but then I read OpenAI's policies and held back 😅. So, it was great to find your project here!

I wanted to inform you about a strange behavior I see here. I'm getting a 400, even after triple-checking the session id, so I decided to bring this to you. I'll paste the code and the error here. If you need any other information, please let me know.

Project structure

.
├── .env
├── index.js
├── node_modules
├── package-lock.json
└── package.json

.env CHATGPT_SESSION_TOKEN="__Secure-next-auth.session-token value"

index.js

require("dotenv").config();
const readline = require("readline");

let ChatGPT;

async function loadChatGPT() {
    const module = await import('chatgpt-io');
    ChatGPT = module.default || module;
}

loadChatGPT().then( async () => {
    let response;

    const bot = new ChatGPT(process.env.CHATGPT_SESSION_TOKEN).then(
        () => { console.log('Bot loaded!') }).catch(err => { console.log(err) });

    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
        terminal: false
    });

    while (readline.line && readline.line != "exit") {
        response = await bot.ask(readline.line);
        console.log(`Bot > ${response}`);
    }

    rl.close().then(() => { process.exit(0) });
});

package.json

{
  "name": "chatgpt-real-wrapper",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "chatgpt-io": "^1.1.4",
    "dotenv": "^16.0.3"
  }
}

Error

➜  chatgpt-real-wrapper node index.js
Bot loaded!
You > [ERROR] 2023-05-30 17:36:24 Request failed with status code 400
file:///Users/juanpedrosugg/Dev/chatgpt-real-wrapper/node_modules/chatgpt-io/dist/classes/chatgpt.js:174
            throw new Error(result.error);
                  ^

Error: Request failed with status code 400
    at ChatGPT.getTokens (file:///Users/juanpedrosugg/Dev/chatgpt-real-wrapper/node_modules/chatgpt-io/dist/classes/chatgpt.js:174:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Timeout._onTimeout (file:///Users/juanpedrosugg/Dev/chatgpt-real-wrapper/node_modules/chatgpt-io/dist/classes/chatgpt.js:42:17)
➜  chatgpt-real-wrapper 

status 400

isman712 commented 11 months ago

Tambien tengo este error