|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +use Symfony\AI\Agent\Agent; |
| 13 | +use Symfony\AI\Agent\StructuredOutput\AgentProcessor as StructuredOutputProcessor; |
| 14 | +use Symfony\AI\Agent\Toolbox\AgentProcessor as ToolProcessor; |
| 15 | +use Symfony\AI\Agent\Toolbox\Tool\Clock; |
| 16 | +use Symfony\AI\Agent\Toolbox\Toolbox; |
| 17 | +use Symfony\AI\Platform\Bridge\VertexAi\Gemini\Model; |
| 18 | +use Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory; |
| 19 | +use Symfony\AI\Platform\Message\Message; |
| 20 | +use Symfony\AI\Platform\Message\MessageBag; |
| 21 | +use Symfony\Component\Clock\Clock as SymfonyClock; |
| 22 | + |
| 23 | +require_once __DIR__.'/bootstrap.php'; |
| 24 | + |
| 25 | +$platform = PlatformFactory::create(env('GOOGLE_CLOUD_LOCATION'), env('GOOGLE_CLOUD_PROJECT'), adc_aware_http_client()); |
| 26 | +$model = new Model(Model::GEMINI_2_5_PRO); |
| 27 | + |
| 28 | +$clock = new Clock(new SymfonyClock()); |
| 29 | +$toolbox = new Toolbox([$clock]); |
| 30 | +$toolProcessor = new ToolProcessor($toolbox); |
| 31 | +$structuredOutputProcessor = new StructuredOutputProcessor(); |
| 32 | +$agent = new Agent($platform, $model, [$toolProcessor, $structuredOutputProcessor], [$toolProcessor, $structuredOutputProcessor], logger()); |
| 33 | + |
| 34 | +$messages = new MessageBag(Message::ofUser('What date and time is it?')); |
| 35 | +$result = $agent->call($messages, ['response_format' => [ |
| 36 | + 'type' => 'json_schema', |
| 37 | + 'json_schema' => [ |
| 38 | + 'name' => 'clock', |
| 39 | + 'strict' => true, |
| 40 | + 'schema' => [ |
| 41 | + 'type' => 'object', |
| 42 | + 'properties' => [ |
| 43 | + 'date' => ['type' => 'string', 'description' => 'The current date in the format YYYY-MM-DD.'], |
| 44 | + 'time' => ['type' => 'string', 'description' => 'The current time in the format HH:MM:SS.'], |
| 45 | + ], |
| 46 | + 'required' => ['date', 'time'], |
| 47 | + 'additionalProperties' => false, |
| 48 | + ], |
| 49 | + ], |
| 50 | +]]); |
| 51 | + |
| 52 | +dump($result->getContent()); |
0 commit comments