Coder Social home page Coder Social logo

theawesomeyopro1 / cai.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mirajalone/cai.js

2.0 0.0 0.0 65 KB

A character.ai API for Node.js

Home Page: https://www.npmjs.com/package/cai.js

License: GNU General Public License v3.0

JavaScript 100.00%

cai.js's Introduction

cai.js

cai.js is a JavaScript library that provides access to the Character.ai API, allowing you to interact with chatbots and create conversational experiences in your JavaScript applications.

Installation

You can install the library via npm:

npm install cai.js

Quick Start

To get started with cai.js and initiate a conversation with a chatbot, follow these steps:

const c = require('cai.js');
const cai = new c();

(async () => {
    // Authenticate as a guest
    await cai.guestAuth();

    // Replace with the character ID of your chatbot
    const characterId = "M5xMXf4FKepKTYtWPqVaEZzuEuy90uu0eNZr4GZtDsA";

    // Create a chat instance
    const chat = await cai.createChat(characterId);

    // Send a message and await a response
    const response = await chat.send('Hello', true);

    console.log(response);
})();

You can find the character ID in the URL when you visit your chatbot's page, the character Id is value of char

Screenshot 2023-09-02 075802

Image Interactions

Generate an Image

To generate an image within the conversation, use:

await chat.generateImage("An avenue");

Upload an Image

To upload an image from a URL to the conversation, use:

await chat.uploadImage("https://www.imageurl.com/");

Send a Message with an Image

You can send a message along with an image:

await chat.send("Hello", { image_rel_path: "https://www.image.com/" }, true);

Other Chat Interactions

Chat History

Fetch the chat history:

await chat.fetchHistory(pageNumber);

Change Conversation by ID

Change the conversation by its external ID:

await chat.changeConversationById(conversationExternalId, force = false);

Get Saved Conversations

Fetch all saved conversations:

await chat.getSavedConversations(amount = 50);

Get Message by ID

Retrieve a message by its ID:

await chat.getMessageById(messageId);

Delete Message by ID

Delete a message by its ID:

await chat.deleteMessage(messageId);

Delete Multiple Messages

Delete multiple messages:

await chat.deleteMessages(messageIds);

Bulk Message Deletion

Perform bulk message deletion:

await chat.deleteMessagesBulk(amount = 50, descending = false);

Start a New Chat

Start a new chat:

await chat.newChat();

Functions Without chat Object

These functions do not require a chat object and provide general information:

Fetch Chatbot Categories

Fetch chatbot categories:

await fetchCategories();

Fetch User Configuration

Fetch user configuration:

await fetchUserConfig();

Fetch User Information

Fetch user information:

await fetchUser();

Fetch Featured Chatbots

Fetch featured chatbots:

await fetchFeaturedCharacters();

Fetch Chatbots by Categories

Fetch chatbots by categories:

await fetchCharactersByCategory(curate = false);

Fetch Chatbot Information

Fetch information about a specific chatbot:

await fetchCharacterInfo(characterId);

Search for Chatbots

Search for chatbots by name:

await searchCharacters(characterName);

Authentication

To authenticate with Character.ai, follow these steps:

  1. Go to Character.ai.

  2. Open your browser's developer tools and navigate to the "Storage" tab, then "Local Storage."

  3. Look for the key @@auth0spajs@@::dyD3gE281MqgISG7FuIXYhL2WEknqZzv::https://auth0.character.ai/::openid profile email offline_access and open its body to copy the access token.

  4. You can log in as a guest using guestAuth() or log in with your account using tokenAuth().

If you have a c.ai plus account, make sure to update .usePlus in the requester.js file and adjust .forceWaitingRoom accordingly.

Now you're ready to create engaging conversational experiences with cai.js!

Feel free to add your logo and customize this README further to fit your project's needs.

cai.js's People

Contributors

enginestein avatar

Stargazers

 avatar theawesomeyopro 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.