Skip to content

Commit

Permalink
flock
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 22, 2024
1 parent a889f16 commit 6c5631d
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 121 deletions.
167 changes: 167 additions & 0 deletions commune/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# The PyParse CLI

We have a pythonic cli for commune, which is a wrapper around the `c.Module` library. This is a simple way to interact with the commune library. This does not need to be formated like argparse, and is more like a pythonic cli, where you can test out the functions and modules.


How the cli works

```bash
c {module_name}/{function_name} {kwargs}
```or
```bash
c {module_name} {function_name} {kwargs} {flags}
```

or if the module you are calling is the main module, you can use the following command:
```bash
c {function_name} {kwargs}
```

if you need help use the --help after the function


c model.openai/generate --help

For example, the following command:

```
c ls
```

is the same as

```python
import commune as c
c.ls()
```

To make a new module

```python
c.new_module("agi")
```
```
c new_module agi
```

This will create a new module called `agi` in the `modules` directory.
This will be located in

to get the config of the model.agi module, you can use the following command:

```bash
c agi/config
```
if you dont have a config or yaml file, the key word arguments will be used as the config.

This is the same as the following python code:
```python

import commune as c
c.module("agi").config()
```


To get the code
```bash
c agi/code
```

```python

import commune as c

class Agi(c.Module):
def __init__(self, a=1, b=2):
self.set_config(kwargs=locals())

def call(self, x:int = 1, y:int = 2) -> int:
c.print(self.config)
c.print(self.config, 'This is the config, it is a Munch object')
return x + y


```

to get the config, which is a yaml, or the key word arguments of the __init__
```bash
c agi/config
```










The template for the cli is as follows:
```bash
c model.openai/forward text="sup"
```
or
```bash

c {module_name}/
```

For example, the following command:


```python
import commune as c
c.modules("model")
```

is the same as

```bash
c modules model
```

## Using the cli to interact with your modules

You can use the cli to interact with your modules. For example, if you have a module called `demo`, you can use the cli to interact with it.

For instance, to get the config of the model.openai module, you can use the following command:

```bash
c model.openai config
```

This is the same as the following python code:

```python
import commune as c
c.module("model.openai").config()
```


## Serving

You can also serve your modules using the cli. For example, if you have a module called `demo`, you can serve it using the following command:

```bash
c demo serve tag=latest
```

This is the same as the following python code:

```python
import commune as c
c.module("demo").serve(tag="latest")
```






## Why did we make this instead of using Argparse?
Argparse is a great library, but it is not very pythonic, and it is not very easy to use. You also have to write a lot of boilerplate code to get it to work, which is not very fun.

Our New Pyparse It is a simple way to interact with the commune library. This does not need to be formated like argparse, and is more like a pythonic cli, where you can test out the functions and modules.


7 changes: 5 additions & 2 deletions commune/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def forward(self,
kwargs.update(extra_kwargs)
timestamp = c.time()
request = self.prepare_request(args=args, kwargs=kwargs, params=params, message_type=message_type)
result = asyncio.run(self.send_request(url=url, request=request, headers=headers, timeout=timeout, verbose=verbose, stream=stream))
future = asyncio.wait_for(self.send_request(url=url, request=request, headers=headers, verbose=verbose, stream=stream), timeout=timeout)
result = asyncio.run(future)

if type(result) in [str, dict, int, float, list, tuple]:
result = self.serializer.deserialize(result)
Expand Down Expand Up @@ -278,6 +279,7 @@ def call(cls, module : str,
network:str = 'local',
key:str = None,
stream = False,
timeout=40,
**extra_kwargs) -> None:

if '//' in module:
Expand All @@ -293,14 +295,15 @@ def call(cls, module : str,
prefix_match=prefix_match,
virtual=False,
key=key)

# if isinstance(kwargs, str):
# kwargs = c.str2dict(kwargs)
if params != None:
kwargs = params
if kwargs == None:
kwargs = {}
kwargs.update(extra_kwargs)
return module.forward(fn=fn, args=args, kwargs=kwargs, stream=stream)
return module.forward(fn=fn, args=args, kwargs=kwargs, stream=stream, timeout=timeout)


@classmethod
Expand Down
7 changes: 5 additions & 2 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,12 +2358,15 @@ def empty_namespace(cls, *args, **kwargs):
def add_namespace(cls, *args, **kwargs):
return c.module("namespace").empty_namespace(*args, **kwargs)



@classmethod
def update_namespace(cls, network:str='local',**kwargs):
return c.module("namespace").update_namespace(network=network, **kwargs)


@classmethod
def build_namespace(cls, network:str='local',**kwargs):
return c.module("namespace").update_namespace(network=network, **kwargs)

@classmethod
def update_subnet(cls, *args, **kwargs):
return c.module("subspace")().update_subnet(*args, **kwargs)
Expand Down
2 changes: 0 additions & 2 deletions commune/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def build_namespace(cls,

return namespace

update_namespace = build_namespace

@classmethod
def migrate_namespace(cls, network:str='local'):
Expand Down Expand Up @@ -424,7 +423,6 @@ def build_namespace(cls,

return namespace

update_namespace = build_namespace

@classmethod
def server_exists(cls, name:str, network:str = None, prefix_match:bool=False, **kwargs) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions commune/subspace/chain/node-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

NODE_DATA_DIR="${NODE_DATA_DIR:-/subspace}"
BOOTNODES="$(< "$NODE_DATA_DIR/bootnodes.txt" xargs echo)"
# # shellcheck disable=SC2086
# node-subspace \
# --base-path "$NODE_DATA_DIR" --chain "$NODE_DATA_DIR/specs/main.json" \
# --rpc-external --rpc-cors=all --port 30333 --rpc-port 9944 \
# --telemetry-url 'ws://telemetry.communeai.net:8001/submit 0' \
# --rpc-max-connections 2000 --bootnodes $BOOTNODES --blocks-pruning 1000 --state-pruning 1000 --sync warp "$@"
# shellcheck disable=SC2086
node-subspace \
--base-path "$NODE_DATA_DIR" --chain "$NODE_DATA_DIR/specs/main.json" \
--rpc-external --rpc-cors=all --port 30333 --rpc-port 9944 \
--telemetry-url 'ws://telemetry.communeai.net:8001/submit 0' \
--rpc-max-connections 2000 --bootnodes $BOOTNODES --blocks-pruning 1000 --state-pruning 1000 --sync warp "$@"

tail -f /dev/null
Loading

0 comments on commit 6c5631d

Please sign in to comment.