symfony/ai-hugging-face-platform
Symfony AI HuggingFace bridge for the HuggingFace Inference API and multiple providers (Cerebras, Cohere, Groq, Together, etc.). Invoke thousands of pretrained models across 40+ tasks—chat, text generation, vision, audio, embeddings—with model discovery, flexible I/O, and typed results.
symfony/http-client works with Laravel’s HttpClient). The factory pattern (Factory::createPlatform()) and dependency injection align with Laravel’s service providers, enabling seamless integration via a custom facade or service binding.HuggingFace\Provider with a Groq\Provider via interfaces).Task::CHAT_COMPLETION, Task::IMAGE_CLASSIFICATION) map cleanly to Laravel’s service-oriented patterns. For example, a ChatService could delegate to the HuggingFace bridge, while a MediaAnalysisService handles vision tasks.ModelInvoked, TaskFailed) for observability, retries, or analytics. The package’s structured result objects (e.g., asText(), asVectors()) simplify event payloads.dispatchSync()) can cache or pre-warm models to reduce latency spikes, aligning with the package’s --warm flag in CLI discovery.Factory::createPlatform()) require <10 lines of Laravel code to integrate. Example:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(HuggingFacePlatform::class, fn() =>
Factory::createPlatform(
apiKey: config('services.huggingface.api_key'),
provider: Provider::from(config('services.huggingface.default_provider')),
httpClient: $this->app->make(HttpClient::class)
)
);
}
temperature, max_new_tokens) map to Laravel’s config files or environment variables, enabling runtime flexibility without hardcoding.HttpClient (or Guzzle) can replace Symfony’s HttpClient, though Symfony’s StreamedResponse may need a Laravel wrapper for large payloads (e.g., image processing).ai:huggingface:model-list CLI can be published as Laravel Artisan commands with minimal effort, leveraging Laravel’s Command class.Illuminate\Cache\RateLimiter) for fallback providers.Illuminate\Support\Facades\Cache::remember()).classifications, vectors), but Laravel’s Eloquent or API resources may need adapters for consistency.HuggingFaceModelError).model_id, task, and cost_per_request).HttpClient (or Guzzle) as a drop-in replacement for Symfony’s HttpClient.HuggingFacePlatform to Laravel’s container via a service provider.config/services/huggingface.php.HuggingFaceTaskExecuted) for analytics or retries.symfony/console for CLI commands (e.g., publish ai:huggingface:model-list as an Artisan command).symfony/http-client if Laravel’s HttpClient lacks features (e.g., streaming responses).Task::CHAT_COMPLETION) in a non-critical feature (e.g., a beta chatbot).app(HuggingFacePlatform::class)).Task::TEXT_GENERATION to Groq for speed).| Laravel Feature | Integration Approach | Potential Gaps | Mitigation |
|---|---|---|---|
| Service Container | Bind HuggingFacePlatform via AppServiceProvider. |
None. | Use Laravel’s DI. |
| HTTP Client | Replace Symfony’s HttpClient with Laravel’s HttpClient or Guzzle. |
Streaming responses may need custom handling. | Use Symfony\Contracts\HttpClient\StreamedResponse. |
| Configuration | Store settings in config/services/huggingface.php. |
No native support for provider-specific configs. | Use nested arrays (e.g., providers.groq.temperature). |
| Artisan Commands | Publish CLI commands via Artisan::command(). |
Symfony’s Command may need Laravel wrappers. |
Extend Illuminate\Console\Command. |
| Queues | Dispatch long tasks to Laravel Queues with dispatchSync(). |
How can I help you explore Laravel packages today?