Giter Club home page Giter Club logo

Comments (30)

realcoloride avatar realcoloride commented on July 29, 2024

Could you show me the code? Have you sure you put the correct token? I have tried it on my environment and it works perfectly.
image

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

Here's the code which, aside from the Discord stuff and the character, I basically copied from the example. It might be a bit messy as I'm still kinda a noob with js.

Do you have the testing environment or some basic code which I could use to test if it works? Looking at an older issue #1 has the same error I get, but it wasn't very clear to me what they did to fix it.

const { SlashCommandBuilder } = require('discord.js');

const node_characterai = require('node_characterai');
const characterAI = new node_characterai();



module.exports = {
    data: new SlashCommandBuilder()
        .setName('cai')
        .setDescription("Talk to Braixen from Character.AI! Remember, don't take anything an AI says seriously.")
        .addStringOption(option =>
            option
            .setName('message')
            .setDescription('What is your message to them?')
            .setRequired(true)
        ),

    async execute(interaction, responseMessage, dateTime) {

        const message = interaction.options.getString('message')
        
        await characterAI.authenticateAsGuest();

        const characterId = "FdOuMH3rMG39zYwTvu5qIYcHda9_oMMpU14BolueOcI";

        const chat = await characterAI.createOrContinueChat(characterId);
        const response = await chat.sendAndAwaitResponse(message, true);

        responseMessage = "";
        await interaction.reply(responseMessage);
        console.log(`${dateTime}    Responded to commands with ${responseMessage}`);
    },
};

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

see the main page, you'll have an example.

const CharacterAI = require('node_characterai');
const characterAI = new CharacterAI();

(async() => {
    await characterAI.authenticateAsGuest();

    const characterId = "8_1NyR8w1dOXmI1uWaieQcd147hecbdIK7CeEAIrdJw" // Discord moderator

    const chat = await characterAI.createOrContinueChat(characterId);
    const response = await chat.sendAndAwaitResponse('Hello discord mod!', true)

    console.log(response);
    // use response.text to use it in a string.
})();

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

You're kinda doing things wrong too. you should store an instance of the chat or characterai and use it per request instead of keep logging and creating new character ai instances when a message is sent

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

Well there isn't much documentation about how to keep the conversation going without starting a new one + the command is still very barebones and I'm just trying to see if I can get it to return anything. I'll just try the code provided in an empty js file and see if it works tomorrow

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

I used your example code in a blank file, and it still just fails on the lazy token. I could probably still test it in a completely new node project folder to rule out if there's any npm package conflicting with it, but I don't think that would be the case. I tried using just Chrome to go to https://beta.character.ai/chat/auth/lazy/ which does work, but it says {"detail":"Method "GET" not allowed."}. That might be normal though

node test.js
/Volumes/Stuff 8 TB/Shared/BraixenBot/node_modules/node_characterai/client.js:211
        } else throw Error('Failed to fetch a lazy token')
                     ^

Error: Failed to fetch a lazy token
    at Client.authenticateAsGuest (/Volumes/Stuff 8 TB/Shared/BraixenBot/node_modules/node_characterai/client.js:211:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Volumes/Stuff 8 TB/Shared/BraixenBot/test.js:5:5

Node.js v19.7.0

from node_characterai.

1Hibiki1 avatar 1Hibiki1 commented on July 29, 2024

I'm having the same issue with the example code. Just to check, I added a console.log(request) inside authenticateAsGuest, and sure enough, it returns a 403. Not sure why that's happening though.

Edit: It works when I send the same request through Postman:
Screenshot 2023-03-09 at 12 38 40

from node_characterai.

gwigz avatar gwigz commented on July 29, 2024

403 is likely Cloudflare blocking the request, which is what I'm seeing myself when I call using this and Node.

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

Hello!
Try using a proxy or a VPN. Doing it worked correctly for me. Which version of the package are you using? Which version of node?
image

from node_characterai.

1Hibiki1 avatar 1Hibiki1 commented on July 29, 2024

I got it to work. I just had to update node. Didn't work with v19.5.0, but works with v19.7.0. Thanks everyone!

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

all good then, waiting for op to confirm if the issue was caused by the same problem

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

all good then, waiting for op to confirm if the issue was caused by the same problem

Using Node.js v19.7.0 as seen on the other comments. What VPN do I need to use/which country do I need to connect to?

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

From Finland, not sure what the question about a code means.
If you're asking for my application's code, it's mentioned in the comment #13 (comment)

from node_characterai.

1Hibiki1 avatar 1Hibiki1 commented on July 29, 2024

Using Node.js v19.7.0 as seen on the other comments. What VPN do I need to use/which country do I need to connect to?

If u don't have a VPN already, how about try Cloudflare WARP? It doesn't let you select specific country, but it's free. btw I'm in the USA and it works without a VPN.

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

I mean source code of the application

From Finland, not sure what the question about a code means. If you're asking for my application's code, it's mentioned in the comment #13 (comment)

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

If u don't have a VPN already, how about try Cloudflare WARP? It doesn't let you select specific country, but it's free. btw I'm in the USA and it works without a VPN.

Tried with Cloudflare WARP, made no difference, unfortunately. This was expected though as Cloudflare has a server in my country, so WARP just connected to that.

I mean source code of the application

test.js
Or do you need the entire project folder?

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

This might be a region issue (use a vpn or proxy)/nodejs version/dependencies

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

I tried out Windscribe to connect to US Central, still the same exact error. What version of node.js do I need and what dependencies? Shouldn't all of them be installed by npm?

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

I tried out Windscribe to connect to US Central, still the same exact error. What version of node.js do I need and what dependencies? Shouldn't all of them be installed by npm?

"node-fetch": "^3.3.0",
"uuid": "^9.0.0",
"json-bigint": "^1.0.0"

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024
"node-fetch": "^3.3.0",
"uuid": "^9.0.0",
"json-bigint": "^1.0.0"

Checked and I seem to have all of them

piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info node-fetch version
3.3.1
piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info uuid version      
9.0.0
piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info json-bigint version
1.0.0

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

whats your current node version and package version?

from node_characterai.

Piipperi avatar Piipperi commented on July 29, 2024

whats your current node version and package version?

I'm sorry but I've now replied with the node version 2 or 3 times. It's v19.7.0. And the package versions are listed on my earlier reply...
If you need the node_characterai version, it's the latest 1.1.0.......

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

Hello! Your code did not fetch a lazy token for some reason, I will investigate the issue.
image

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

image
Turns out its because cloudflare seems to be blocking stuff...

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

Hello again, I will try to find a way to go around cloudflare and update you today. Thank you for the patience!
If you have any idea in how I can go around it in the meantime, please let me know!
Roadmap issue - #14

from node_characterai.

Naozumi520 avatar Naozumi520 commented on July 29, 2024

@realcoloride After contacting w/ user K3YOMI in #1, it turns out that he fixed with adding the user agent. He sent me a copy with the patched package and it was working, but today I checked for it and it returns nothing. Here's his modified version and I have granted his permission. I hope this helps you to confirm what's going on in here.

node_characterai.zip

According to his instructions, there are two step to make it work:

  1. fill in the the token (not access token) in chat.js, by replacing (TOKEN HERE) to the token (Keep the TOKEN word)
    The token can be found in the network tab of dev tool, by searching recent:

Screenshot 2023-03-14 at 9 38 38 PM

Screenshot 2023-03-14 at 9 38 55 PM

  1. Only authenticateWithToken will work (with access token), cannot login as guest

I have confirmed that it was working yesterday night, but somehow it stopped working in today. See if it works for you.

from node_characterai.

realcoloride avatar realcoloride commented on July 29, 2024

Merging all updates for 1.1.1 in a new issue: #17.
Thank you for your understanding and patience.

from node_characterai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.