Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Dec 20, 2024
1 parent 1d71013 commit 92c8fa8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 23 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 12 additions & 7 deletions commune/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion commune/modules/fal/fal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
21 changes: 17 additions & 4 deletions commune/modules/memory/memory.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion commune/modules/model/openrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')])]
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions commune/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ 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
functions:Optional[List[Union[str, callable]]] = None, # list of endpoints
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
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 92c8fa8

Please sign in to comment.