CommuneAI Developer Documentation

website·Indexed 30 days ago

https://comdocs.netlify.app

Developer resources for CommuneAI, featuring guides on the PyParse CLI, module basics, and the Subspace module. Includes tutorials for deploying miners, registering validators, staking tokens, and managing keys, as well as technical specifications from the blackpaper regarding emissions, profit sharing, and the module filesystem.

Tokens
10.4K
Snippets
83
Records
104
Agent score
75%

What's inside CommuneAI

  1. Overview of Commune Consensus Protocols

    Commune is a modular chain supporting multiple consensus protocols to adapt to different use cases. The primary protocols include Linear, Yuma, and Yomama, with the ability to add more in the future.
  2. Overview of the CommuneAI Protocol

    Commune is an unopinionated protocol designed to connect developer tools into a single network to create a shareable and open economy. It provides a flexible framework that allows developers to integrate specific tools into their existing projects without imposing rigid structures or constraints, enabling the sharing and extension of tools across a collaborative ecosystem.
  3. Search for and retrieve module information

    You can search for specific modules using c.modules() and retrieve detailed information about a module using the info() method or by calling the module's info endpoint.
    # Search for a specific module
    c.modules('model.openai')
    
    # View module info via module object
    model_openai = c.module('model.openai')
    c.print(model_openai.info(*args, **kwargs))
    
    # View module info via direct call
    c.print(c.call('model.openai/info', *args, **kwargs))
  4. Understand the Commune module tree structure

    The module tree is used to locate all files containing a module within the commune folder. It maps a module's short-form name (the key) to the absolute file path of the module class (the value). This allows the system to resolve object imports to their corresponding source files globally.
    {
        "repo": "/Users/saltoshi/commune/modules/repo/repo.py",
        "tool.web": "/Users/saltoshi/commune/modules/tool/web/web.py",
        "miner.add": "/Users/saltoshi/commune/miner/add/add.py"
    }
  5. Understand Commune's AI and Blockchain architecture

    Commune scales AI and Blockchain by separating computation from the chain. The blockchain only tracks economic information related to AI activity. AI validation is performed off-chain, and only the final results are submitted to the blockchain to avoid overloading the chain with computation-heavy tasks.
  6. Understand the Access Module security flow

    The Access Module restricts access based on stake and permissions using the following logic:

    1. Verifies the address using the signature and data via the user's private key.
    2. Verifies the timestamp is not stale (must be within the last 2 seconds).
    3. Checks if the user is an admin (full access) or if the function is whitelisted and not blacklisted.
    4. For whitelisted functions, checks if the current request rate is below the user's max_rate (determined by total stake divided by the stake2rate variable).
  7. Organize modules using the Module Filesystem

    The module.py file acts as an anchor for the module filesystem. Modules are organized by their directory path relative to the project root. For example, a dataset module stored at {PWD}/dataset/text is referenced by the path dataset.text. Note that there is currently a limitation where the name of the configuration must match the name of the Python object.
  8. Define a Commune Module

    A Module in Commune is a Turing-complete entity that represents a collection of functions that change a state. While designed to mimic a Python class, it can be implemented in any language (e.g., Rust, JavaScript) using structs or classes. Each module is identified by an sr25519 public key used for blockchain registration, signing, and encryption.
    import commune as c
    
    class Model(c.Module):
        def __init__(self, c=0):
            self.c = c
        
        def add(self, a=1, b=1):
            return a + b + self.c
  9. Understand the Validator scoring and voting process

    The validator operates by randomly sampling modules within a network (subnet) and applying a score function to them.

    1. Scoring: The validator calls the score function for a sampled module. If the score is non-zero, the module's info and score are stored.
    2. Voting: A background thread periodically votes on the top 'n' modules with the highest scores. The frequency of these votes is determined by the vote_staleness parameter (the number of blocks between votes).
    3. Trust Ratio: The trust ratio is calculated as the trust score (number of modules that voted for a specific module) divided by the total stake.
  10. Enable trustless liquidity via Trustless Bridges

    Trustless bridges are used within the multichain ecosystem to allow the transfer of assets between chains without relying on trusted intermediaries. This architecture supports trustless liquidity provision and decentralized trading, allowing users to access diverse assets and liquidity pools across multiple chains securely and transparently.
  11. Understand Commune protocol and philosophy

    Commune is a censorship-resistant peer-to-peer protocol that uses crypto-economic incentives for the decentralized creation and access of machine intelligence and digital commodities. It follows a modular, OpenSource design philosophy focused on cooperation, sharing, and resource reusability. The project is community-driven, operating without a formal bureaucracy, foundation, or VC backing.
  12. Retrieve and manage existing keys

    The commune package provides functions to list, search, and retrieve detailed information about managed keys.
    # List all keys
    c.keys()
    # or
    c keys
    
    # Search for keys containing a specific term
    c keys ali
    
    # Get detailed info for a specific key
    c.key_info('fam')
    
    # Remove a key
    c.rm_key('demo')