mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
32 lines
906 B
PHP
32 lines
906 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
use Symfony\AI\Platform\Bridge\OpenAI\PlatformFactory;
|
|
use Symfony\AI\Platform\Bridge\OpenAI\Whisper;
|
|
use Symfony\AI\Platform\Message\Content\Audio;
|
|
use Symfony\Component\Dotenv\Dotenv;
|
|
|
|
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
|
|
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
|
|
|
|
if (empty($_ENV['OPENAI_API_KEY'])) {
|
|
echo 'Please set the OPENAI_API_KEY environment variable.'.\PHP_EOL;
|
|
exit(1);
|
|
}
|
|
|
|
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
|
|
$model = new Whisper();
|
|
$file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3');
|
|
|
|
$response = $platform->request($model, $file);
|
|
|
|
echo $response->getContent().\PHP_EOL;
|