NodejsSDK
Last updated
Last updated
This is a TypeScript library that provides functionalities for Rivazl AI
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.
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:
Encryption Key: Used for encrypting files to ensure data security.
Secret Key: Required for authenticating API requests to access Rivalz services.
Import and use the RivalzClient class in your TypeScript/JavaScript code:
file: A readable stream of the file to be uploaded.
Returns a promise that resolves to the IPFS hash of the uploaded file.
file: A readable stream of the file to be uploaded.
Returns a promise that resolves to the IPFS hash of the uploaded file.
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.
ipfsHash: The IPFS hash of the file to be downloaded.
Returns a promise that resolves to a buffer containing the downloaded file.
ipfsHash: The IPFS hash of the file to be deleted.
Returns a promise that resolves to the IPFS hash of the deleted file.
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.
Prerequisites
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.
To add a document to an existing knowledge base, use the addDocumentToKnowledgeBase
method with the knowledge base id and the path to the document.
To delete a document from an existing knowledge base, use the deleteDocumentFromKnowledgeBase
method with the knowledge base id and the document name.
To get all knowledge bases, use the getKnowledgeBases
method.
To get details of a knowledge base, use the getKnowledgeBase
method with the knowledge base id.
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.
To add a message to a conversation, use the same method createChatSession
with the chat session id and the message.
To get all conversations, use the getChatSessions
method.
To get details of a conversation (which contains chat history for this conversation), use the getChatSession
method with the chat session id.
To get all uploaded documents, use the getUploadedDocuments
method.
Here is a complete example demonstrating how to use the rivalz-client
to create a simple RAG conversation based on a PDF document:
After installing the package, proceed to the to generate your encryption key and secret key:
Before using the RAG API, you need api key and some rivalz credits. Claim for free now