diff --git a/_version.py b/_version.py index c704a27a..e28be794 100644 --- a/_version.py +++ b/_version.py @@ -17,5 +17,5 @@ __version_tuple__: VERSION_TUPLE version_tuple: VERSION_TUPLE -__version__ = version = '0.1.dev274+geef99c6.d20250422' -__version_tuple__ = version_tuple = (0, 1, 'dev274', 'geef99c6.d20250422') +__version__ = version = '0.1.dev277+g5cdf048.d20250423' +__version_tuple__ = version_tuple = (0, 1, 'dev277', 'g5cdf048.d20250423') diff --git a/nnll.egg-info/PKG-INFO b/nnll.egg-info/PKG-INFO index f2f724c9..ccbe4bc5 100644 --- a/nnll.egg-info/PKG-INFO +++ b/nnll.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: nnll -Version: 0.1.dev274+geef99c6.d20250422 +Version: 0.1.dev277+g5cdf048.d20250423 Summary: Neural Network Link Library : A comprehensive modular toolkit for Diffusion and Large Language Model inference processes. Author-email: darkshapes <91800957+exdysa@users.noreply.github.com> License: #// SPDX-License-Identifier: blessing diff --git a/nnll_01/__init__.py b/nnll_01/__init__.py index f48b7298..1dc435a7 100644 --- a/nnll_01/__init__.py +++ b/nnll_01/__init__.py @@ -138,30 +138,30 @@ def wrapper(*args, **kwargs) -> None: return return_data except Exception as error_log: - file_name = f".nnll_trace{datetime.now().strftime('%Y%m%d%_H.%M.%S.%f')}.json" - assembled_path = os.path.join("log", file_name) - - tracer = viztracer.VizTracer() - tracer.start() - logger_obj.debug( - { - "Exception": { - "exc_info": error_log, - "filename": func.__module__, - "pathname": Path(func.__module__).cwd(), - "func_name": func.__name__, - "process": os.getppid(), - "thread": get_native_id(), - **{"ain_type": type(args), "ain": args if args else {}}, - **{"kin_type": type(kwargs), "kin": kwargs if kwargs else {}}, - "locals": locals(), - "globals": globals(), - } - } - ) - # Re-raise the exception to propagate it - tracer.stop() - tracer.save(output_file=assembled_path) + # file_name = f".nnll_trace{datetime.now().strftime('%Y%m%d%_H.%M.%S.%f')}.json" + # assembled_path = os.path.join("log", file_name) + + # tracer = viztracer.VizTracer() + # tracer.start() + # logger_obj.debug( + # { + # "Exception": { + # "exc_info": error_log, + # "filename": func.__module__, + # "pathname": Path(func.__module__).cwd(), + # "func_name": func.__name__, + # "process": os.getppid(), + # "thread": get_native_id(), + # **{"ain_type": type(args), "ain": args if args else {}}, + # **{"kin_type": type(kwargs), "kin": kwargs if kwargs else {}}, + # "locals": locals(), + # "globals": globals(), + # } + # } + # ) + # # Re-raise the exception to propagate it + # tracer.stop() + # tracer.save(output_file=assembled_path) raise error_log return wrapper diff --git a/nnll_11/__init__.py b/nnll_11/__init__.py index e6630bc8..2864971d 100644 --- a/nnll_11/__init__.py +++ b/nnll_11/__init__.py @@ -50,8 +50,10 @@ async def get_api(model: str, library: LibType) -> dict: model = {"model": model} # api_base="https://localhost:xxxx/address:port/sdbx/placeholder"} # huggingface/ elif library == LibType.VLLM: model = {"model": model, "api_base": "http://localhost:8000/chat/completions"} # hosted_vllm/ - if library == LibType.LLAMAFILE: + elif library == LibType.LLAMAFILE: model = {"model": model, "api_base": "http://localhost:8080/v1", "api_key": "sk-no-key-required"} + elif library == LibType.CORTEX: + model = {"model": model, "api_base": "http://127.0.0.1:39281/v1/chat/completions"} return model diff --git a/nnll_15/__init__.py b/nnll_15/__init__.py index 35957ca0..23489765 100644 --- a/nnll_15/__init__.py +++ b/nnll_15/__init__.py @@ -35,7 +35,7 @@ def available_tasks(self) -> List[Tuple]: library_tasks = {} processed_tasks = [] library_tasks = VALID_TASKS[self.library] - if self.library == LibType.OLLAMA: + if self.library == LibType.OLLAMA or self.library == LibType.CORTEX: default_task = ("text", "text") elif self.library == LibType.HUB: pattern = re.compile(r"(\w+)-to-(\w+)") @@ -65,54 +65,63 @@ def from_model_data(cls) -> list[tuple[str]]: # lib_type: LibType) model_data: if LibType.OLLAMA: try: - from ollama import ListResponse, list as ollama_list # type: ignore - except (ModuleNotFoundError, ImportError) as error_log: - dbug(error_log) - return - model_data: ListResponse = ollama_list() - for model in model_data.models: # pylint:disable=no-member - entry = cls( - model=f"ollama_chat/{model.model}", - size=model.size.real, - tags=[model.details.family], - library=LibType.OLLAMA, - timestamp=int(model.modified_at.timestamp()), - ) - entries.append(entry) + from ollama import ListResponse, list as ollama_list + model_data: ListResponse = ollama_list() # type: ignore + except (ConnectionError, ModuleNotFoundError, ImportError) as error_log: + dbug(error_log) + else: + for model in model_data.models: # pylint:disable=no-member + entry = cls( + model=f"ollama_chat/{model.model}", + size=model.size.real, + tags=[model.details.family], + library=LibType.OLLAMA, + timestamp=int(model.modified_at.timestamp()), + ) + entries.append(entry) if LibType.HUB: try: from huggingface_hub import scan_cache_dir, repocard # type: ignore except (ModuleNotFoundError, ImportError) as error_log: dbug(error_log) - return - - model_data = scan_cache_dir() - for repo in model_data.repos: - try: - meta = repocard.RepoCard.load(repo.repo_id).data - except ValueError as error_log: - dbug(error_log) - continue - tags = [] - if hasattr(meta, "tags"): - tags.extend(meta.tags) - if hasattr(meta, "pipeline_tag"): - tags.append(meta.pipeline_tag) - if not tags: - tags = ["unknown"] - entry = cls(model=repo.repo_id, size=repo.size_on_disk, tags=tags, library=LibType.HUB, timestamp=int(repo.last_modified)) + else: + model_data = scan_cache_dir() + for repo in model_data.repos: + try: + meta = repocard.RepoCard.load(repo.repo_id).data + except ValueError as error_log: + dbug(error_log) + continue + tags = [] + if hasattr(meta, "tags"): + tags.extend(meta.tags) + if hasattr(meta, "pipeline_tag"): + tags.append(meta.pipeline_tag) + if not tags: + tags = ["unknown"] + entry = cls(model=repo.repo_id, size=repo.size_on_disk, tags=tags, library=LibType.HUB, timestamp=int(repo.last_modified)) + entries.append(entry) + if LibType.CORTEX: + import requests + from datetime import datetime + + response = requests.get("http://127.0.0.1:39281/v1/models", timeout=(3, 3)) + model = response.json() + for model_data in model["data"]: + entry = cls( + model=f"openai/{model_data.get('model')}", + size=model_data.get("size", 0), + tags=[model_data.get("modalities", ["text", "text"])], + library=LibType.CORTEX, + timestamp=datetime.timestamp(datetime.now()), # no api for this data in cortex + ) entries.append(entry) if LibType.LM_STUDIO: # doesn't populate RegitryEntry yet try: from lmstudio import get_default_client, list_downloaded_models # type: ignore - - lms_client = get_default_client() - lms_client.api_host = "localhost:1143" - model_data = list_downloaded_models() except (ModuleNotFoundError, ImportError) as error_log: dbug(error_log) - if LibType.VLLM: # placeholder try: import vllm # type: ignore # noqa: F401 #pylint:disable=unused-import diff --git a/nnll_15/constants.py b/nnll_15/constants.py index 604fb018..91ae3a5b 100644 --- a/nnll_15/constants.py +++ b/nnll_15/constants.py @@ -4,7 +4,7 @@ from enum import Enum from sys import modules as sys_modules -from typing import Annotated, Callable, Optional +from typing import Annotated, Callable, Optional, Tuple from pydantic import BaseModel, Field @@ -15,15 +15,31 @@ mir_db = JSONCache(CONFIG_PATH_NAMED) -API_NAMES: list = ["ollama", "huggingface_hub", "lmstudio", "vllm", "llamafile"] +# Order is important for this list since it is used for LibType below +API_NAMES: list = ["ollama", "huggingface_hub", "lmstudio", "cortex", "llamafile", "vllm"] @debug_monitor -def _check_and_import(): +def check_and_import() -> Tuple[bool]: """Check if the module is available. If not, try to import it dynamically. Returns True if the module is successfully imported or already available, False otherwise.""" + import requests + + cortex_server: bool = False + llamafile_server: bool = False for api in API_NAMES: + if api == "cortex": + response = requests.get("http://127.0.0.1:39281/v1/chat/completions", timeout=(3, 3)) + data = response.json() + if data.get("result") == "OK": + cortex_server = True + elif api == "llamafile": + response = requests.get("http://localhost:8080/v1", timeout=(3, 3)) + data = response.json() + if data.get("result") == "OK": + llamafile_server = True + try: __import__(api) # setattr(LibType, api_libtype.get(api), True) @@ -31,9 +47,10 @@ def _check_and_import(): nfo("|Ignorable| Source unavailable:", f"{api}") dbug(error_log) # setattr(LibType, api_libtype.get(api), False) + return cortex_server, llamafile_server -_check_and_import() +cortex_server, llamafile_server = check_and_import() class LibType(Enum): @@ -41,11 +58,10 @@ class LibType(Enum): OLLAMA: int = (0, API_NAMES[0] in sys_modules) HUB: int = (1, API_NAMES[1] in sys_modules) - VLLM: int = (2, API_NAMES[2] in sys_modules) - LM_STUDIO: int = (3, API_NAMES[3] in sys_modules) - LLAMAFILE: int = (4, API_NAMES[4] in sys_modules) - # CORTEX : Identical to OpenAI, http://localhost:39281 - # LLAMAFILE : "http://localhost:8080/v1 api_key = "sk-no-key-required" + LM_STUDIO: int = (2, API_NAMES[2] in sys_modules) + CORTEX: int = (3, cortex_server) + LLAMAFILE: int = (4, llamafile_server) + VLLM: int = (5, API_NAMES[5] in sys_modules) example_str = ("function_name", "import.function_name") diff --git a/uv.lock b/uv.lock index fc1df1d8..330525fe 100644 --- a/uv.lock +++ b/uv.lock @@ -1498,7 +1498,7 @@ wheels = [ [[package]] name = "nnll" -version = "0.1.dev274+geef99c6.d20250422" +version = "0.1.dev277+g5cdf048.d20250423" source = { editable = "." } [package.optional-dependencies]