NodejsSDK

Rivalz Nodejs SDK for developers

https://www.npmjs.com/package/rivalz-client

Rivalz client Node.js SDK

This is a TypeScript library that provides functionalities for Rivazl AI

Features

  • Upload Files: Upload any file to the Rivalz platform and get an IPFS hash.

  • Upload Passport Images: Upload passport images to the Rivalz platform.

  • Download Files: Download files from the Rivalz platform using an IPFS hash.v

  • Delete Files: Delete files from the Rivalz platform using an IPFS hash.

  • Vectorize Documents: Vectorize documents to create a RAG (Retrieval-Augmented Generation) based on the document uploaded.

  • Create conversations: Create conversations based on the document uploaded.

Installation

Before getting started, ensure that you have both Node.js and either npm or yarn installed. These are essential for managing the Rivalz client dependencies.

To install the Rivalz client, run one of the following commands:

Usage

  1. After installing the package, proceed to the Rivalz Dashboard to generate your encryption key and secret key:

  • Encryption Key: Used for encrypting files to ensure data security.

  • Secret Key: Required for authenticating API requests to access Rivalz services.

  1. Import and use the RivalzClient class in your TypeScript/JavaScript code:

API


1. Upload File

  • file: A readable stream of the file to be uploaded.

  • Returns a promise that resolves to the IPFS hash of the uploaded file.

2. Upload passport file

  • file: A readable stream of the file to be uploaded.

  • Returns a promise that resolves to the IPFS hash of the uploaded file.

3. Download File and save it to the local file system (Node.js only)

  • ipfsHash: The IPFS hash of the file to be downloaded.

  • savePath: The path where the downloaded file will be saved.

  • Returns a promise that resolves to the path of the saved file.

4. Download the File and return it as a buffer

  • ipfsHash: The IPFS hash of the file to be downloaded.

  • Returns a promise that resolves to a buffer containing the downloaded file.

5. Delete File

  • ipfsHash: The IPFS hash of the file to be deleted.

  • Returns a promise that resolves to the IPFS hash of the deleted file.

6. Get Uploaded History

  • page: The page number of the uploaded history.

  • size: The number of items per page.

  • Returns a promise that resolves to an array of uploaded files.

Please replace your-secret, file, passport, ipfsHash, and savePath with actual values when using the RivalzClient class.

7. RAG (Retrieval-Augmented Generation) API

Prerequisites

Before using the RAG API, you need api key and some rivalz credits. Claim for free now here

Creating a knowledge base from a document

To vectorize a document and create a knowledge base for Retrieval-Augmented Generation (RAG), use the createRagKnowledgeBase method, which takes the document's file path as input. This method generates a vectorized embedding of the document, assigns it a knowledge base ID, and stores it for future use in RAG-based conversations. Currently, this process supports only PDF files.

Click here to learn How to create a knowledge base

Adding documents to an existing knowledge base

To add a document to an existing knowledge base, use the addDocumentToKnowledgeBase method with the knowledge base id and the path to the document.

Deleting documents from an existing knowledge base

To delete a document from an existing knowledge base, use the deleteDocumentFromKnowledgeBase method with the knowledge base id and the document name.

Getting all knowledge bases

To get all knowledge bases, use the getKnowledgeBases method.

Getting details of a knowledge base

To get details of a knowledge base, use the getKnowledgeBase method with the knowledge base id.

8. Conversations

To initiate a conversation in the RAG (Retrieval Augmented Generation) system, use the createChatSession method. This method requires the knowledge base ID (from your existing knowledge base) and the question you want to ask. The AI will return a response based on the context provided by the knowledge base, along with a chat session ID to continue the conversation if needed.

Adding a message to a conversation

To add a message to a conversation, use the same method createChatSession with the chat session id and the message.

Getting all conversations

To get all conversations, use the getChatSessions method.

Getting details of a conversation

To get details of a conversation (which contains chat history for this conversation), use the getChatSession method with the chat session id.

Get uploaded documents

To get all uploaded documents, use the getUploadedDocuments method.

Examples

Here is a complete example demonstrating how to use the rivalz-client to create a simple RAG conversation based on a PDF document:

Last updated