Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
2 changes: 1 addition & 1 deletion nnll.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 24 additions & 24 deletions nnll_01/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion nnll_11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
83 changes: 46 additions & 37 deletions nnll_15/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)")
Expand Down Expand Up @@ -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
Expand Down
34 changes: 25 additions & 9 deletions nnll_15/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,37 +15,53 @@

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)
except ImportError as error_log:
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):
"""API library constants"""

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")
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.