定制 symfony/ai-hugging-face-platform 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symfony/ai-hugging-face-platform

Composer 安装命令:

composer require symfony/ai-hugging-face-platform

包简介

HuggingFace platform bridge for Symfony AI

README 文档

README

The HuggingFace bridge provides integration with the HuggingFace Inference API, enabling access to thousands of pre-trained models for various AI tasks including natural language processing, computer vision, audio processing, and more.

HuggingFace Documentation

Features

  • Multi-Provider Support: Access models through multiple inference providers (HuggingFace Inference, Cerebras, Cohere, Groq, Together, and others)
  • Comprehensive Task Support: Support for 40+ different AI tasks including:
    • Chat completion and text generation
    • Image classification, object detection, and segmentation
    • Automatic speech recognition and audio classification
    • Text classification, translation, summarization
    • Feature extraction and embeddings
    • And many more...
  • Model Discovery: Built-in API client to discover and query available models
  • Flexible Input/Output: Support for text, images, audio, and binary data
  • Type-Safe Results: Structured result objects for each task type

Installation

Install the symfony/ai-hugging-face-platform package:

composer require symfony/ai-hugging-face-platform

Quick Start

Initialize the Platform

use Symfony\AI\Platform\Bridge\HuggingFace\Factory;
use Symfony\AI\Platform\Bridge\HuggingFace\Provider;

$platform = Factory::createPlatform(
    apiKey: 'hf_your_api_key_here',
    provider: Provider::CEREBRAS, // or other providers
    httpClient: $httpClient  // optional, uses default if not provided
);

Chat Completion Example

use Symfony\AI\Platform\Bridge\HuggingFace\Task;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

$messages = new MessageBag(
    Message::ofUser('Hello, how are you doing today?')
);

$result = $platform->invoke('HuggingFaceH4/zephyr-7b-beta', $messages, [
    'task' => Task::CHAT_COMPLETION,
]);

echo $result->asText();

Image Classification Example

use Symfony\AI\Platform\Bridge\HuggingFace\Task;
use Symfony\AI\Platform\Message\Content\Image;

$image = Image::fromFile('/path/to/image.jpg');

$result = $platform->invoke('google/vit-base-patch16-224', $image, [
    'task' => Task::IMAGE_CLASSIFICATION,
]);

$classifications = $result->asObject()->getClassifications();
foreach ($classifications as $classification) {
    echo $classification->getLabel() . ': ' . $classification->getScore() . PHP_EOL;
}

Feature Extraction (Embeddings)

$result = $platform->invoke('sentence-transformers/all-MiniLM-L6-v2', 'Hello world', [
    'task' => Task::FEATURE_EXTRACTION,
]);

$vectors = $result->asVectors();

Providers

The bridge supports multiple inference providers. For a complete list of available providers and their constants, see the Provider interface.

Specify a provider when creating the platform:

use Symfony\AI\Platform\Bridge\HuggingFace\Factory;
use Symfony\AI\Platform\Bridge\HuggingFace\Provider;

$platform = Factory::createPlatform(
    apiKey: 'your_api_key',
    provider: Provider::GROQ,
);

Supported Tasks

The bridge supports 40+ AI tasks across multiple categories including:

  • Natural Language Processing: Chat completion, text generation, classification, translation, summarization, embeddings, and more
  • Computer Vision: Image classification, object detection, segmentation, depth estimation, and more
  • Audio: Speech recognition, audio classification, text-to-speech, and more
  • Multimodal: Visual question answering, document understanding, and more

For the complete list of supported tasks and their constants, see the Task interface.

Model Discovery

The bridge includes commands to discover available models without using inference credits. They help to research and use models, and can be registered in a Symfony Console application.

Command-Line Interface

The HuggingFace bridge provides two console commands for model discovery:

List Models

List available models with optional filtering:

ai:huggingface:model-list [options]

Options:

  • --provider, -p: Filter by inference provider (e.g., inference)
  • --task, -t: Filter by task type (e.g., text-generation)
  • --search, -s: Search term to filter models
  • --warm, -w: Only list models with warm inference (ready without cold start)

Examples:

# List all text generation models
ai:huggingface:model-list --task=text-generation

# List warm models for a specific provider
ai:huggingface:model-list --provider=hf-inference --warm

# Search for specific models
ai:huggingface:model-list --search=llama

Get Model Information

Retrieve detailed information about a specific model:

ai:huggingface:model-info <model-name>

Examples:

# Get information about a specific model
ai:huggingface:model-info meta-llama/Llama-2-7b-chat
ai:huggingface:model-info gpt2

Output includes:

  • Model ID, downloads, and community likes
  • Task type (pipeline tag)
  • Inference status (warm/cold)
  • Inference provider mappings and availability

Options and Configuration

When invoking the platform, you can pass task-specific options:

$result = $platform->invoke('model/id', $input, [
    'task' => Task::TEXT_GENERATION,
    'temperature' => 0.7,
    'top_p' => 0.9,
    'top_k' => 50,
    'max_new_tokens' => 256,
    'repetition_penalty' => 1.2,
    // ... other provider-specific parameters
]);

You can also override the provider per request:

$result = $platform->invoke('model/id', $input, [
    'task' => Task::CHAT_COMPLETION,
    'provider' => Provider::GROQ,  // Override default provider
]);

symfony/ai-hugging-face-platform 适用场景与选型建议

symfony/ai-hugging-face-platform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.48k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Bridge」 「platform」 「ai」 「huggingface」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 symfony/ai-hugging-face-platform 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 symfony/ai-hugging-face-platform 我们能提供哪些服务?
定制开发 / 二次开发

基于 symfony/ai-hugging-face-platform 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 22
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-18