Class HuggingFaceProvider

All Implemented Interfaces:
PropertyChangeSource, Rebindable

public class HuggingFaceProvider extends OpenAiChatCompletionsProvider
A specialized provider for the Hugging Face Inference API that performs deep model inspection by fetching metadata directly from the HF Hub.
Author:
anahata
  • Field Details

    • HF_HUB_BASE

      public static final String HF_HUB_BASE
      The base URL for the Hugging Face Hub metadata API.
      See Also:
    • HUB_CLIENT

      public static final HttpClient HUB_CLIENT
      A specialized HTTP client for fetching model configuration files from the Hub. Uses connection pooling and follows redirects to the Hub's CDN. Configured with HTTP/1.1 to prevent HTTP/2 multiplexed stream exhaustion.
  • Constructor Details

    • HuggingFaceProvider

      public HuggingFaceProvider()
      Constructs a new Hugging Face provider with the stable UUID 'HuggingFace' and pre-configured endpoint and acquisition URIs.
  • Method Details

    • listModels

      public List<? extends AbstractModel> listModels()
      Fetches the list of all models available from the provider's remote API.

      Implementation details: Performs a GET request to the /models endpoint of the configured getBaseUrl(). Parses the standard OpenAI list-response and wraps each ID in an OpenAiCompatibleModel instance.

      Implementation details: Fetches basic models from the router and orchestrates parallel deep self-inspection across all models without artificial timeouts. Resolves the API key upfront to prevent thread-monitor lock contention.

      Overrides:
      listModels in class OpenAiChatCompletionsProvider
      Returns:
      A list of provider-specific AbstractModel objects.
    • isRetryable

      public boolean isRetryable(int statusCode, String responseBody)
      Determines if an HTTP status code or response body indicates a transient failure that should trigger a retry or rotation.

      Checks for common OpenAI-compatible error codes (429, 503, 500, 499, 408).

      Implementation details: Adds specific handling for Hugging Face credit-related errors (HTTP 402).

      Overrides:
      isRetryable in class OpenAiChatCompletionsProvider
      Parameters:
      statusCode - The HTTP status code.
      responseBody - The raw response body.
      Returns:
      true if retryable, false otherwise.