From 4a21591e0f2db17854755ff3f8d7bf483dd5cf03 Mon Sep 17 00:00:00 2001 From: latentvector Date: Fri, 6 Sep 2024 14:45:51 -0400 Subject: [PATCH] readme --- README.md | 197 ++++++++++++++++------------------------------ commune/README.md | 149 +++++++++++++++++++++++++++++++++++ commune/module.py | 17 +++- 3 files changed, 234 insertions(+), 129 deletions(-) create mode 100644 commune/README.md diff --git a/README.md b/README.md index 3fbb302a..233b417d 100644 --- a/README.md +++ b/README.md @@ -12,97 +12,50 @@ PLEASE REFER TO THE DOCS FOLDER FOR MORE INFO [DOCS](./commune/docs) -### An Open Anything Network: Connect Anything You Want +Introduction to Commune +Commune is an open-source project that aims to create a network for connecting various developer tools. It's designed to be flexible and unopinionated, allowing developers to use it alongside their existing projects. - +Key Features: +- Module Filesystem +- Subspace blockchain integration +- Flexible key management +- Pythonic CLI -Commune is a protocol that aims to connect all developer tools into one network, fostering a more shareable, reusable, and open economy. It follows an inclusive design philosophy that is based on being maximally unopinionated. This means that developers can leverage Commune as a versatile set of tools alongside their existing projects and have the freedom to incorporate additional tools they find valuable. +To get started, you can install Commune either locally or using Docker. -By embracing an unopinionated approach, Commune acknowledges the diverse needs and preferences of developers. It provides a flexible framework that allows developers to integrate specific tools seamlessly while avoiding imposing rigid structures or constraints. This adaptability enables developers to leverage Commune's capabilities in a manner that best aligns with their individual projects and workflows. - -The overarching goal of Commune is to create a collaborative ecosystem where developers can easily share, connect, and extend their tools, ultimately fostering innovation and efficiency within the development community. By providing a network that encourages openness and accessibility, Commune empowers developers to leverage the collective knowledge and resources of the community to enhance their own projects. - -# Install - -You can install commune locally or run in docker. Commune is a python package and can be built from source for maximal control. We want you to define what you want to do with your code, and commune is here to help you do that. - - - -### Setting Up Commune With Docker - -Install Docker: If you don't have Docker installed on your system, download and install it from the official Docker website: [https://www.docker.com/get-started](https://www.docker.com/get-started). - -Clone the Commune Repository: Open your terminal or command prompt and clone the Commune repository from GitHub: - - -Please cd into commune - -``` -cd commune -``` -Start Commune: Once the Docker container is built, start Commune by running the following command: - -```bash -make up -# or -docker-compose up -d # or make up -``` -To enter the docker container do, and do the following - -```bash -make enter -# or -docker exec -it commune bash -``` - -Then run the following command to sync the network - -```bash -c ls -``` - -### Local Setup (Without Docker) +Installation +Local Installation: ```bash apt-get install python3.10 python3-pip npm npm install -g pm2 pip install -r requirements.txt pip install -e . ``` -or -```bash -./start.sh -``` - -To exit the container +Docker Installation: ```bash -exit +git clone https://github.com/commune-ai/commune.git +cd commune +make build +make start +make enter ``` -Sync Commune with the Network: Inside the Docker container, run the following command to sync Commune with the network: - +After installation, sync with the network: ```bash -c sync +c ls ``` -Congratulations! Commune is now set up and running inside a Docker container. -Congratulations! Commune is now set up and running without Docker - -## Note: - -This repo is on the cutting edge of experimentation, so there may be some hiccups along the way. If you're primarily interested in using the core features of the protocol (such as intuitive cli) or seeking a more lightweight implementation, consider installing the [Communex](https://github.com/agicommies/communex) package. - -# Key Features +Page 3: Module Filesystem -## Module Filesystem - -The `module.py` file serves as an anchor, organizing future modules in what we call a module filesystem. The module filesystem is a mix of the commune's core modules with your local modules with respect to your PWD (parent working directory). This allows you to create a module in your local directory and have it be recognized by the commune. For instance if I have a file called `model.py` in my local directory, with the following code: +Commune organizes modules in a filesystem-like structure. You can create local modules that integrate seamlessly with Commune's core modules. +Example: ```python - import commune as c + class Example(c.Module): def __init__(self): pass @@ -111,96 +64,86 @@ class Example(c.Module): return x + 1 ``` -I can call it from the commune cli by running the following command: - +You can call this module using: ```bash c model/predict x=1 ``` -or -```python -c.call('model/predict', x=1) -``` - - -## Subspace - -![Example](https://drive.google.com/uc?export=view&id=1ZqCK-rBKF2p8KFr5DvuFcJaPXdMcISlT) -Subspace is a blockchain that Commune uses for several purposes: +Page 4: Subspace Integration -- **DNS for Python**: Decentralized Name Service for deployed objects. -- **Evaluating Performance through Voting**: Stake-weighted voting system for users to evaluate each other instead of self-reported networks. This provides users with +Commune uses the Subspace blockchain for: +- Decentralized Name Service (DNS) for deployed objects +- Stake-weighted voting system for performance evaluation -## Register On The Chain - -To register a module, do the following - -```python -c register {module_path} name={module_name (OPTIONAL)} +To register a module on the blockchain: +```bash +c register my_module_path name=my_module tag=1 ``` -The module path is specified +Page 5: Key Management -Yo, listen up! I'm about to drop some updated knowledge on how to create a dope module and register it on the blockchain. Here's the revised step-by-step guide: +Commune uses sr25519 keys for signing, encryption, and verification. -1. **Create Your Module**: Start by creating your own module in Python. It can be anything you want - a model, a service, or some sick functionality. Make sure your module is ready to rock and roll. - -2. **Import Commune**: Import the Commune library into your Python code. You'll need it to create and register your module. - -```python -import commune as c +To add a new key: +```bash +c add_key alice ``` -3. **Define Your Module Class**: Create a class that represents your module. Make sure it inherits from `c.Module`. +To list keys: +```bash +c keys +``` +To sign a message: ```python -class MyDopeModule(c.Module): - def __init__(self): - super().__init__() - # Your module initialization code goes here - - def some_cool_function(self): - # Your module's cool functionality goes here - return "I'm bringing the heat!" +key = c.get_key("alice") +signature = key.sign("hello world") ``` -4. **Register Your Module**: Now it's time to register your module on the blockchain. You have the option to specify a custom name and tag for your module. If you don't provide a custom name, the module will default to the module path. The tag is optional and can be used for versioning or categorization purposes. +Page 6: Pythonic CLI -To register your module with a custom name and tag, run the following command: +Commune provides a Pythonic CLI for easy interaction: ```bash -c register my_module_path name=my_module tag=1 +c {module_name}/{function_name} *args **kwargs ``` -Replace `my_module_path` with the actual path to your module file (without the class name), `my_module` with the desired name for your module, and `1` with the desired tag. This will register your module on the blockchain with the specified name and tag. - -If you prefer to use the default module path as the name, simply omit the `name` parameter: - +Example: ```bash -c register my_module_path tag=1 +c ls ./ ``` -# Developement FAQ +This is equivalent to: +```python +import commune as c +c.ls('./') +``` -- Where can i find futher documentation? This repository folder, [Doc](https://github.com/commune-ai/commune/tree/main/docs). -- Can I install on Windows? Yes, [Guide](https://github.com/OmnipotentLabs/communeaisetup). -- Can I contribute? Absolutely! We are open to all contributions. Please feel free to submit a pull request. +Page 7: Serving Modules +To serve a module: +```bash +c serve model.openai::tag +``` -## Testing +To call a served module: +```python +c.call("model.openai::tag/forward", "sup") +``` -To run the commune tests, do the following +Page 8: Testing +To run tests: ```bash -pytest commune/tests # or c test or make tests -``` - -The test is only one file, but it calls the test function for the core modules. This is because commune is a network of modules, and the core modules are the most important. - +pytest commune/tests +``` -## License :: MIT, but really IDGAF (I Don't Give A F*ck, its open source, why do we need a ) +Page 9: Contributing -This project is licensed under both MIT but primarely under its own liscense (IDGAF). Do what you want with the code, dont pull up on me with some legal shit for building fam. +Contributions to Commune are welcome. Please submit pull requests on the GitHub repository. +Page 10: License +Commune is licensed under MIT, but with a "Do What You Want" philosophy. The project encourages open-source usage without strict legal restrictions. +This documentation provides a high-level overview of Commune. For more detailed information on specific features, please refer to the individual module documentation or the project's GitHub repository. \ No newline at end of file diff --git a/commune/README.md b/commune/README.md new file mode 100644 index 00000000..233b417d --- /dev/null +++ b/commune/README.md @@ -0,0 +1,149 @@ +
+ +# **Commune AI** + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Discord Chat](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.com/invite/DgjvQXvhqf) +[![Website Uptime](https://img.shields.io/website-up-down-green-red/http/monip.org.svg)](https://www.communeai.org/) +[![Twitter Follow](https://img.shields.io/twitter/follow/communeaidotorg.svg?style=social&label=Follow)](https://twitter.com/communeaidotorg) + +![Alt text](image.png) +PLEASE REFER TO THE DOCS FOLDER FOR MORE INFO + +[DOCS](./commune/docs) + +Introduction to Commune + +Commune is an open-source project that aims to create a network for connecting various developer tools. It's designed to be flexible and unopinionated, allowing developers to use it alongside their existing projects. + +Key Features: +- Module Filesystem +- Subspace blockchain integration +- Flexible key management +- Pythonic CLI + +To get started, you can install Commune either locally or using Docker. + +Installation + +Local Installation: +```bash +apt-get install python3.10 python3-pip npm +npm install -g pm2 +pip install -r requirements.txt +pip install -e . +``` + +Docker Installation: +```bash +git clone https://github.com/commune-ai/commune.git +cd commune +make build +make start +make enter +``` + +After installation, sync with the network: +```bash +c ls +``` + +Page 3: Module Filesystem + +Commune organizes modules in a filesystem-like structure. You can create local modules that integrate seamlessly with Commune's core modules. + +Example: +```python +import commune as c + +class Example(c.Module): + def __init__(self): + pass + + def predict(self, x): + return x + 1 +``` + +You can call this module using: +```bash +c model/predict x=1 +``` + +Page 4: Subspace Integration + +Commune uses the Subspace blockchain for: +- Decentralized Name Service (DNS) for deployed objects +- Stake-weighted voting system for performance evaluation + +To register a module on the blockchain: +```bash +c register my_module_path name=my_module tag=1 +``` + +Page 5: Key Management + +Commune uses sr25519 keys for signing, encryption, and verification. + +To add a new key: +```bash +c add_key alice +``` + +To list keys: +```bash +c keys +``` + +To sign a message: +```python +key = c.get_key("alice") +signature = key.sign("hello world") +``` + +Page 6: Pythonic CLI + +Commune provides a Pythonic CLI for easy interaction: + +```bash +c {module_name}/{function_name} *args **kwargs +``` + +Example: +```bash +c ls ./ +``` + +This is equivalent to: +```python +import commune as c +c.ls('./') +``` + +Page 7: Serving Modules + +To serve a module: +```bash +c serve model.openai::tag +``` + +To call a served module: +```python +c.call("model.openai::tag/forward", "sup") +``` + +Page 8: Testing + +To run tests: +```bash +pytest commune/tests +``` + +Page 9: Contributing + +Contributions to Commune are welcome. Please submit pull requests on the GitHub repository. + +Page 10: License + +Commune is licensed under MIT, but with a "Do What You Want" philosophy. The project encourages open-source usage without strict legal restrictions. + +This documentation provides a high-level overview of Commune. For more detailed information on specific features, please refer to the individual module documentation or the project's GitHub repository. \ No newline at end of file diff --git a/commune/module.py b/commune/module.py index 892ecbaf..ef1f9a90 100755 --- a/commune/module.py +++ b/commune/module.py @@ -1814,17 +1814,26 @@ def jsonable( value): except: return False - def file2text(self, path = './', relative=True, **kwargs): + def file2text(self, path = './', + avoid_folders = ['__pycache__', + '.git', + '.ipynb_checkpoints', + 'package.lock', + 'node_modules'], + relative=True, **kwargs): path = os.path.abspath(path) file2text = {} for file in c.glob(path, recursive=True): + if os.path.isdir(file): + continue + if any([folder in file for folder in avoid_folders]): + continue with open(file, 'r') as f: content = f.read() file2text[file] = content if relative: print(path) return {k[len(path)+1:]:v for k,v in file2text.items()} - return file2text def file2lines(self, path:str='./')-> List[str]: @@ -4095,6 +4104,10 @@ def executor(cls, max_workers:int=None, mode:str="thread", maxsize=200, **kwargs @classmethod def obj2typestr(cls, obj): return str(type(obj)).split("'")[1] + + def explain_myself(self): + context = c.file2text(self.root_path) + return c.ask(f'{context} write full multipage docuemntation aobut this, be as simple as possible with examples \n')