realcoloride / node_characterai

Unofficial Character AI wrapper for node.
https://beta.character.ai/
341 stars 72 forks source link

The example code in README.md throws an Error #155

Closed SeoulSKY closed 4 months ago

SeoulSKY commented 6 months ago

Version: 1.2.5

I tried to run the code in README.md

  const characterAI = new CharacterAI();
  await characterAI.authenticateAsGuest();

  // Place your character's id here
  const characterId = "8_1NyR8w1dOXmI1uWaieQcd147hecbdIK7CeEAIrdJw";

  const chat = await characterAI.createOrContinueChat(characterId);

  // Send a message
  const response = await chat.sendAndAwaitResponse(
      "Hello discord mod!",
      true
  );

But I get the following exception

Traceback:

/Users/swkim7519/Desktop/SoruSora/sorusora-ai/node_modules/node_characterai/chat.js:70
            for (let i = 0; i < replies.length; i++) {
                                        ^
TypeError: Cannot read properties of undefined (reading 'length')
    at Chat.sendAndAwaitResponse (/Users/swkim7519/Desktop/SoruSora/sorusora-ai/node_modules/node_characterai/chat.js:70:41)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

When I debug the Chat.sendAndAwaitResponse(), the request.code is 200 and the response object is the following:

{
  "force_login": true
}

So, the issue is that the response.replies is undefined and it tries to get length properly from undefined

SeoulSKY commented 6 months ago

Changing authenticateAsGuest() with authenticateWithToken() fixes the problem. I believe there is a problem in authenticateAsGuest()

realcoloride commented 6 months ago

Hello,

this is an intended error and nothing is wrong. Force login means you've reached the quota of messages. Sadly it looks like characterAI has restricted guests users.

devaoto commented 6 months ago

@realcoloride restricted? Means we can no longer authenticate as guests?

realcoloride commented 6 months ago

Exactly. Try opening CharacterAI in an incognito tab and see how they restrict you from the first message.

devaoto commented 6 months ago

Wow, character ai seriously removed guest authentication system, it's not a big issue though

SeoulSKY commented 6 months ago

@realcoloride It's odd that I got this error because I ran the code for the first time. Anyway, if authenticateAsGuest() no longer works, I think it would be better if you modify the example code in README.md because people might think your library no longer works or at least throw a custom error saying you used all quotas. Thank you!

realcoloride commented 6 months ago

They do these kinds of unprevented things here and then sometimes. Sorry.

They might restore it soon, though. I will not change the README.md because it happened before and they restored the guest logins shortly. So just in case, if they (any developer) get the problem, they shall see this issue or open an issue and I will redirect them.

For now, please use authenticateWithToken, sorry for the incovenience!

realcoloride commented 6 months ago

least throw a custom error that the function no longer works

I will not make that but I will definitely make an exception and throw an error.

SeoulSKY commented 6 months ago

sorry for the incovenience!

No worries. I appreciate your hard work, and I totally understand that this kind of problem might happen frequently with using their unofficial API :).

realcoloride commented 6 months ago

Hello, I have commited https://github.com/realcoloride/node_characterai/commit/144f2bb9b5cabfa514e0c9b1b0c4520223e1d0d1 and experimental version 1.2.7 has been pushed. Please let me know if you get a proper error now.

SeoulSKY commented 6 months ago

Please let me know if you get a proper error now.

It now throws a proper error with the example code in README.md :)

Error: Too many messages! (this might be because you use a guest account or that characterai has restricted messages for guests.)
    at new Reply (/Users/swkim7519/Desktop/SoruSora/sorusora-ai/node_modules/node_characterai/message.js:119:48)
    at Chat.sendAndAwaitResponse (/Users/swkim7519/Desktop/SoruSora/sorusora-ai/node_modules/node_characterai/chat.js:68:24)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)