|
| 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\DeepSeek\PlatformFactory; |
| 18 | +use Symfony\AI\Platform\Message\Message; |
| 19 | +use Symfony\AI\Platform\Message\MessageBag; |
| 20 | +use Symfony\Component\Clock\Clock as SymfonyClock; |
| 21 | + |
| 22 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 23 | + |
| 24 | +$platform = PlatformFactory::create(env('DEEPSEEK_API_KEY'), http_client()); |
| 25 | + |
| 26 | +$clock = new Clock(new SymfonyClock()); |
| 27 | +$toolbox = new Toolbox([$clock]); |
| 28 | +$toolProcessor = new ToolProcessor($toolbox); |
| 29 | +$structuredOutputProcessor = new StructuredOutputProcessor(); |
| 30 | +$agent = new Agent($platform, 'deepseek-chat', [$toolProcessor, $structuredOutputProcessor], [$toolProcessor, $structuredOutputProcessor]); |
| 31 | + |
| 32 | +$messages = new MessageBag( |
| 33 | + // for DeepSeek it is *mandatory* to mention JSON anywhere in the prompt when using structured output |
| 34 | + Message::forSystem('Respond in JSON as instructed in the response format.'), |
| 35 | + Message::ofUser('What date and time is it?') |
| 36 | +); |
| 37 | +$result = $agent->call($messages, ['response_format' => [ |
| 38 | + 'type' => 'json_object', |
| 39 | + 'json_object' => [ |
| 40 | + 'name' => 'clock', |
| 41 | + 'strict' => true, |
| 42 | + 'schema' => [ |
| 43 | + 'type' => 'object', |
| 44 | + 'properties' => [ |
| 45 | + 'date' => ['type' => 'string', 'description' => 'The current date in the format YYYY-MM-DD.'], |
| 46 | + 'time' => ['type' => 'string', 'description' => 'The current time in the format HH:MM:SS.'], |
| 47 | + ], |
| 48 | + 'required' => ['date', 'time'], |
| 49 | + 'additionalProperties' => false, |
| 50 | + ], |
| 51 | + ], |
| 52 | +]]); |
| 53 | + |
| 54 | +dump($result->getContent()); |
0 commit comments