contenteaseai-npm

1.0.1 • Public • Published

ContentEaseAI npm Library Documentation


Introduction

ContentEaseAI is an advanced content generation and manipulation library, powered by cutting-edge AI. Whether you're looking to summarize large volumes of text, initiate AI-based conversations, or perform context-aware interactions, ContentEaseAI is tailored to meet diverse content needs with ease and precision.


Installation

To get started, install the library via npm:

npm install contenteaseai-npm --save

Initialization

Once installed, initialize the library by importing it and providing your unique API key:

const ContentEaseAI = require('contenteaseai-npm');
const ce = new ContentEaseAI('YOUR_UNIQUE_API_KEY');

Available Methods

1. Summarize

Distill lengthy text content into concise summaries.

Parameters:

  • text (String): The text content you want to condense.
  • input_language (Optional, Default 'auto'): Specify the language of the input text or use 'auto' for the library to automatically detect it.
  • output_language (Optional, Default 'en'): Determine the language of the summarized output.

Usage:

const options = {
    text: "The Renaissance was a fervent period of European cultural, artistic, political, and economic “rebirth” following the Middle Ages. Generally described as taking place from the 14th century to the 17th century...",
    input_language: 'en',
    output_language: 'fr'
};

ce.summarize(options).then(response => console.log(response.summary));

Errors:

  • Language Detection Failed: Automatic language detection for the input text was unsuccessful.
  • Translation Failed: An issue occurred during the translation process.

2. Start Conversation With Summary

Initiate an AI-driven conversation based on a summarized context. This method not only provides a summary but also gives you a conversation_id, allowing you to continue the conversation based on that summary.

Parameters:

  • text (String): The text content you want to generate a conversation from.
  • input_language (Optional, Default 'auto'): Specify the language of the input text or use 'auto' for automatic language detection.
  • output_language (Optional): Determine the language of the summarized output. If not specified, it reverts to the input_language.

Usage:

const startConversationWithSummaryOptions = {
    text: "AI and machine learning are transforming various industries by providing data-driven insights.",
    input_language: 'auto',
    output_language: 'en'
};

ce.startConversationWithSummary(startConversationWithSummaryOptions)
    .then(response => {
        console.log('Start Conversation With Summary Response:', response);
        // Follow-up queries or other operations can be made using the response data.
    })
    .catch(error => {
        console.error(`Error with startConversationWithSummary: ${error}`);
    });

Returns:

  • conversation_id (String): The unique identifier for this conversation which can be used for continuation.
  • summary (String): The summarized version of the input text.

Errors:

  • Redis connection failed: Indicates an issue with the Redis connection.
  • Language detection failed: The system couldn't auto-detect the language of the provided text.
  • Translation failed: An issue occurred during the translation of the text.

3. Continue Conversation With Summary

Continue an AI-driven conversation that was initiated using the startConversationWithSummary method. This method lets you build upon the summarized context by providing subsequent queries to the conversation using the provided conversation_id.

Parameters:

  • conversation_id (String): The unique identifier of the conversation obtained from the startConversationWithSummary method.
  • query (String): The follow-up query or statement you want the AI to respond to.
  • input_language (Optional, Default 'auto'): Specify the language of the input query or use 'auto' for automatic language detection.
  • output_language (Optional): Determine the language of the AI's response. If not specified, it reverts to the input_language.

Usage:

const continueConversationWithSummaryOptions = {
    conversation_id: 'YOUR_UNIQUE_CONVERSATION_ID_FROM_PREVIOUS_METHOD',
    query: "What industries are most affected?",
    input_language: 'auto',
    output_language: 'en'
};

ce.continueConversationWithSummary(continueConversationWithSummaryOptions)
    .then(response => {
        console.log('Continue Conversation With Summary Response:', response);
    })
    .catch(error => {
        console.error(`Error with continueConversationWithSummary: ${error}`);
    });

Returns:

  • conversation_id (String): The unique identifier for this conversation, consistent with the provided ID.
  • response (String): The AI's response to the provided query based on the summarized context.

Errors:

  • No entity memory found for conversation ID: Indicates a missing entity memory associated with the provided conversation_id.
  • No summary found for conversation ID: The system couldn't retrieve the summary for the given conversation_id.
  • Language detection failed: The system couldn't auto-detect the language of the provided query.
  • Translation failed: An issue occurred during the translation of the query or response.

4. Start Conversation With Context

Initiate a new AI-driven conversation while providing an additional context to guide the AI's responses. The context helps ensure that the AI's responses align better with the specific nuances or details that the user desires.

Parameters:

  • query (String): The initial query or statement you want the AI to respond to.
  • context (String): An additional piece of information or context you want the AI to consider when formulating its response.
  • input_language (Optional, Default 'auto'): Specify the language of the input query or use 'auto' for automatic language detection.
  • output_language (Optional, Default 'en'): Determine the language of the AI's response. If not specified, it defaults to the English language.

Usage:

const startConversationWithContextOptions = {
    query: "Tell me about renewable energy.",
    context: "Focus on solar energy and its benefits.",
    input_language: 'auto',
    output_language: 'en'
};

ce.startConversationWithContext(startConversationWithContextOptions)
    .then(response => {
        console.log('Start Conversation With Context Response:', response);
    })
    .catch(error => {
        console.error(`Error with startConversationWithContext: ${error}`);
    });

Returns:

  • conversation_id (String): A unique identifier for the conversation that can be used in subsequent API calls.
  • response (String): The AI's response to the provided query, taking the given context into account.

Errors:

  • Redis connection failed: Indicates an unsuccessful connection to the Redis database.
  • Language detection failed: The system couldn't auto-detect the language of the provided query.
  • Translation failed: An issue occurred during the translation of the query or response.

5. Continue Conversation With Context

Continue an existing AI-driven conversation by providing a subsequent query. This method allows the continuation of a previously initiated conversation, leveraging any context that was set.

Parameters:

  • conversation_id (UUID): The unique identifier of the conversation you want to continue.
  • query (String): The follow-up query or statement you want the AI to respond to.
  • input_language (Optional, Default 'auto'): Specify the language of the follow-up query or use 'auto' for automatic language detection.
  • output_language (Optional, Default 'en'): Determine the language of the AI's response. If not specified, it defaults to the English language.

Usage:

const continueConversationWithContextOptions = {
    conversation_id: "example-uuid-of-previous-conversation",
    query: "How is it beneficial?",
    input_language: 'auto',
    output_language: 'en'
};

ce.continueConversationWithContext(continueConversationWithContextOptions)
    .then(response => {
        console.log('Continue Conversation With Context Response:', response);
    })
    .catch(error => {
        console.error(`Error with continueConversationWithContext: ${error}`);
    });

Returns:

  • conversation_id (UUID): A unique identifier for the conversation, the same ID as was used to initiate the conversation.
  • response (String): The AI's response to the provided query, considering any previous context and responses.

Errors:

  • No entity memory found for conversation ID {conversation_id}: Indicates that the conversation's entity memory couldn't be retrieved from the Redis store.
  • Language detection failed: The system couldn't auto-detect the language of the provided query.

6. Start Conversation

Initiates a new conversation with the AI-driven bot. This method sets the foundation of the conversation without any added context or memory.

Parameters:

  • query (String): The initial question or statement you want the AI to respond to.
  • input_language (Optional, Default 'auto'): Specify the language of the initial query or use 'auto' for automatic language detection.
  • output_language (Optional, Default 'en'): Determine the language of the AI's response. If not specified, it defaults to the English language.

Usage:

const startConversationOptions = {
    query: "Tell me more about AI?",
    input_language: 'auto',
    output_language: 'en'
};

ce.startConversation(startConversationOptions)
    .then(response => {
        console.log('Start Conversation Response:', response);
    })
    .catch(error => {
        console.error(`Error with startConversation: ${error}`);
    });

Returns:

  • conversation_id (UUID): A unique identifier for the new conversation.
  • response (String): The AI's response to the provided initial query.

Errors:

  • Redis connection failed: Indicates that a connection couldn't be established with the Redis store.
  • Language detection failed: The system couldn't auto-detect the language of the provided query.
  • Translation failed: The system couldn't translate the query to or response from English.

7. Continue Conversation

This method allows you to carry on with an existing conversation using the same conversation_id. The AI bot will use the previously provided context to give more contextually relevant responses.

Parameters:

  • conversation_id (UUID): The unique identifier of the conversation you want to continue.
  • query (String): The new question or statement you want the AI to respond to.
  • input_language (Optional, Default 'auto'): Specify the language of the query or use 'auto' for automatic language detection.
  • output_language (Optional, Default 'en'): Determine the language of the AI's response. If not specified, it defaults to the English language.

Usage:

const continueConversationOptions = {
    conversation_id: "unique-conversation-id",
    query: "Tell me more about neural networks?",
    input_language: 'auto',
    output_language: 'en'
};

ce.continueConversation(continueConversationOptions)
    .then(response => {
        console.log('Continue Conversation Response:', response);
    })
    .catch(error => {
        console.error(`Error with continueConversation: ${error}`);
    });

Returns:

  • conversation_id (UUID): The unique identifier of the continued conversation.
  • response (String): The AI's response to the provided query.

Errors:

  • No entity memory found for conversation ID: Indicates that the specified conversation ID does not exist in the Redis store.
  • Language detection failed: The system couldn't auto-detect the language of the provided query.
  • Translation failed: The system couldn't translate the query to or response from English.

8. Get Supported Languages

This method allows you to retrieve a list of languages that are supported by the platform. This is useful for understanding which languages the platform can detect and translate to/from.

Usage:

ce.getSupportedLanguages()
    .then(languages => {
        console.log('Supported Languages:', languages);
    })
    .catch(error => {
        console.error(`Error fetching supported languages: ${error}`);
    });

Returns:

  • A list of supported languages in JSON format. Each language will typically have:
    • code: The ISO language code.
    • name: The readable name of the language.

For instance:

{
    "en": "English",
    "es": "Spanish",
    "fr": "French",
    ...
}

Errors:

  • Error fetching supported languages: Indicates an issue occurred while trying to read the supported languages from the system.

Errors and Exception Handling

In the event of an exception, the library returns descriptive error messages to assist in troubleshooting:

  • Language Detection Failed: Indicates an inability to ascertain the language of the provided text. Ensure the text is in a supported language or explicitly state the language using the input_language parameter.
  • Translation Failed: A hiccup occurred during the translation. Check the text and ensure the target language is supported.
  • Other HTTP Errors: These may arise due to various reasons like server downtimes, exceeded API limits, or network issues. It's advisable to have error-handling logic in place to deal with these gracefully.

Test Scripts

For a hands-on introduction and to aid in familiarizing yourself with the library's functionalities, a test.js script is bundled with the package. This script showcases practical examples of how each method can be utilized effectively.


Package Sidebar

Install

npm i contenteaseai-npm

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

22.8 kB

Total Files

4

Last publish

Collaborators

  • contenteaseai