diff --git a/Dockerfile b/Dockerfile index 5d0e98f1..56fa368e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,25 @@ # THE GENERAL CONTAINER FOR CONNECTING ALL THE ENVIRONMENTS 😈 FROM ubuntu:22.04 + #SYSTEM ARG DEBIAN_FRONTEND=noninteractive RUN usermod -s /bin/bash root RUN apt-get update + #RUST RUN apt-get install curl nano build-essential cargo libstd-rust-dev -y -#NPM/JS + +#JS RUN apt-get install -y nodejs npm RUN npm install -g pm2 + #PYTHON RUN apt-get install python3 python3-pip python3-venv -y -COPY . /commune -RUN pip install -e /commune -# RUN git clone -b main https://github.com/commune-ai/commune.git /commune WORKDIR /app +# make /commune equal to the current directory +COPY . /commune +RUN pip install -e /commune -# TODO DOCKERIZE THE ENTRYPOINT +# ENTRYPOINT ENTRYPOINT [ "tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/commune/module.py b/commune/module.py index 1cfa3032..588893e6 100755 --- a/commune/module.py +++ b/commune/module.py @@ -1049,11 +1049,11 @@ def fn2code(cls, module=None)-> Dict[str, str]: module_name = module.module_name() functions = module.fns() fn_code_map = {} + for fn in functions: - try: - fn_code_map[fn] = c.code(module_name + '/' + fn) - except Exception as e: - print(f'Error: {e}') + + fn_code_map[fn] = c.code(getattr(module, fn)) + return fn_code_map @classmethod @@ -1157,11 +1157,16 @@ def code(cls, module = None, search=None, *args, **kwargs): return inspect.getsource(obj) pycode = code + @classmethod + def module_hash(cls, module=None, *args, **kwargs): + return c.hash(c.code(module or cls.module_name(), **kwargs)) + + @classmethod + def module_hash(cls, module=None, *args, **kwargs): + return c.hash(c.code(module or cls.module_name(), **kwargs)) + @classmethod def code_hash(cls, module=None, *args, **kwargs): - """ - The hash of the code, where the code is the code of the class (cls) - """ return c.hash(c.code(module or cls.module_name(), **kwargs)) @classmethod diff --git a/commune/modules/api/api.py b/commune/modules/apikey/apikey.py similarity index 97% rename from commune/modules/api/api.py rename to commune/modules/apikey/apikey.py index 26107007..ca926f22 100644 --- a/commune/modules/api/api.py +++ b/commune/modules/apikey/apikey.py @@ -2,11 +2,15 @@ import commune as c -class API: +class ApiKey: def __init__(self, module='model.openrouter', path:str=None): self.set_module(module) self.path = path or c.resolve_path('api') + def set_module(self, module): + """ + sets the module + """ if not isinstance(module, str): if hasattr(module, 'module_name'): module = module.module_name() diff --git a/commune/modules/api/test.py b/commune/modules/apikey/test.py similarity index 97% rename from commune/modules/api/test.py rename to commune/modules/apikey/test.py index 64c9e507..1542e831 100644 --- a/commune/modules/api/test.py +++ b/commune/modules/apikey/test.py @@ -3,7 +3,7 @@ class Test: def __init__(self, module='api.test'): self.module = module - self.api = c.module('api')(module=module) + self.api = c.module('apikey')(module=module) def test_set_module(self): # Test with string diff --git a/commune/modules/fal/fal.py b/commune/modules/fal/fal.py index b1c3e570..7280e711 100644 --- a/commune/modules/fal/fal.py +++ b/commune/modules/fal/fal.py @@ -12,7 +12,7 @@ def __init__(self, api: Optional = None): Args: api_key (str, optional): FAL API key. If not provided, will try to get from environment. """ - self.api_key = c.module('api')(self).get_key() + self.api_key = c.module('apikey')(self).get_key() if not self.api_key: raise ValueError("FAL_KEY must be provided either as argument or environment variable") diff --git a/commune/modules/memory/memory.py b/commune/modules/memory/memory.py index 16e9ed7b..d8b4be8c 100644 --- a/commune/modules/memory/memory.py +++ b/commune/modules/memory/memory.py @@ -1,9 +1,22 @@ + +import json + + class Memory: - def __init__(self): - self.memory = {} + def __init__(self, max_bytes_size = 100000): + self.memory = [] + self.max_bytes_size = max_bytes_size + + + def current_size(self): + return sum([len(x) for x in self.memory]) + + def check_storage(self, value:str): + return len(self.memory) + len(value) <= self.max_bytes - def store(self, address, value): - self.memory[address] = value + def store(self, value): + value = json.dumps(value) + self.memory += [value_hash] def load(self, address): return self.memory.get(address, 0) \ No newline at end of file diff --git a/commune/modules/model/openrouter.py b/commune/modules/model/openrouter.py index b948c1c7..5f43aad6 100644 --- a/commune/modules/model/openrouter.py +++ b/commune/modules/model/openrouter.py @@ -88,6 +88,7 @@ def stream_generator( result): def resolve_model(self, model=None): models = self.models() + model = str(model) if str(model) not in models: if ',' in model: models = [m for m in models if any([s in m for s in model.split(',')])] @@ -100,7 +101,7 @@ def resolve_model(self, model=None): return model def get_key(self): - return c.module('api')(module=self).get_key() + return c.module('apikey')(module=self).get_key() def authenticate( self, diff --git a/commune/server.py b/commune/server.py index 54f929c8..f38a9afa 100644 --- a/commune/server.py +++ b/commune/server.py @@ -36,7 +36,6 @@ class Server(c.Module): def __init__( self, - ### CORE PARAMETERS module: Union[c.Module, object] = None, key:str = None, # key for the server (str) name: str = None, # the name of the server @@ -44,7 +43,7 @@ def __init__( port: Optional[int] = None, # the port the server is running on network:str = 'subspace', # the network used for incentives fn2cost : Dict[str, float] = None, # the cost of the function - free : bool = False, + free : bool = False, # if the server is free (checks signature) kwargs : dict = None, # the kwargs for the module crypto_type = 'sr25519', # the crypto type of the key users_path: Optional[str] = None, # the path to the user data diff --git a/scripts/test.sh b/scripts/test.sh index ef8aa843..a7d25faa 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,4 +4,4 @@ CONTAINER_EXISTS=$(docker ps -a | grep $NAME) if [ -z "$CONTAINER_EXISTS" ]; then make run fi -docker exec -it $NAME c pytest +docker exec -it $NAME pytest /$NAME/tests