| 1844 | |
| 1845 | @dataclass |
| 1846 | class _ModelWrapper: |
| 1847 | model: Union[str, Path] |
| 1848 | |
| 1849 | def __post_init__(self): |
| 1850 | if not self.model: |
| 1851 | raise ValueError("model should be provided.") |
| 1852 | assert isinstance(self.model, |
| 1853 | (str, Path)), f"Invalid model: {self.model}" |
| 1854 | |
| 1855 | model_dir = Path(self.model) |
| 1856 | |
| 1857 | if model_dir.exists() and model_dir.is_dir(): |
| 1858 | self.model = model_dir |
| 1859 | |
| 1860 | @property |
| 1861 | def is_hub_model(self) -> bool: |
| 1862 | return not self.is_local_model |
| 1863 | |
| 1864 | @property |
| 1865 | def is_local_model(self) -> bool: |
| 1866 | return isinstance(self.model, Path) |
| 1867 | |
| 1868 | @property |
| 1869 | def model_dir(self) -> Path: |
| 1870 | assert self.is_local_model, f"model_dir is only available for local model, {self.model}." |
| 1871 | return self.model |
| 1872 | |
| 1873 | @model_dir.setter |
| 1874 | def model_dir(self, model_dir: Union[str, Path]): |
| 1875 | model_dir = Path(model_dir) |
| 1876 | assert model_dir.exists() and model_dir.is_dir( |
| 1877 | ), f"model_dir is not a valid path, {model_dir}" |
| 1878 | self.model = model_dir |
| 1879 | |
| 1880 | @property |
| 1881 | def model_name(self) -> Union[str, Path]: |
| 1882 | return self.model if isinstance(self.model, str) else None |
| 1883 | |
| 1884 | |
| 1885 | class BaseLlmArgs(StrictBaseModel): |
no outgoing calls
no test coverage detected