common.py


Overview

The common.py file serves as a centralized client-side API utility module for interacting with multiple backend services of the InfiniFlow system. It provides a collection of Python functions that encapsulate HTTP requests targeting various RESTful endpoints related to knowledge bases (KB), documents, chunks, and dialogs.

Each group of functions corresponds to one of the core applications or services within the system:

This modular approach abstracts the low-level API calls, streamlining integration and testing for clients by providing reusable functions with consistent request patterns and error handling (via response JSON parsing).


Detailed Descriptions


Constants and Imports


KB APP Functions

These functions interact with the Knowledge Base (KB) backend service.


create_kb(auth, payload=None, *, headers=HEADERS, data=None)


list_kbs(auth, params=None, payload=None, *, headers=HEADERS, data=None)


update_kb(auth, payload=None, *, headers=HEADERS, data=None)


rm_kb(auth, payload=None, *, headers=HEADERS, data=None)


detail_kb(auth, params=None, *, headers=HEADERS)


Tag and Knowledge Graph Management Functions


batch_create_datasets(auth, num)


DOCUMENT APP Functions


upload_documents(auth, payload=None, files_path=None)


Other document-related functions:


CHUNK APP Functions

These are for managing document chunks (text fragments).


DIALOG APP Functions

Functions related to dialog session management.


Important Implementation Details


Interaction with Other System Components


Visual Diagram

The following flowchart illustrates the main functions grouped by application area and their relationships (e.g., batch functions call individual create/add functions):

flowchart TD
    subgraph KB_App [KB App]
        create_kb
        list_kbs
        update_kb
        rm_kb
        detail_kb
        list_tags_from_kbs
        list_tags
        rm_tags
        rename_tags
        knowledge_graph
        delete_knowledge_graph
        batch_create_datasets --> create_kb
    end

    subgraph Document_App [Document App]
        upload_documents
        create_document
        list_documents
        delete_document
        parse_documents
        bulk_upload_documents --> upload_documents
    end

    subgraph Chunk_App [Chunk App]
        add_chunk
        list_chunks
        get_chunk
        update_chunk
        delete_chunks
        retrieval_chunks
        batch_add_chunks --> add_chunk
    end

    subgraph Dialog_App [Dialog App]
        create_dialog
        update_dialog
        get_dialog
        list_dialogs
        delete_dialog
        batch_create_dialogs --> create_dialog
        delete_dialogs --> list_dialogs & delete_dialog
    end

Summary

common.py is a comprehensive API client layer that abstracts RESTful interactions with InfiniFlow backend services related to knowledge bases, documents, chunks, and dialogs. It provides synchronous, reusable Python functions encapsulating request logic, authentication, and response handling, thereby enabling efficient integration and automation workflows within the InfiniFlow ecosystem.