PHP code example of symfony / ai-hugging-face-platform
1. Go to this page and download the library: Download symfony/ai-hugging-face-platform library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symfony / ai-hugging-face-platform example snippets
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::FEATHERLESS_AI,
);
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();