Class: DurableHuggingfaceHub::Configuration
- Inherits:
-
Object
- Object
- DurableHuggingfaceHub::Configuration
- Defined in:
- lib/durable_huggingface_hub/configuration.rb
Overview
Configuration management for the HuggingFace Hub client.
This class provides a singleton configuration object that can be accessed and modified throughout the library. Configuration values are read from environment variables or can be set programmatically.
Instance Attribute Summary collapse
-
#cache_dir ⇒ String
Base cache directory for HuggingFace Hub files.
-
#disable_progress_bars ⇒ Boolean
Whether to disable progress bars during downloads.
-
#disable_telemetry ⇒ Boolean
Whether to disable telemetry.
-
#download_timeout ⇒ Integer
Default timeout for downloads.
-
#endpoint ⇒ String
HuggingFace Hub endpoint URL.
-
#offline ⇒ Boolean
Whether to operate in offline mode.
-
#request_timeout ⇒ Integer
Default timeout for API requests.
-
#token ⇒ String?
HuggingFace API token.
Class Method Summary collapse
-
.instance ⇒ Configuration
Returns the singleton configuration instance.
-
.reset! ⇒ Configuration
Resets the configuration to default values.
Instance Method Summary collapse
-
#hub_cache_dir ⇒ Pathname
Returns the path to the HuggingFace Hub cache directory.
-
#initialize ⇒ Configuration
constructor
Creates a new Configuration instance with default values.
-
#token_path ⇒ Pathname
Returns the path to the token file.
Constructor Details
#initialize ⇒ Configuration
Creates a new Configuration instance with default values.
Configuration values are read from environment variables if available, otherwise sensible defaults are used.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 49 def initialize @token = env_var("HF_TOKEN") || env_var("HUGGING_FACE_HUB_TOKEN") @cache_dir = determine_cache_dir @endpoint = env_var("HF_ENDPOINT") || Constants::ENDPOINT @offline = parse_boolean(env_var("HF_HUB_OFFLINE"), default: false) @disable_progress_bars = parse_boolean(env_var("HF_HUB_DISABLE_PROGRESS_BARS"), default: false) @disable_telemetry = parse_boolean(env_var("HF_HUB_DISABLE_TELEMETRY"), default: true) @request_timeout = parse_integer(env_var("HF_HUB_REQUEST_TIMEOUT"), default: Constants::DEFAULT_REQUEST_TIMEOUT) @download_timeout = parse_integer(env_var("HF_HUB_DOWNLOAD_TIMEOUT"), default: Constants::DEFAULT_DOWNLOAD_TIMEOUT) end |
Instance Attribute Details
#cache_dir ⇒ String
Returns Base cache directory for HuggingFace Hub files.
25 26 27 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 25 def cache_dir @cache_dir end |
#disable_progress_bars ⇒ Boolean
Returns Whether to disable progress bars during downloads.
34 35 36 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 34 def @disable_progress_bars end |
#disable_telemetry ⇒ Boolean
Returns Whether to disable telemetry.
37 38 39 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 37 def disable_telemetry @disable_telemetry end |
#download_timeout ⇒ Integer
Returns Default timeout for downloads.
43 44 45 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 43 def download_timeout @download_timeout end |
#endpoint ⇒ String
Returns HuggingFace Hub endpoint URL.
28 29 30 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 28 def endpoint @endpoint end |
#offline ⇒ Boolean
Returns Whether to operate in offline mode.
31 32 33 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 31 def offline @offline end |
#request_timeout ⇒ Integer
Returns Default timeout for API requests.
40 41 42 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 40 def request_timeout @request_timeout end |
#token ⇒ String?
Returns HuggingFace API token.
22 23 24 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 22 def token @token end |
Class Method Details
.instance ⇒ Configuration
Returns the singleton configuration instance.
65 66 67 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 65 def self.instance @instance ||= new end |
.reset! ⇒ Configuration
Resets the configuration to default values. Primarily used for testing.
73 74 75 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 73 def self.reset! @instance = new end |
Instance Method Details
#hub_cache_dir ⇒ Pathname
Returns the path to the HuggingFace Hub cache directory.
The cache directory is created if it doesn’t exist.
82 83 84 85 86 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 82 def hub_cache_dir path = Pathname.new(cache_dir).join(Constants::HF_CACHE_SUBDIR) path.mkpath unless path.exist? path end |
#token_path ⇒ Pathname
Returns the path to the token file.
91 92 93 |
# File 'lib/durable_huggingface_hub/configuration.rb', line 91 def token_path Pathname.new(cache_dir).join("token") end |