secondtruth / huggingface
Fund package maintenance!
Liberapay
Open Collective
Patreon
Ko Fi
paypal.me/secondtruth
Requires
- php: ^8.1.0
- php-http/discovery: ^1.15.3
- psr/http-client: ^1.0.2
- psr/http-client-implementation: ^1.0.1
- psr/http-factory-implementation: *
- psr/http-message: ^1.1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.5.1
- guzzlehttp/psr7: ^2.5.0
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.8
This package is auto-updated.
Last update: 2024-10-10 03:32:02 UTC
README
Huggingface PHP is a community-maintained PHP API client that allows you to interact with the Hugging Face API.
Table of Contents
Get Started
Requires PHP 8.1+
First, install OpenAI via the Composer package manager:
composer require kambo/huggingface-php
Ensure that the php-http/discovery
composer plugin is allowed to run or install a client manually if your project does not already have a PSR-18 client integrated.
composer require guzzlehttp/guzzle
Then, interact with Hugging Face's API:
use Kambo\Huggingface\Huggingface; use Kambo\Huggingface\Enums\Type; $yourApiKey = getenv('HUGGINGFACE_API_KEY'); $client = Huggingface::client($yourApiKey); $result = $client->inference()->create([ 'model' => 'gpt2', 'inputs' => 'The goal of life is?', 'type' => Type::TEXT_GENERATION, ]); echo $result['generated_text']."\n";
Usage
Inference
Resource
create
Execute inference using the chosen model.
$response = $client->inference()->create([ 'model' => 'gpt2', 'inputs' => 'The goal of life is?', 'type' => Type::TEXT_GENERATION, ]); $response->toArray(); // ['type' => .., 'generated_text' => ...]
Acknowledge
This library was inspired at the source level by the PHP OpenAI client. Portions of the code have been directly copied from this outstanding library.
Huggingface PHP is an open-sourced software licensed under the MIT license.