Skip to content

Commit

Permalink
added docs agent additions
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Nov 7, 2024
1 parent d4984a0 commit d36eb6b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion commune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import *
import asyncio
import commune as c
import json
import requests
import commune as c

# from .pool import ClientPool

Expand Down
19 changes: 6 additions & 13 deletions commune/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@

class c:
splitters = [':', '/', '.']

endpoints = ['ask', 'generate', 'forward']

core_features = ['module_name', 'module_class', 'filepath', 'dirpath', 'tree']

# these are shortcuts for the module finder c.module('openai') --> c.module('modle.openai')
# if openai : model.openai
shortcuts = {
'openai' : 'model.openai',
'openrouter': 'model.openrouter',
Expand All @@ -33,7 +28,7 @@ class c:
'local': 'network',
'network.local': 'network',
}

lib_name = libname = lib = __file__.split('/')[-3]# the name of the library
organization = org = orgname = 'commune-ai' # the organization
git_host = 'https://github.com'
Expand All @@ -49,8 +44,6 @@ class c:
lib_path = libpath = os.path.dirname(root_path) # the path to the library
repo_path = repopath = os.path.dirname(root_path) # the path to the repo
modules_path = os.path.dirname(__file__) + '/modules'


cache = {} # cache for module objects
home = os.path.expanduser('~') # the home directory
__ss58_format__ = 42 # the ss58 format for the substrate address
Expand Down Expand Up @@ -500,7 +493,7 @@ def get_yaml( path:str=None, default={}, **kwargs) -> Dict:
with open(path, 'r') as file:
data = yaml.load(file, Loader=yaml.FullLoader)
return data

@classmethod
def get_routes(cls, cache=True):
if not hasattr(cls, 'routes'):
Expand Down Expand Up @@ -1410,7 +1403,6 @@ def get_fn(cls, fn:str, init_kwargs = None, splitters=splitters):
fn2route = cls.fn2route()
if fn in fn2route:
return c.obj(fn2route[fn])

# step 3, if the function is routed
return getattr(cls, fn)

Expand Down Expand Up @@ -1913,7 +1905,10 @@ def module(cls, path:str = 'module',
verbose = False,
tree = None,
trials=1, **_kwargs ) -> str:

if path == None:
path = 'module'
if path.endswith('.py'):
path = c.path2name(path)
og_path = path
path = path or 'module'
t0 = time.time()
Expand Down Expand Up @@ -2098,8 +2093,6 @@ def round(x, sig=6, small_value=1.0e-9):
"""
return round(x, sig - int(math.floor(math.log10(max(abs(x), abs(small_value))))) - 1)



@classmethod
def is_root_key(cls, address:str)-> str:
return address == cls.root_key().ss58_address
Expand Down
3 changes: 2 additions & 1 deletion commune/modules/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import commune as c

c.print(c.ask('what is the vibe'))
docs = c.file2text("./docs")
c.print(c.ask(f"whats is commune? {docs}"))
48 changes: 27 additions & 21 deletions commune/network/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ def unstake(
def update_module(
self,
name: str,
address: str = '0.0.0.0:8888',
address: str = None ,
metadata: str | None = None,
delegation_fee: int = 20,
netuid: int = 0,
Expand Down Expand Up @@ -1253,13 +1253,13 @@ def update_module(
key = self.resolve_key(key or name)
assert isinstance(delegation_fee, int)
netuid = self.resolve_netuid(subnet or netuid)

namespace = c.namespace()
address = namespace.get(name, address)
if public:
address = c.ip() +':'+ address.split(':')[-1]
else:
address = '0.0.0.0' +':'+ address.split(':')[-1]
if address==None:
namespace = c.namespace()
address = namespace.get(name, address)
if public:
address = c.ip() +':'+ address.split(':')[-1]
else:
address = '0.0.0.0' +':'+ address.split(':')[-1]
params = {
"netuid": netuid,
"name": name,
Expand All @@ -1282,7 +1282,6 @@ def register(
key: Keypair = None,
metadata: str | None = 'NA',
wait_for_finalization = True,
suffixes = ['miner', 'validator', 'vali'],
public = False,
) -> ExtrinsicReceipt:
"""
Expand All @@ -1299,21 +1298,22 @@ def register(


key = c.get_key(key)
address = self.resolve_module_address(name=name, address=address)
for suffix in suffixes:
if name.endswith(suffix):
subnet = name.split('.')[0]
break
subnet = self.resolve_subnet(netuid or subnet)
if public:
c.print('WARNING: Your Module is Publically Accessible')
else:
address = '0.0.0.0' +':'+ address.split(':')[-1]

if address == None:
namespace = c.namespace()
address = namespace.get(name, '0.0.0.0:8888')
if public:
ip = c.ip()
c.print(f'WARNING: Your Module is Publically Accessible ip:{ip}')
else:
address = '0.0.0.0' +':'+ address.split(':')[-1]
module_key_address = c.get_key(module_key or name, creaet_if_not_exists=True).ss58_address
params = {
"network_name": subnet,
"address": address,
"name": name,
"module_key":c.get_key(module_key or name, creaet_if_not_exists=True).ss58_address,
"module_key":module_key_address,
"metadata": metadata,
}
response = self.compose_call("register", params=params, key=key, wait_for_finalization=wait_for_finalization)
Expand Down Expand Up @@ -2948,13 +2948,16 @@ def modules(self,
features = ['Name',
'Address',
'Keys',
'Metadata'
],
extra_features = [
'Weights',
'Incentive',
'Dividends',
'Emission',
'DelegationFee',
'LastUpdate',
'Metadata'],
'LastUpdate'],
lite = True,
vector_fetures = ['Incentive', 'Dividends', 'Emission'],
num_connections = 4,
default_module = {
Expand All @@ -2970,6 +2973,9 @@ def modules(self,
return self.all_modules(max_age=max_age, update=update, module=module, features=features, default_module=default_module, **kwargs)

netuid = self.resolve_netuid(netuid=netuid, subnet=subnet)
if lite:
features += extra_features

if netuid in [0]:
features += ['StakeFrom']
path = f'{self.network}/modules/{netuid}'
Expand Down
1 change: 0 additions & 1 deletion commune/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def rate_limit(self,
rates['stake2rate'] = rates['stake2rate'] * module.fn2cost.get(fn, 1)
return min((stake / rates['stake2rate']), rates['max'])


def user2count(self):
user2count = {}
for user in self.users():
Expand Down
4 changes: 3 additions & 1 deletion commune/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ def get_folder_contents_advanced(url='commune-ai/commune.git',

except Exception as e:
print(f"Error: {e}")
return None
return None


2 changes: 1 addition & 1 deletion commune/vali.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_next_result(self, futures):
did_score_bool = bool(result['score'] > 0)
emoji = '🟢' if did_score_bool else '🔴'
if did_score_bool:
keys = ['score', 'name', 'address', 'latency']
keys = ['score', 'name', 'address', 'latency', 'key', 'crypto_type']
else:
keys = list(result.keys())
result = {k: result.get(k, None) for k in keys if k in result}
Expand Down

0 comments on commit d36eb6b

Please sign in to comment.