Skip to main content

The Module

The module is a collection of functions that are reusable and can be added and removed by the developer.

import commune as c
# for jupyter notebook please use c.jupyter() as this will allow the notebook to display the output
c.jupyter()

The Module

The module is a collection of functions that are reusable and can be added and removed by the developer.

# This is the module
c.Module
c.module('module') # or c.m('module')

It has a bunch of lit functions that you can add and remove, to your liking.

storage = c.module('storage')
import commune as c
from typing import *
import streamlit as st
import json

class Storage(c.Module)

The module config

The module config is represented as a Munch object, which is a dictionary that can be accessed as an object. There are two ways to define the config.

  1. with a YAML file
a : 1
b : 2
c : 3

where the file is named {module}.yaml where {module}.py is the name of the module file.

  1. Without a YAML file
class Config:
def __init__(self, a=1, b=2, c=3):
...
storage.config()
storage.serve()
client = c.connect('storage')
k,v = 'test', 'hey'
client.put(k, v)
assert client.get(k) == v
c.serve('model.openai')
c.call('model.openai/generate', 'hey how is it going?')
model = {}
model['local'] = c.module('model.openai')()
model['remote'] = c.connect('model.openai')
model = c.munch(model)
response = {}
response['local'] = model.local.generate('what is 2+2?')
response['remote'] = model.local.generate('what is 2+2?')
response