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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 6 additions & 17 deletions demo/config/packages/ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,27 @@ ai:
api_key: '%env(OPENAI_API_KEY)%'
agent:
blog:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
model: 'gpt-4o-mini'
tools:
- 'Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch'
- service: 'clock'
name: 'clock'
description: 'Provides the current date and time.'
method: 'now'
stream:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
model: 'gpt-4o-mini'
prompt: |
You are an example chat application where messages from the LLM are streamed to the user using
Server-Sent Events via `symfony/ux-turbo` / Turbo Streams. This example does not use any custom
javascript and solely relies on the built-in `live` & `turbo_stream` Stimulus controllers.
Whatever the user asks, tell them about the application & used technologies.
tools: false
youtube:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
model: 'gpt-4o-mini'
tools: false
wikipedia:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
name: 'gpt-4o-mini'
options:
temperature: 0.5
prompt:
Expand All @@ -40,9 +33,7 @@ ai:
tools:
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
audio:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: 'gpt-4o-mini?temperature=1.0'
model: 'gpt-4o-mini?temperature=1.0'
prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
tools:
# Agent in agent 🤯
Expand All @@ -55,9 +46,7 @@ ai:
collection: 'symfony_blog'
vectorizer:
openai:
model:
class: 'Symfony\AI\Platform\Bridge\OpenAi\Embeddings'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_ADA_002
model: 'text-embedding-ada-002'
indexer:
blog:
loader: 'Symfony\AI\Store\Document\Loader\RssFeedLoader'
Expand Down
4 changes: 1 addition & 3 deletions examples/aimlapi/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Platform\Bridge\AiMlApi\Completions;
use Symfony\AI\Platform\Bridge\AiMlApi\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('AIMLAPI_API_KEY'), http_client());
$model = new Completions(Completions::GEMINI_2_0_FLASH);

$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $platform->invoke($model, $messages, [
$result = $platform->invoke('gemini-2.0-flash', $messages, [
'max_tokens' => 500, // specific options just for this call
]);

Expand Down
8 changes: 1 addition & 7 deletions examples/aimlapi/image-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Platform\Bridge\AiMlApi\Completions;
use Symfony\AI\Platform\Bridge\AiMlApi\PlatformFactory;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Message\Content\Image;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('AIMLAPI_API_KEY'), http_client());
$model = new Completions(
name: Completions::GOOGLE_GEMMA_3_27B_IT,
capabilities: [...Completions::DEFAULT_CAPABILITIES, Capability::INPUT_IMAGE]
);

$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Expand All @@ -31,6 +25,6 @@
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$result = $platform->invoke($model, $messages);
$result = $platform->invoke('google/gemma-3-27b-it', $messages);

echo $result->getResult()->getContent().\PHP_EOL;
8 changes: 1 addition & 7 deletions examples/aimlapi/toolcall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@
use Symfony\AI\Agent\Toolbox\AgentProcessor;
use Symfony\AI\Agent\Toolbox\Tool\Wikipedia;
use Symfony\AI\Agent\Toolbox\Toolbox;
use Symfony\AI\Platform\Bridge\AiMlApi\Completions;
use Symfony\AI\Platform\Bridge\AiMlApi\PlatformFactory;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('AIMLAPI_API_KEY'), http_client());
$model = new Completions(
name: Completions::GOOGLE_GEMINI_2_5_FLASH,
capabilities: [...Completions::DEFAULT_CAPABILITIES, Capability::TOOL_CALLING]
);

$wikipedia = new Wikipedia(http_client());
$toolbox = new Toolbox([$wikipedia], logger: logger());
$processor = new AgentProcessor($toolbox);
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger());
$agent = new Agent($platform, 'google/gemini-2.5-flash', [$processor], [$processor], logger: logger());

$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
$result = $agent->call($messages);
Expand Down
6 changes: 1 addition & 5 deletions examples/aimlapi/vectorizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Platform\Bridge\AiMlApi\Embeddings;
use Symfony\AI\Platform\Bridge\AiMlApi\PlatformFactory;
use Symfony\AI\Store\Document\Vectorizer;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('AIMLAPI_API_KEY'), http_client());
$embeddings = new Embeddings(
name: Embeddings::TEXT_EMBEDDING_3_SMALL
);

$vectorizer = new Vectorizer($platform, $embeddings);
$vectorizer = new Vectorizer($platform, 'text-embedding-3-small');

$string = 'Hello World';
$vector = $vectorizer->vectorize($string);
Expand Down
5 changes: 1 addition & 4 deletions examples/albert/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
*/

use Symfony\AI\Platform\Bridge\Albert\PlatformFactory;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

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

$model = new Gpt('gpt-4o');

$documentContext = <<<'CONTEXT'
Document: AI Strategy of France

Expand All @@ -42,6 +39,6 @@
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
);

$result = $platform->invoke($model, $messages);
$result = $platform->invoke('llama-3.3-70b-instruct', $messages);

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

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$result = $platform->invoke($model, $messages);
$result = $platform->invoke('claude-3-5-sonnet-20241022', $messages);

echo $result->getResult()->getContent().\PHP_EOL;
4 changes: 1 addition & 3 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\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Image;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -18,7 +17,6 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Expand All @@ -27,6 +25,6 @@
'Describe this image.',
),
);
$result = $platform->invoke($model, $messages);
$result = $platform->invoke('claude-3-5-sonnet-20241022', $messages);

echo $result->getResult()->getContent().\PHP_EOL;
4 changes: 1 addition & 3 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\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\ImageUrl;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -18,7 +17,6 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Expand All @@ -27,6 +25,6 @@
'Describe this image.',
),
);
$result = $platform->invoke($model, $messages);
$result = $platform->invoke('claude-3-5-sonnet-20241022', $messages);

echo $result->getResult()->getContent().\PHP_EOL;
4 changes: 1 addition & 3 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\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\Document;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -18,14 +17,13 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$messages = new MessageBag(
Message::ofUser(
Document::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
'What is this document about?',
),
);
$result = $platform->invoke($model, $messages);
$result = $platform->invoke('claude-3-5-sonnet-20241022', $messages);

echo $result->getResult()->getContent().\PHP_EOL;
4 changes: 1 addition & 3 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\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Content\DocumentUrl;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -18,14 +17,13 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

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

echo $result->getResult()->getContent().\PHP_EOL;
4 changes: 1 addition & 3 deletions examples/anthropic/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
* file that was distributed with this source code.
*/

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$messages = new MessageBag(
Message::forSystem('You are a thoughtful philosopher.'),
Message::ofUser('What is the purpose of an ant?'),
);
$result = $platform->invoke($model, $messages, ['stream' => true]);
$result = $platform->invoke('claude-3-5-sonnet-20241022', $messages, ['stream' => true]);

print_stream($result);
4 changes: 1 addition & 3 deletions examples/anthropic/token-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Bridge\Anthropic\TokenOutputProcessor;
use Symfony\AI\Platform\Message\Message;
Expand All @@ -19,9 +18,8 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), http_client());
$model = new Claude(Claude::SONNET_37);

$agent = new Agent($platform, $model, outputProcessors: [new TokenOutputProcessor()], logger: logger());
$agent = new Agent($platform, 'claude-3-5-sonnet-20241022', outputProcessors: [new TokenOutputProcessor()], logger: logger());
$messages = new MessageBag(
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
Expand Down
4 changes: 1 addition & 3 deletions examples/anthropic/toolcall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
use Symfony\AI\Agent\Toolbox\AgentProcessor;
use Symfony\AI\Agent\Toolbox\Tool\Wikipedia;
use Symfony\AI\Agent\Toolbox\Toolbox;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);

$wikipedia = new Wikipedia(http_client());
$toolbox = new Toolbox([$wikipedia], logger: logger());
$processor = new AgentProcessor($toolbox);
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger());
$agent = new Agent($platform, 'claude-3-5-sonnet-20241022', [$processor], [$processor], logger: logger());

$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
$result = $agent->call($messages);
Expand Down
4 changes: 1 addition & 3 deletions examples/azure/audio-transcript.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory;
use Symfony\AI\Platform\Bridge\OpenAi\Whisper;
use Symfony\AI\Platform\Message\Content\Audio;

require_once dirname(__DIR__).'/bootstrap.php';
Expand All @@ -22,9 +21,8 @@
env('AZURE_OPENAI_KEY'),
http_client(),
);
$model = new Whisper(Whisper::WHISPER_1);
$file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3');

$result = $platform->invoke($model, $file);
$result = $platform->invoke('whisper-1', $file);

echo $result->asText().\PHP_EOL;
Loading