PythonSDK
Rivalz Python SDK for developers
https://pypi.org/project/rivalz-client/0.2.2/
from mimetypes import knownfiles
Rivalz Python Client
rivalz-client
is a Python client designed for interacting with the Rivalz API. It enables developers to upload, download, and manage files on the Rivalz platform using IPFS (InterPlanetary File System).
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
You can install the rivalz-client package via pip using the following command:
Usage
This guide provides detailed instructions on how to use the rivalz-client to interact with the Rivalz API.
Initialization
First, import the RivalzClient
class and initialize it with your secret token. If you don’t provide a token, it will use a default example token.
1. Uploading a File
To upload a file to the Rivalz, you can use the upload_file
method. Simply provide the path to the file you want to upload as an argument
2. Uploading a Passport Image
To upload a passport image, use the upload_passport
method. Provide the path to the passport image file.
3. Downloading a File
To download a file, use the download_file
method with the IPFS hash of the file and the directory where you want to save the file.
4. Deleting a File
To delete a file, use the delete_file
method with the IPFS hash of the file you want to delete.
5. 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 create_rag_knowledge_base
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 add_document_to_knowledge_base
method. This method requires the knowledge base ID (from the knowledge base you’ve already created) and the file path of the new document.
Deleting documents from an existing knowledge base
To delete a document from an existing knowledge base, use the delete_document_from_knowledge_base
method with the knowledge base id and the document name.
Getting all knowledge bases
To get all knowledge bases, use the get_knowledge_bases
method.
Getting details of a knowledge base
To get details of a knowledge base, use the get_knowledge_base
method with the knowledge base id.
6. Conversations
Creating a conversation
To initiate a conversation in the RAG (Retrieval Augmented Generation) system, use the create_chat_session
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 create_chat_session
with the chat session id and the message.
Getting all conversations
To get all conversations, use the get_chat_sessions
method.
Getting details of a conversation
To get details of a conversation (which contains chat history for this conversation), use the get_chat_session
method with the chat session id.
Get uploaded documents
To get all uploaded documents, use the get_uploaded_documents
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