Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/albert/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Albert\PlatformFactory;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -20,7 +19,6 @@
$platform = PlatformFactory::create(env('ALBERT_API_KEY'), env('ALBERT_API_URL'), http_client());

$model = new Gpt('gpt-4o');
$agent = new Agent($platform, $model, logger: logger());

$documentContext = <<<'CONTEXT'
Document: AI Strategy of France
Expand All @@ -44,6 +42,6 @@
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
);

$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/anthropic/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -20,11 +19,10 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/anthropic/image-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Image;
Expand All @@ -21,14 +20,13 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Message::ofUser(
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
'Describe this image.',
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/anthropic/image-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\ImageUrl;
Expand All @@ -21,14 +20,13 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Message::ofUser(
new ImageUrl('https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg'),
'Describe this image.',
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/anthropic/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Document;
Expand All @@ -21,13 +20,12 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::ofUser(
Document::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
'What is this document about?',
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/anthropic/pdf-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\DocumentUrl;
Expand All @@ -21,13 +20,12 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::ofUser(
new DocumentUrl('https://upload.wikimedia.org/wikipedia/commons/2/20/Re_example.pdf'),
'What is this document about?',
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
8 changes: 2 additions & 6 deletions examples/anthropic/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -20,16 +19,13 @@
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude();

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a thoughtful philosopher.'),
Message::ofUser('What is the purpose of an ant?'),
);
$result = $agent->call($messages, [
'stream' => true, // enable streaming of response text
]);
$result = $platform->invoke($model, $messages, ['stream' => true]);

foreach ($result->getContent() as $word) {
foreach ($result->getResult()->getContent() as $word) {
echo $word;
}
echo \PHP_EOL;
6 changes: 2 additions & 4 deletions examples/azure/chat-gpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -26,11 +25,10 @@
);
$model = new Gpt(Gpt::GPT_4O_MINI);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/azure/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Azure\Meta\PlatformFactory;
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -20,14 +19,13 @@
$platform = PlatformFactory::create(env('AZURE_LLAMA_BASEURL'), env('AZURE_LLAMA_KEY'), http_client());
$model = new Llama(Llama::V3_3_70B_INSTRUCT);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
$result = $agent->call($messages, [
$result = $platform->invoke($model, $messages, [
'max_tokens' => 2048,
'temperature' => 0.8,
'top_p' => 0.1,
'presence_penalty' => 0,
'frequency_penalty' => 0,
]);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/bedrock/chat-claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -26,11 +25,10 @@
$platform = PlatformFactory::create();
$model = new Claude('claude-3-7-sonnet-20250219');

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You answer questions in short and concise manner.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/bedrock/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -26,11 +25,10 @@
$platform = PlatformFactory::create();
$model = new Llama(Llama::V3_2_3B_INSTRUCT);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/bedrock/chat-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -26,11 +25,10 @@
$platform = PlatformFactory::create();
$model = new Nova(Nova::PRO);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/bedrock/image-claude-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Image;
Expand All @@ -27,14 +26,13 @@
$platform = PlatformFactory::create();
$model = new Claude('claude-3-7-sonnet-20250219');

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Message::ofUser(
'Describe the image as a comedian would do it.',
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/bedrock/image-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Image;
Expand All @@ -27,14 +26,13 @@
$platform = PlatformFactory::create();
$model = new Nova(Nova::PRO);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Message::ofUser(
'Describe the image as a comedian would do it.',
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$result = $agent->call($messages);
$result = $platform->invoke($model, $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
6 changes: 2 additions & 4 deletions examples/cerebras/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Cerebras\Model;
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -19,11 +18,10 @@

$platform = PlatformFactory::create(env('CEREBRAS_API_KEY'), http_client());

$agent = new Agent($platform, new Model(), logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a helpful assistant.'),
Message::ofUser('How is the weather in Tokyo today?'),
);
$result = $agent->call($messages);
$result = $platform->invoke(new Model(), $messages);

echo $result->getContent().\PHP_EOL;
echo $result->getResult()->getContent().\PHP_EOL;
7 changes: 2 additions & 5 deletions examples/cerebras/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Cerebras\Model;
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -19,18 +18,16 @@

$platform = PlatformFactory::create(env('CEREBRAS_API_KEY'), http_client());

$agent = new Agent($platform, new Model(), logger: logger());

$messages = new MessageBag(
Message::forSystem('You are an expert in places and geography who always responds concisely.'),
Message::ofUser('What are the top three destinations in France?'),
);

$result = $agent->call($messages, [
$result = $platform->invoke(new Model(), $messages, [
'stream' => true,
]);

foreach ($result->getContent() as $word) {
foreach ($result->getResult()->getContent() as $word) {
echo $word;
}
echo \PHP_EOL;
Loading