Giter Site home page Giter Site logo

node_characterai's Introduction

Character AI Unofficial Node API

Node.js client for the unofficial Character AI API, an awesome website which brings characters to life with AI!

Intro

This repository is inspired by RichardDorian's unofficial node API. Though, I found it hard to use and it was not really stable and archived. So I remade it in javascript.

This project is not affiliated with Character AI in any way! It is a community project. The purpose of this project is to bring and build projects powered by Character AI.

If you like this project, please check their website.

Features

  • ๐Ÿ‘ Fully written in Javascript and CommonJS (for max compatibility and ease of use)
  • โŒš Asynchronous requests
  • ๐Ÿ—ฃ๏ธ Use conversations or use the API to fetch information
  • ๐Ÿงธ Easy to use
  • ๐Ÿ” Active development
  • ๐Ÿ‘ค Guest & token login support

Installation

npm install node_characterai

Usage

Basic guest login and conversation message:

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.
})();

Using an Access Token

Some parts of the API, like managing a conversation requires for you to be logged in using an accessToken. To get it, you can open your browser, go to the character.ai website in localStorage.

To do so:

  1. Open the Character AI website in your browser
  2. Open the developer tools F12 and go to the Application tab.
  3. Go to the Storage section and click on Local Storage.
  4. Look for the @@auth0spajs@@::dyD3gE281MqgISG7FuIXYhL2WEknqZzv::https://auth0.character.ai/::openid profile email offline_access key.
  5. Open the body and copy the access token.

Access_Token

When using the package, you can:

  • Login as guest using authenticateAsGuest() - for mass usage or testing purposes
  • Login with your account or a token using authenticateWithToken()

Finding the Character ID

You can find your character ID in the URL of a Character's chat page. For example, if you go to the chat page of the character Test Character you will see the URL https://character.ai/chat/chat?char=5f7f9b9b9b9b9b9b9b9b9b9b.

The last part of the URL is the character ID: Character_ID

Troubleshooting

Problem Answer
โŒ Token was invalid Make sure your token is actually valid and you copied your entire token (its pretty long).
โ“ Fetch is not defined Upgrade to node 18 or higher (19 is better) or try installing node-fetch.
๐Ÿ‘ฅ authenticateAsGuest() doesn't work See issue #14.
๐Ÿฆ’ Hit the max amount of messages? Sadly, guest accounts only have a limited amount of messages before they get limited and forced to login. See below for more info ๐Ÿ‘‡
๐Ÿช How to use an account to mass use the library? You can use conversations, a feature introduced in 1.0.0, to assign to users and channels. To reproduce a conversation, use OOC (out of character) to make the AI think you're with multiple people. See an example here: chrome_RDbmXXtFNlchrome_BgF8crPvqC (Disclaimer: on some characters, their personality will make them ignore any OOC request).
๐Ÿ˜ฎ Why is a chrome window opening? This is because as of currently, the simple fetching is broken and I use puppeteer (a chromium browser control library) to go around cloudflare's restrictions.
๐Ÿ“ฃ Is this official? No, this project is made by a fan of the website and is unofficial. To support the developers, please check out their website.
๐Ÿ˜ฒ Did something awesome with node_characterai? Please let me know!
โœ‰๏ธ Want to contact me? See my profile
๐Ÿ’ก Have an idea? Open an issue in the Issues tab
โž• Other issue? Open an issue in the Issues tab

Disclaimer

โค๏ธ This project is updated frequently, always check for the latest version for new features or bug fixes.

๐Ÿš€ If you have an issue or idea, let me know in the Issues tab. ๐Ÿ“œ If you use this API, you also bound to the terms of usage of their website.

(real)coloride - 2023, Licensed MIT.

node_characterai's People

Contributors

onnowhere avatar realcoloride avatar reymaicer avatar

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.