conva-ai
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

Conva AI Typescript Library

This library enables interaction with Conva AI Co-pilots

Installation

npm install conva-ai

Usage

Initializing the Client

To use the Conva AI library, you first need to initialize the ConvaAI client with your credentials:

import ConvaAI from 'conva-ai';

const client = new ConvaAI({
    assistantID:"<YOUR_ASSISTANT_ID>",
    assistantVersion:"<YOUR_ASSISTANT_VERSION>",
    apiKey:"<YOUR_API_KEY>"});

Basic Response Generation

To generate a response from Conva AI, use the invokeCapability method:

client.invokeCapability({
    query: 'What is the weather like today?',
    stream: false
  }).then(response => {
    console.log('ConvaAI Response:', response); 
    // TODO: Add application logic here
  }).catch(error => {
    console.error('Error:', error);
  });

This will send your query to Conva AI and return a response. The stream=False parameter indicates that you want to receive the full response at once.

Invoking Specific Capabilities

If you want to use a particular capability of Conva AI, you can specify it using the invokeCapabilityName method:

let conversationHistory: string | undefined = "{}";

client.invokeCapabilityName({
    query: 'Can you tell me about yourself?',
    history: conversationHistory,
    capabilityName: 'small_talk',
    stream: false
  }).then(response => {
    console.log('ConvaAI Response:', response);  
    //TODO: Add application logic here
  }).catch(error => {
    console.error('Error:', error);
  });

In this example, we're specifically invoking the "small_talk" capability of Conva AI.

Maintaining Conversation History

To have a continuous conversation with Conva AI, you can keep track of the conversation history:

let conversationHistory = JSON.stringify({});

client.invokeCapability({
  query: 'What all products do you sell?',
  stream: false,
  history: conversationHistory
}).then(response => {
  if (response && 'conversationHistory' in response) {
    conversationHistory = JSON.stringify(response.conversationHistory)
  }
  console.log('ConvaAI Response:', response);
  //TODO: Add application logic here
}).catch(error => {
  console.error('Error:', error);
});

You need to set history: conversationHistory to have an ongoing conversation with Conva AI, with each response considering the context of previous interactions.

The conversationHistory variable is initialized as an empty JSON string, which is used to track the conversation context. After receiving the response from invokeCapability, it updates conversationHistory with the new conversation history from the response.

Package Sidebar

Install

npm i conva-ai

Weekly Downloads

68

Version

0.0.12

License

MIT

Unpacked Size

22.6 kB

Total Files

20

Last publish

Collaborators

  • ashrita