The PersonalityAI npm package allows users to interact with their favorite characters using real-time data. The package provides methods for testing the API, conducting chat sessions, creating profiles, fetching images, and retrieving conversation history.
To use PersonalityAI in your project, install it using npm:
npm install personalityai
const PersonalityAI = require("personalityai");
const personalityAI = new PersonalityAI();
// Example usage
(async () => {
try {
const testResult = await personalityAI.test();
console.log('Test Result:', testResult);
let prompt = 'Hi what is your name?';
let character = 'Satoru Gojo';
let source = 'Jujutsu Kaisen';
const Profile = await personalityAI.profile(character, source);
console.log('Profile Result:', Profile);
const chatResult = await personalityAI.chat(prompt, character, source);
console.log('Chat Result:', chatResult);
} catch (error) {
console.error(error.message);
}
})();
Test Result: The API is working!
Profile Result: {
character: 'Satoru Gojo',
source: 'Jujutsu Kaisen',
image: 'https://staticg.sportskeeda.com/editor/2023/04/8487c-16812291196707.png',
introduction: "Yo, I'm Satoru Gojo, the strongest Jujutsu Sorcerer. Remember that name, cause it's the only one you need to know."
}
Chat Result: The name's Satoru Gojo, the strongest Jujutsu sorcerer. Remember it well.
Usage of all the api endpoints.
const PersonalityAI = require('personalityai');
// Create an instance of PersonalityAI
const personalityAI = new PersonalityAI();
// Test the API
try {
const testResult = await personalityAI.test();
console.log(testResult);
} catch (error) {
console.error(error.message);
}
// Start a chat session
const prompt = "How are you today?";
const character = "Walter White";
const source = "Breaking bad";
try {
const chatResult = await personalityAI.chat(prompt, character, source);
console.log(chatResult);
} catch (error) {
console.error(error.message);
}
// Create a new profile
const profileCharacter = "Jane Smith";
try {
const profileResult = await personalityAI.profile(profileCharacter, source);
console.log(profileResult);
} catch (error) {
console.error(error.message);
}
// Fetch images
const imageSource = "web";
const imageNumber = 3;
const imageOptions = { type: "animated" };
try {
const imageResult = await personalityAI.images(imageSource, imageNumber, imageOptions);
console.log(imageResult);
} catch (error) {
console.error(error.message);
}
// Get conversation history
const conversationId = "123456";
try {
const conversationResult = await personalityAI.conversations(conversationId);
console.log(conversationResult);
} catch (error) {
console.error(error.message);
}
-
apiBaseUrl
(optional): The base URL of the PersonalityAI API. Defaults to 'https://personalityai.onrender.com'. -
chatOptions
(optional): Advanced options for chat sessions.
Tests the PersonalityAI API by making a GET request to /test
.
Starts a chat session with the specified prompt, character, and source. If advanced options are provided during initialization, they will be included in the request.
Creates a new profile for the specified character and source.
Fetches a specified number of images from the given source. Options can be provided for more specific image requirements.
Retrieves the conversation history for the specified ID.
All methods throw an Error
object if the API request fails, providing detailed error messages.
Make sure to handle asynchronous operations appropriately, using try
and catch
blocks or .then()
and .catch()
as per your preference.
This package is licensed under the MIT License. See the LICENSE file for details.