bluefly/ai_agent_huggingface

HuggingFace AI agent with advanced model discovery and pipeline management

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:drupal-module

dev-main 2025-07-09 18:29 UTC

This package is auto-updated.

Last update: 2025-07-09 18:31:06 UTC


README

Enterprise AI agent module for Drupal that provides intelligent HuggingFace integration with advanced model discovery, pipeline management, and analytics capabilities.

Overview

The AI Agent HuggingFace module extends Drupal's AI capabilities by providing an intelligent agent that can:

  • Automatically discover and sync models from HuggingFace Hub
  • Execute 25+ different pipeline types for multi-modal AI processing
  • Monitor performance and provide analytics
  • Manage datasets and training jobs
  • Deploy models to HuggingFace Spaces

Requirements

  • Drupal 10.3 or 11.x
  • PHP 8.1 or higher
  • AI module (drupal/ai)
  • AI Provider HuggingFace module (drupal/ai_provider_huggingface)

Installation

  1. Install the module using Composer:

    composer require bluefly/ai_agent_huggingface
    
  2. Enable the module:

    drush en ai_agent_huggingface
    
  3. Configure the module at /admin/config/ai/huggingface-agent

Configuration

API Key Setup

  1. Obtain a HuggingFace API token from https://huggingface.co/settings/tokens
  2. Store the API key using Drupal's Key module
  3. Configure the key reference in the module settings

Model Discovery

Enable automatic model discovery to sync popular models:

  • Navigate to /admin/config/ai/huggingface-agent
  • Enable "Automatic model discovery"
  • Set sync interval (default: daily)
  • Configure max models per sync

Pipeline Configuration

The module supports various pipeline types:

  • Text Generation
  • Summarization
  • Translation
  • Question Answering
  • Sentiment Analysis
  • Feature Extraction
  • Image Classification
  • Object Detection
  • And many more...

Usage

As an AI Agent

// Get the HuggingFace agent service
$agent = \Drupal::service('ai_agent_huggingface.pipeline_manager');

// Execute a summarization task
$result = $agent->execute('summarization', [
  'model' => 'facebook/bart-large-cnn',
  'inputs' => 'Your long text here...'
]);

Model Discovery

// Discover models by criteria
$discovery = \Drupal::service('ai_agent_huggingface.model_discovery');
$models = $discovery->discoverModels([
  'task' => 'text-generation',
  'min_likes' => 100,
  'language' => 'en'
]);

Analytics

View model performance metrics at /admin/config/ai/huggingface-agent/analytics

Features

Dynamic Model Discovery

  • Automatically discover models from HuggingFace Hub
  • Filter by task, language, likes, and downloads
  • Cache model metadata for performance

Pipeline Management

  • Support for 25+ HuggingFace pipeline types
  • Automatic model selection based on task
  • Configurable parameters per pipeline

Performance Monitoring

  • Track response times and token usage
  • Monitor error rates and success metrics
  • Generate cost estimates

Dataset Management

  • Import datasets from HuggingFace Hub
  • Preprocess data for training
  • Export datasets in various formats

Training Job Orchestration

  • Create and monitor fine-tuning jobs
  • Track training progress
  • Manage model versions

Spaces Integration

  • Deploy models to HuggingFace Spaces
  • Monitor deployment status
  • Manage Space configurations

Permissions

  • administer ai_agent_huggingface: Full module administration
  • view huggingface models: View model information
  • create huggingface models: Add new models
  • edit huggingface models: Edit model configurations
  • delete huggingface models: Remove models
  • manage huggingface training jobs: Create and monitor training jobs
  • view huggingface analytics: Access performance analytics
  • manage huggingface spaces: Deploy and manage Spaces
  • sync huggingface models: Trigger model synchronization

API Endpoints

The module provides several API endpoints:

  • /admin/config/ai/huggingface-agent/models - Model management dashboard
  • /admin/config/ai/huggingface-agent/analytics - Analytics dashboard

Troubleshooting

Common Issues

  1. API Key not working

    • Verify the key is stored correctly in Key module
    • Check API key permissions on HuggingFace
  2. Model discovery fails

    • Check internet connectivity
    • Verify HuggingFace API is accessible
    • Review error logs at /admin/reports/dblog
  3. Pipeline execution errors

    • Ensure the model supports the requested pipeline
    • Check model availability
    • Verify input format matches pipeline requirements

Development

Running Tests

# Unit tests
./vendor/bin/phpunit -c web/modules/custom/ai_agent_huggingface

# Functional tests
./vendor/bin/phpunit -c web/modules/custom/ai_agent_huggingface --testsuite functional

Extending the Module

Create custom pipeline plugins by implementing HuggingFacePipelineInterface:

namespace Drupal\my_module\Plugin\OperationType\HuggingFacePipeline;

use Drupal\ai_agent_huggingface\Attribute\HuggingFacePipeline;
use Drupal\ai_agent_huggingface\Plugin\OperationType\HuggingFacePipeline\HuggingFacePipelineBase;

#[HuggingFacePipeline(
  id: 'custom_pipeline',
  label: 'Custom Pipeline',
  description: 'My custom HuggingFace pipeline'
)]
class CustomPipeline extends HuggingFacePipelineBase {
  // Implementation
}

Support

For issues and feature requests, please use the issue queue.

License

This module is licensed under the GPL-2.0-or-later license.

Credits

Maintained by Bluefly Collective