Skip to content

Commit 5a162c5

Browse files
committed
feat(platform): add scaleway platform
1 parent 4eee553 commit 5a162c5

23 files changed

+1225
-0
lines changed

examples/scaleway/chat.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\Platform\Bridge\Scaleway\PlatformFactory;
13+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
14+
use Symfony\AI\Platform\Message\Message;
15+
use Symfony\AI\Platform\Message\MessageBag;
16+
17+
require_once dirname(__DIR__).'/bootstrap.php';
18+
19+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
20+
$model = new Scaleway(Scaleway::OPENAI_OSS);
21+
22+
$messages = new MessageBag(
23+
Message::forSystem('You are a pirate and you write funny.'),
24+
Message::ofUser('What is the Symfony framework?'),
25+
);
26+
$result = $platform->invoke($model, $messages);
27+
28+
echo $result->asText().\PHP_EOL;

examples/scaleway/embeddings.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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\Platform\Bridge\Scaleway\Embeddings;
13+
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory;
14+
15+
require_once dirname(__DIR__).'/bootstrap.php';
16+
17+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
18+
19+
$result = $platform->invoke(new Embeddings(), <<<TEXT
20+
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
21+
The people of Japan were very kind and hardworking. They loved their country very much and took care of it. The
22+
country was very peaceful and prosperous. The people lived happily ever after.
23+
TEXT);
24+
25+
print_vectors($result);

examples/scaleway/stream.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Platform\Bridge\Scaleway\PlatformFactory;
13+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
14+
use Symfony\AI\Platform\Message\Message;
15+
use Symfony\AI\Platform\Message\MessageBag;
16+
17+
require_once dirname(__DIR__).'/bootstrap.php';
18+
19+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
20+
$model = new Scaleway(Scaleway::OPENAI_OSS);
21+
22+
$messages = new MessageBag(
23+
Message::forSystem('You are a pirate and you write funny.'),
24+
Message::ofUser('What is the Symfony framework?'),
25+
);
26+
$result = $platform->invoke($model, $messages, ['stream' => true]);
27+
28+
foreach ($result->getResult()->getContent() as $word) {
29+
echo $word;
30+
}
31+
echo \PHP_EOL;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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;
14+
use Symfony\AI\Fixtures\StructuredOutput\MathReasoning;
15+
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory;
16+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
17+
use Symfony\AI\Platform\Message\Message;
18+
use Symfony\AI\Platform\Message\MessageBag;
19+
20+
require_once dirname(__DIR__).'/bootstrap.php';
21+
22+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
23+
$model = new Scaleway(Scaleway::OPENAI_OSS);
24+
25+
$processor = new AgentProcessor();
26+
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger());
27+
$messages = new MessageBag(
28+
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
29+
Message::ofUser('how can I solve 8x + 7 = -23'),
30+
);
31+
$result = $agent->call($messages, ['output_structure' => MathReasoning::class]);
32+
33+
dump($result->getContent());
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Toolbox\AgentProcessor;
14+
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber;
15+
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory;
17+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
18+
use Symfony\AI\Platform\Message\Message;
19+
use Symfony\AI\Platform\Message\MessageBag;
20+
21+
require_once dirname(__DIR__).'/bootstrap.php';
22+
23+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
24+
$model = new Scaleway(Scaleway::OPENAI_OSS);
25+
26+
$transcriber = new YouTubeTranscriber(http_client());
27+
$toolbox = new Toolbox([$transcriber], logger: logger());
28+
$processor = new AgentProcessor($toolbox);
29+
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger());
30+
31+
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s'));
32+
$result = $agent->call($messages, ['stream' => true]);
33+
34+
foreach ($result->getContent() as $word) {
35+
echo $word;
36+
}
37+
echo \PHP_EOL;

examples/scaleway/toolcall.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Toolbox\AgentProcessor;
14+
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber;
15+
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory;
17+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
18+
use Symfony\AI\Platform\Message\Message;
19+
use Symfony\AI\Platform\Message\MessageBag;
20+
21+
require_once dirname(__DIR__).'/bootstrap.php';
22+
23+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
24+
$model = new Scaleway(Scaleway::OPENAI_OSS);
25+
26+
$transcriber = new YouTubeTranscriber(http_client());
27+
$toolbox = new Toolbox([$transcriber], logger: logger());
28+
$processor = new AgentProcessor($toolbox);
29+
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger());
30+
31+
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s'));
32+
$result = $agent->call($messages);
33+
34+
echo $result->getContent().\PHP_EOL;

examples/scaleway/vision.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Platform\Bridge\Scaleway\PlatformFactory;
13+
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
14+
use Symfony\AI\Platform\Message\Content\Image;
15+
use Symfony\AI\Platform\Message\Message;
16+
use Symfony\AI\Platform\Message\MessageBag;
17+
18+
require_once dirname(__DIR__).'/bootstrap.php';
19+
20+
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client());
21+
$model = new Scaleway(Scaleway::MISTRAL_PIXTRAL);
22+
23+
$messages = new MessageBag(
24+
Message::ofUser(
25+
'Describe this image in 1 sentence. What is the object in the image?',
26+
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
27+
),
28+
);
29+
$result = $platform->invoke($model, $messages);
30+
31+
echo $result->asText().\PHP_EOL;

src/ai-bundle/config/options.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@
165165
->end()
166166
->end()
167167
->end()
168+
->arrayNode('scaleway')
169+
->children()
170+
->scalarNode('api_key')->isRequired()->end()
171+
->stringNode('http_client')
172+
->defaultValue('http_client')
173+
->info('Service ID of the HTTP client to use')
174+
->end()
175+
->end()
176+
->end()
168177
->end()
169178
->end()
170179
->arrayNode('agent')

src/ai-bundle/src/AiBundle.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
4545
use Symfony\AI\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
4646
use Symfony\AI\Platform\Bridge\Perplexity\PlatformFactory as PerplexityPlatformFactory;
47+
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory as ScalewayPlatformFactory;
4748
use Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory as VertexAiPlatformFactory;
4849
use Symfony\AI\Platform\Bridge\Voyage\PlatformFactory as VoyagePlatformFactory;
4950
use Symfony\AI\Platform\Exception\RuntimeException;
@@ -492,6 +493,23 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
492493
return;
493494
}
494495

496+
if ('scaleway' === $type && isset($platform['api_key'])) {
497+
$platformId = 'ai.platform.scaleway';
498+
$definition = (new Definition(Platform::class))
499+
->setFactory(ScalewayPlatformFactory::class.'::create')
500+
->setLazy(true)
501+
->addTag('proxy', ['interface' => PlatformInterface::class])
502+
->setArguments([
503+
$platform['api_key'],
504+
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
505+
])
506+
->addTag('ai.platform');
507+
508+
$container->setDefinition($platformId, $definition);
509+
510+
return;
511+
}
512+
495513
throw new InvalidArgumentException(\sprintf('Platform "%s" is not supported for configuration via bundle at this point.', $type));
496514
}
497515

src/platform/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CHANGELOG
2525
- Perplexity (Sonar models, supporting search results)
2626
- AI/ML API (language models and embeddings)
2727
- Docker Model Runner (local model hosting)
28+
- Scaleway (language models like OpenAI OSS, Llama 4, Qwen 3, and more)
2829
* Add comprehensive message system with role-based messaging:
2930
- `UserMessage` for user inputs with multi-modal content
3031
- `SystemMessage` for system instructions

0 commit comments

Comments
 (0)