-
-
Notifications
You must be signed in to change notification settings - Fork 102
[Platform] Add Scaleway #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
use Symfony\AI\Platform\Message\Message; | ||
use Symfony\AI\Platform\Message\MessageBag; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::OPENAI_OSS); | ||
|
||
$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); | ||
|
||
echo $result->asText().\PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\Scaleway\Embeddings; | ||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
|
||
$result = $platform->invoke(new Embeddings(), <<<TEXT | ||
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers. | ||
The people of Japan were very kind and hardworking. They loved their country very much and took care of it. The | ||
country was very peaceful and prosperous. The people lived happily ever after. | ||
TEXT); | ||
|
||
print_vectors($result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
use Symfony\AI\Platform\Message\Message; | ||
use Symfony\AI\Platform\Message\MessageBag; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::OPENAI_OSS); | ||
|
||
$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, ['stream' => true]); | ||
|
||
foreach ($result->getResult()->getContent() as $word) { | ||
echo $word; | ||
} | ||
echo \PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Agent\Agent; | ||
use Symfony\AI\Agent\StructuredOutput\AgentProcessor; | ||
use Symfony\AI\Fixtures\StructuredOutput\MathReasoning; | ||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
use Symfony\AI\Platform\Message\Message; | ||
use Symfony\AI\Platform\Message\MessageBag; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::OPENAI_OSS); | ||
|
||
$processor = new AgentProcessor(); | ||
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger()); | ||
$messages = new MessageBag( | ||
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'), | ||
Message::ofUser('how can I solve 8x + 7 = -23'), | ||
); | ||
$result = $agent->call($messages, ['output_structure' => MathReasoning::class]); | ||
|
||
dump($result->getContent()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Agent\Agent; | ||
use Symfony\AI\Agent\Toolbox\AgentProcessor; | ||
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber; | ||
use Symfony\AI\Agent\Toolbox\Toolbox; | ||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
use Symfony\AI\Platform\Message\Message; | ||
use Symfony\AI\Platform\Message\MessageBag; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::OPENAI_OSS); | ||
|
||
$transcriber = new YouTubeTranscriber(http_client()); | ||
$toolbox = new Toolbox([$transcriber], logger: logger()); | ||
$processor = new AgentProcessor($toolbox); | ||
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger()); | ||
|
||
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s')); | ||
$result = $agent->call($messages, ['stream' => true]); | ||
|
||
foreach ($result->getContent() as $word) { | ||
echo $word; | ||
} | ||
echo \PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Agent\Agent; | ||
use Symfony\AI\Agent\Toolbox\AgentProcessor; | ||
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber; | ||
use Symfony\AI\Agent\Toolbox\Toolbox; | ||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
use Symfony\AI\Platform\Message\Message; | ||
use Symfony\AI\Platform\Message\MessageBag; | ||
|
||
require_once dirname(__DIR__).'/bootstrap.php'; | ||
|
||
$platform = PlatformFactory::create(env('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::OPENAI_OSS); | ||
|
||
$transcriber = new YouTubeTranscriber(http_client()); | ||
$toolbox = new Toolbox([$transcriber], logger: logger()); | ||
$processor = new AgentProcessor($toolbox); | ||
$agent = new Agent($platform, $model, [$processor], [$processor], logger: logger()); | ||
|
||
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s')); | ||
$result = $agent->call($messages); | ||
|
||
echo $result->getContent().\PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\AI\Platform\Bridge\Scaleway\PlatformFactory; | ||
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway; | ||
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('SCALEWAY_SECRET_KEY'), http_client()); | ||
$model = new Scaleway(Scaleway::MISTRAL_PIXTRAL); | ||
|
||
$messages = new MessageBag( | ||
Message::ofUser( | ||
'Describe this image in 1 sentence. What is the object in the image?', | ||
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'), | ||
), | ||
); | ||
$result = $platform->invoke($model, $messages); | ||
|
||
echo $result->asText().\PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\AI\Platform\Bridge\Scaleway; | ||
|
||
use Symfony\AI\Platform\Model; | ||
|
||
/** | ||
* @author Marcus Stöhr <marcus@fischteich.net> | ||
*/ | ||
final class Embeddings extends Model | ||
{ | ||
public const BAAI_BGE = 'bge-multilingual-gemma2'; | ||
|
||
/** | ||
* @param array<string, mixed> $options | ||
*/ | ||
public function __construct(string $name = self::BAAI_BGE, array $options = []) | ||
{ | ||
parent::__construct($name, [], $options); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/platform/src/Bridge/Scaleway/Embeddings/ModelClient.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\AI\Platform\Bridge\Scaleway\Embeddings; | ||
|
||
use Symfony\AI\Platform\Bridge\Scaleway\Embeddings; | ||
use Symfony\AI\Platform\Exception\InvalidArgumentException; | ||
use Symfony\AI\Platform\Model; | ||
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory; | ||
use Symfony\AI\Platform\Result\RawHttpResult; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @author Marcus Stöhr <marcus@fischteich.net> | ||
*/ | ||
final readonly class ModelClient implements PlatformResponseFactory | ||
{ | ||
public function __construct( | ||
private HttpClientInterface $httpClient, | ||
#[\SensitiveParameter] private string $apiKey, | ||
) { | ||
if ('' === $apiKey) { | ||
throw new InvalidArgumentException('The API key must not be empty.'); | ||
} | ||
} | ||
|
||
public function supports(Model $model): bool | ||
{ | ||
return $model instanceof Embeddings; | ||
} | ||
|
||
public function request(Model $model, array|string $payload, array $options = []): RawHttpResult | ||
{ | ||
return new RawHttpResult($this->httpClient->request('POST', 'https://api.scaleway.ai/v1/embeddings', [ | ||
'auth_bearer' => $this->apiKey, | ||
'json' => array_merge($options, [ | ||
'model' => $model->getName(), | ||
'input' => $payload, | ||
]), | ||
])); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.