mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-15 00:07:28 +00:00
fix issues with optional dependencies (#204)
* fix issues with optional dependencies * format document * Tree: Format and comment
This commit is contained in:
52
common/optional_dependencies.py
Normal file
52
common/optional_dependencies.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Construct a model of all optional dependencies"""
|
||||
|
||||
import importlib.util
|
||||
from pydantic import BaseModel, computed_field
|
||||
|
||||
|
||||
# Declare the exported parts of this module
|
||||
__all__ = ["dependencies"]
|
||||
|
||||
|
||||
class DependenciesModel(BaseModel):
|
||||
"""Model of which optional dependencies are installed."""
|
||||
|
||||
torch: bool
|
||||
exllamav2: bool
|
||||
flash_attn: bool
|
||||
outlines: bool
|
||||
infinity_emb: bool
|
||||
sentence_transformers: bool
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def extras(self) -> bool:
|
||||
return self.outlines and self.infinity_emb and self.sentence_transformers
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def exl2(self) -> bool:
|
||||
return self.torch and self.exllamav2 and self.flash_attn
|
||||
|
||||
|
||||
def is_installed(package_name: str) -> bool:
|
||||
"""Utility function to check if a package is installed."""
|
||||
|
||||
spec = importlib.util.find_spec(package_name)
|
||||
return spec is not None
|
||||
|
||||
|
||||
def get_installed_deps() -> DependenciesModel:
|
||||
"""Check if optional dependencies are installed by looping over the fields."""
|
||||
|
||||
fields = DependenciesModel.model_fields
|
||||
|
||||
installed_deps = {}
|
||||
|
||||
for field_name in fields.keys():
|
||||
installed_deps[field_name] = is_installed(field_name)
|
||||
|
||||
return DependenciesModel(**installed_deps)
|
||||
|
||||
|
||||
dependencies = get_installed_deps()
|
||||
Reference in New Issue
Block a user