Langertha

 view release on metacpan or  search on metacpan

lib/Langertha/Engine/HuggingFace.pm  view on Meta::CPAN


  # Only cache non-search results
  unless ($opts{search}) {
    $self->_models_cache({
      timestamp => time,
      models => $models,
      model_ids => \@model_ids,
    });
  }

  return $opts{full} ? $models : \@model_ids;
}


__PACKAGE__->meta->make_immutable;


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Langertha::Engine::HuggingFace - HuggingFace Inference Providers API

=head1 VERSION

version 0.502

=head1 SYNOPSIS

    use Langertha::Engine::HuggingFace;

    my $hf = Langertha::Engine::HuggingFace->new(
        api_key => $ENV{HF_TOKEN},
        model   => 'Qwen/Qwen2.5-7B-Instruct',
    );

    print $hf->simple_chat('Hello from Perl!');

    # Access many models through one API
    my $llama = Langertha::Engine::HuggingFace->new(
        api_key => $ENV{HF_TOKEN},
        model   => 'meta-llama/Llama-3.3-70B-Instruct',
    );

=head1 DESCRIPTION

Provides access to HuggingFace Inference Providers, a unified API gateway
for open-source models hosted on the HuggingFace Hub. The endpoint at
C<https://router.huggingface.co/v1> is 100% OpenAI-compatible.

Model names use C<org/model> format (e.g., C<Qwen/Qwen2.5-7B-Instruct>,
C<meta-llama/Llama-3.3-70B-Instruct>). No default model is set;
C<model> must be specified explicitly.

Supports chat, streaming, and MCP tool calling. Embeddings and transcription
are not supported.

Get your API token at L<https://huggingface.co/settings/tokens> and set
C<LANGERTHA_HUGGINGFACE_API_KEY> in your environment.

B<THIS API IS WORK IN PROGRESS>

=head2 hub_url

Base URL for the HuggingFace Hub API. Default: C<https://huggingface.co>.
Used by C<list_models> to query available inference models.

=head2 list_models_request

    my $request = $engine->list_models_request(%opts);

Generates an HTTP GET request for the HuggingFace Hub API models
endpoint with inference provider filtering. Accepts options:
C<search>, C<pipeline_tag> (default: C<text-generation>),
C<inference_provider> (default: C<all>), C<limit> (default: 50).

=head2 list_models_response

    my $models = $engine->list_models_response($http_response);

Parses the Hub API response. Returns an ArrayRef of model objects
with C<id>, C<pipeline_tag>, C<inferenceProviderMapping>, etc.

=head2 list_models

    # All text-generation models with inference providers
    my $ids = $hf->list_models;

    # Search for specific models
    my $ids = $hf->list_models(search => 'llama');

    # Filter by pipeline tag
    my $ids = $hf->list_models(pipeline_tag => 'text-to-image');

    # Full model objects with provider details
    my $models = $hf->list_models(full => 1);

Queries the HuggingFace Hub API for models available via inference
providers. Only returns models that have at least one active inference
provider. Results are cached for C<models_cache_ttl> seconds (search
results are not cached).

=head1 SEE ALSO

=over

=item * L<https://huggingface.co/docs/inference-providers/index> - HuggingFace Inference Providers docs

=item * L<https://huggingface.co/models> - Browse available models

=item * L<https://status.huggingface.co/> - HuggingFace service status

=item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role

=back



( run in 1.572 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )