Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

The CharacterAI Web API is a server application built using Node.js, Express.js, Puppeteer, and the node_characterai module. This application serves as a bridge between users and an external service, in this case, the CharacterAI service that enables the creation of intelligent chatbots.

NotificationsYou must be signed in to change notification settings

SazumiVicky/cAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 

Repository files navigation

The CharacterAI Web API is a server application built using Node.js, Express.js, Puppeteer, and thenode_characterai module. This application serves as a bridge between users and an external service, in this case, the CharacterAI service that enables the creation of intelligent chatbots.

Key Features:

  • Token Authentication: The web API allows users to authenticate themselves with the CharacterAI service using a valid token. This token is used to access the CharacterAI service.
  • Usage of Puppeteer: The application uses the Puppeteer module to manage the Chromium browser used for interacting with the CharacterAI service.
  • Request Queue: To avoid conflicts when multiple users access the API simultaneously, the application uses theasync.queue module to manage request queues.
  • Handling Concurrent Requests: The application has been updated to efficiently handle multiple requests from different users simultaneously, avoiding issues with invalid token authentication.
  • JSON Response: The web API provides responses in JSON format containing information about execution time, response text, and the relevant developer.

Usage:

Users can access this API by sending a GET request with the inclusion of parametersid (character ID),teks (text to be processed), andtoken (authentication token) through the URL. The API will respond with a JSON format containing the text processing results.

Notes:

Ensure that the authentication token used is valid and complies with any usage restrictions imposed by the CharacterAI service. Additionally, this application has been updated to address issues with invalid token authentication in concurrent request scenarios.

The CharacterAI Web API can be used to integrate the CharacterAI service with other applications or services you create, enabling the development of intelligent and responsive chatbots.

Step-by-Step Explanation:

1. Import the required modules:

constexpress=require("express");constpuppeteer=require("puppeteer");constCharacterAI=require("node_characterai");constasync=require("async");

2. Create an Express app:

constapp=express();

3. Use the express.json() middleware to parse JSON requests:

app.use(express.json());

4. Create an async queue to handle requests:

constqueue=async.queue(async(task,callback)=>{const{ characterId, message, accessToken, res}=task;try{if(!characterId||!message||!accessToken){thrownewError("Missing required parameters");}constisolatedCharacterAI=newCharacterAI();awaitisolatedCharacterAI.authenticateWithToken(accessToken);constchat=awaitisolatedCharacterAI.createOrContinueChat(characterId);conststart=Date.now();constbrowser=awaitinitializeBrowser();constpage=awaitbrowser.newPage();awaitpage.setRequestInterception(true);page.removeAllListeners('request');page.on('request',(request)=>{request.continue();});constresponse=awaitchat.sendAndAwaitResponse(message,true);constend=Date.now();constelapsedTime=end-start;constjsonResponse={Developer:"Sazumi Viki",Loaded:`${elapsedTime} ms`,Response:response.text,};awaitbrowser.close();res.setHeader("Content-Type","application/json");res.send(JSON.stringify(jsonResponse,null,2));if(typeofcallback==='function'){callback();}}catch(error){console.error("Error:",error.message);res.status(500).json({error:error.message||"Internal server error"});if(typeofcallback==='function'){callback(error);}}},

Thanks To

About

The CharacterAI Web API is a server application built using Node.js, Express.js, Puppeteer, and the node_characterai module. This application serves as a bridge between users and an external service, in this case, the CharacterAI service that enables the creation of intelligent chatbots.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp