Problem/Motivation

The AI core module is adding a new text_classification operation type in #3456768 (MR !1400). The Hugging Face provider already has the low-level API client method HuggingfaceApi::textClassification() but the provider plugin (HuggingfaceProvider) does not implement TextClassificationInterface, so the operation type is not available to users.

The Hugging Face project page already lists Text Classification as a feature, and the Inference API supports it via the text-classification pipeline.

Steps to reproduce

  1. Install the AI core module with the text classification patch from #3456768
  2. Install and enable ai_provider_huggingface
  3. Visit /admin/config/ai/providers/huggingface — there is no "Add Text Classification Model" button
  4. The Text Classification Explorer at /admin/config/ai/explorers/text_classification_generator

Proposed resolution

Wire up the existing HuggingfaceApi::textClassification() client method to the provider plugin by:

Depends on

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ahmad khader created an issue. See original summary.

ahmad khader’s picture

ahmad khader’s picture

Steps to test

  1. Install the AI core module with the text classification patch from #3456768
  2. Visit /admin/config/ai/providers/huggingface — there is now "Add Text Classification Model" button
  3. Add end point like nlptown/bert-base-multilingual-uncased-sentiment — sentiment analysis (1-5 stars) or
    distilbert-base-uncased-finetuned-sst-2-english — positive/negative sentiment
  4. Go to the Text Classification Explorer at /admin/config/ai/explorers/text_classification_generator

Additional fix needed in HuggingfaceApi

The existing HuggingfaceApi::textClassification() method always sends 'parameters' => [] in the request payload. The Hugging Face Inference API interprets an empty PHP array as a JSON list [], which causes a 400 Bad Request error:

{"error":"'list' object has no attribute 'setdefault'"}

The fix is to omit the parameters key when the array is empty, or cast it to (object) so it serializes as {}.

ahmad khader’s picture

Title: Add Text Classification support to Hugging Face provider » Add Text Classification support
ahmad khader’s picture

Assigned: ahmad khader » Unassigned
arianraeesi’s picture