tooluniverse.utils moduleΒΆ
- tooluniverse.utils.hf_hub_download(repo_id: str, filename: str, *, subfolder: str | None = None, repo_type: str | None = None, revision: str | None = None, library_name: str | None = None, library_version: str | None = None, cache_dir: str | Path | None = None, local_dir: str | Path | None = None, user_agent: Dict | str | None = None, force_download: bool = False, proxies: Dict | None = None, etag_timeout: float = 10, token: bool | str | None = None, local_files_only: bool = False, headers: Dict[str, str] | None = None, endpoint: str | None = None, resume_download: bool | None = None, force_filename: str | None = None, local_dir_use_symlinks: bool | Literal['auto'] = 'auto') str [source][source]ΒΆ
Download a given file if itβs not already present in the local cache.
The new cache file layout looks like this: - The cache directory contains one subfolder per repo_id (namespaced by repo type) - inside each repo folder:
refs is a list of the latest known revision => commit_hash pairs
blobs contains the actual file blobs (identified by their git-sha or sha256, depending on whether theyβre LFS files or not)
snapshots contains one subfolder per commit, each βcommitβ contains the subset of the files that have been resolved at that particular commit. Each filename is a symlink to the blob at that particular commit.
[ 96] . βββ [ 160] models--julien-c--EsperBERTo-small βββ [ 160] blobs β βββ [321M] 403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd β βββ [ 398] 7cb18dc9bafbfcf74629a4b760af1b160957a83e β βββ [1.4K] d7edf6bd2a681fb0175f7735299831ee1b22b812 βββ [ 96] refs β βββ [ 40] main βββ [ 128] snapshots βββ [ 128] 2439f60ef33a0d46d85da5001d52aeda5b00ce9f β βββ [ 52] README.md -> ../../blobs/d7edf6bd2a681fb0175f7735299831ee1b22b812 β βββ [ 76] pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd βββ [ 128] bbc77c8132af1cc5cf678da3f1ddf2de43606d48 βββ [ 52] README.md -> ../../blobs/7cb18dc9bafbfcf74629a4b760af1b160957a83e βββ [ 76] pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
If
local_dir
is provided, the file structure from the repo will be replicated in this location. When using this option, thecache_dir
will not be used and a.cache/huggingface/
folder will be created at the root oflocal_dir
to store some metadata related to the downloaded files. While this mechanism is not as robust as the main cache-system, itβs optimized for regularly pulling the latest version of a repository.- Parameters:
repo_id (
str
) β A user or an organization name and a repo name separated by a/
.filename (
str
) β The name of the file in the repo.subfolder (
str
, optional) β An optional value corresponding to a folder inside the model repo.repo_type (
str
, optional) β Set to"dataset"
or"space"
if downloading from a dataset or space,None
or"model"
if downloading from a model. Default isNone
.revision (
str
, optional) β An optional Git revision id which can be a branch name, a tag, or a commit hash.library_name (
str
, optional) β The name of the library to which the object corresponds.library_version (
str
, optional) β The version of the library.cache_dir (
str
,Path
, optional) β Path to the folder where cached files are stored.local_dir (
str
orPath
, optional) β If provided, the downloaded file will be placed under this directory.user_agent (
dict
,str
, optional) β The user-agent info in the form of a dictionary or a string.force_download (
bool
, optional, defaults toFalse
) β Whether the file should be downloaded even if it already exists in the local cache.proxies (
dict
, optional) β Dictionary mapping protocol to the URL of the proxy passed torequests.request
.etag_timeout (
float
, optional, defaults to10
) β When fetching ETag, how many seconds to wait for the server to send data before giving up which is passed torequests.request
.token (
str
,bool
, optional) β- A token to be used for the download.
If
True
, the token is read from the HuggingFace config folder.If a string, itβs used as the authentication token.
local_files_only (
bool
, optional, defaults toFalse
) β IfTrue
, avoid downloading the file and return the path to the local cached file if it exists.headers (
dict
, optional) β Additional headers to be sent with the request.
- Returns:
Local path of file or if networking is off, last version of file cached on disk.
- Return type:
str
- Raises:
[RepositoryNotFoundError] β If the repository to download from cannot be found. This may be because it doesnβt exist, or because it is set to
private
and you do not have access.[RevisionNotFoundError] β If the revision to download from cannot be found.
[EntryNotFoundError] β If the file to download cannot be found.
[LocalEntryNotFoundError] β If network is disabled or unavailable and file is not found in cache.
[EnvironmentError](https β //docs.python.org/3/library/exceptions.html#EnvironmentError) If
token=True
but the token cannot be found.[OSError](https β //docs.python.org/3/library/exceptions.html#OSError) If ETag cannot be determined.
[ValueError](https β //docs.python.org/3/library/exceptions.html#ValueError) If some parameter value is invalid.
- class tooluniverse.utils.ModelMetaclass(cls_name: str, bases: tuple[type[Any], ...], namespace: dict[str, Any], __pydantic_generic_metadata__: PydanticGenericMetadata | None = None, __pydantic_reset_parent_namespace__: bool = True, _create_model_module: str | None = None, **kwargs: Any)[source][source]ΒΆ
Bases:
ABCMeta
- static __new__(mcs, cls_name: str, bases: tuple[type[Any], ...], namespace: dict[str, Any], __pydantic_generic_metadata__: PydanticGenericMetadata | None = None, __pydantic_reset_parent_namespace__: bool = True, _create_model_module: str | None = None, **kwargs: Any) type [source][source]ΒΆ
Metaclass for creating Pydantic models.
- Parameters:
cls_name β The name of the class to be created.
bases β The base classes of the class to be created.
namespace β The attribute dictionary of the class to be created.
__pydantic_generic_metadata__ β Metadata for generic models.
__pydantic_reset_parent_namespace__ β Reset parent namespace.
_create_model_module β The module of the class to be created, if created by
create_model
.**kwargs β Catch-all for any other keyword arguments.
- Returns:
The new class created by the metaclass.
- __getattr__(item: str) Any [source][source]ΒΆ
This is necessary to keep attribute access working for class attribute access.
- tooluniverse.utils.yaml_to_dict(yaml_file_path)[source][source]ΒΆ
Convert a YAML file to a dictionary.
- tooluniverse.utils.read_json_list(file_path)[source][source]ΒΆ
Reads a list of JSON objects from a file.
Parameters: file_path (str): The path to the JSON file.
Returns: list: A list of dictionaries containing the JSON objects.
- tooluniverse.utils.compare_function_calls(pred_function_call, gt_function_call, compare_arguments=True, compare_value=True)[source][source]ΒΆ
- tooluniverse.utils.extract_function_call_json(lst, return_message=False, verbose=True, format='llama')[source][source]ΒΆ
- tooluniverse.utils.validate_query(query: Dict[str, Any]) bool [source][source]ΒΆ
Validate a query dictionary for required fields and structure.
- tooluniverse.utils.normalize_gene_symbol(gene_symbol: str) str [source][source]ΒΆ
Normalize a gene symbol to standard format.
- tooluniverse.utils.format_api_response(response_data: Any, format_type: str = 'json') str | Dict[str, Any] | List[Any] [source][source]ΒΆ
Format API response data into a standardized format.
- tooluniverse.utils.validate_hook_config(config: Dict[str, Any]) bool [source][source]ΒΆ
Validate hook configuration for correctness and completeness.
This function checks that the hook configuration contains all required fields and that the structure is valid for the hook system.