common.py


Overview

common.py is a utility module designed to facilitate interaction with a remote knowledge base and document management service exposed via a RESTful API. The file provides a set of functions to manage datasets (knowledge bases) and documents on a specified host server, abstracting the HTTP request details and simplifying common operations such as creating, listing, updating, and removing datasets, as well as uploading and parsing documents.

The module is primarily intended for use in applications that need to programmatically manage knowledge bases and their associated documents, enabling integration with the backend service without requiring the user to handle raw HTTP requests.


Constants


Functions

1. create_dataset(auth: str, dataset_name: str) -> dict

Creates a new dataset (knowledge base) on the remote server.


2. list_dataset(auth: str, page_number: int, page_size: int = 30) -> dict

Retrieves a paginated list of datasets available on the server.


3. rm_dataset(auth: str, dataset_id: str) -> dict

Removes (deletes) a dataset specified by its identifier.


4. update_dataset(auth: str, json_req: dict) -> dict

Updates dataset information based on the provided JSON request payload.


5. upload_file(auth: str, dataset_id: str, path: str) -> dict

Uploads a file associated with a dataset.


6. list_document(auth: str, dataset_id: str) -> dict

Lists all documents associated with a given dataset.


7. get_docs_info(auth: str, doc_ids: list) -> dict

Fetches detailed information about a list of document IDs.


8. parse_docs(auth: str, doc_ids: list) -> dict

Triggers parsing and processing of specified documents on the server.


9. parse_file(auth: str, document_id: str)


Implementation Details


Interaction with Other Parts of the System


Diagram: Flowchart of Functions and Their Relationships

flowchart TD
    A[Start] --> B[create_dataset]
    A --> C[list_dataset]
    A --> D[rm_dataset]
    A --> E[update_dataset]
    A --> F[upload_file]
    A --> G[list_document]
    A --> H[get_docs_info]
    A --> I[parse_docs]
    A --> J[parse_file (unimplemented)]
    
    F --> G
    G --> H
    H --> I

Diagram Explanation:


Summary

The common.py file is a concise and focused utility module for managing knowledge bases and documents via a REST API. Its simple function-based interface abstracts HTTP details, enabling easy integration into larger systems that require knowledge base operations or document processing workflows. To maximize robustness, future enhancements could include error handling, input validation, and implementing currently stubbed functions like parse_file.