PHP code example of cors / symfony-ai-506-platform

1. Go to this page and download the library: Download cors/symfony-ai-506-platform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cors / symfony-ai-506-platform example snippets


use CORS\AI\Platform\Bridge\Ai506\Factory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

$platform = Factory::createPlatform(
    host: 'acme',                 // "acme", "acme.506.ai" or "https://acme.506.ai:3003"
    organizationId: $_ENV['AI_506_ORGANIZATION_ID'],
    apiKey: $_ENV['AI_506_API_KEY'],
);

$messages = new MessageBag(
    Message::forSystem('You are a helpful baker.'),
    Message::ofUser('What is a Kornspitz?'),
);

echo $platform->invoke('gpt-4.1', $messages)->asText();

// config/bundles.php
return [
    // ...
    CORS\AI\Platform\Bridge\Ai506\Bundle\CORSAi506Bundle::class => ['all' => true],
];

use Symfony\AI\Platform\PlatformInterface;

public function __construct(
    private readonly PlatformInterface $ai506Platform,
) {
}

$result = $platform->invoke('gpt-4.1', $messages, ['stream' => true]);

foreach ($result->asStream() as $delta) {
    echo $delta;
}

final class Recipe
{
    public string $title;
    public int $servings;
    /** @var list<Ingredient> */
    public array $ingredients = [];
}

$recipe = $platform->invoke('gpt-4.1', $messages, ['response_format' => Recipe::class])->asObject();

$result = $platform->invoke('gpt-4.1', $messages, ['mode' => 'QA', 'data_collections' => ['…']])->getResult();
$references = $result->getMetadata()->get('references');