Vai al contenuto principale

File attachments

Specifica file o directory in un array come segue.
use Revolution\Copilot\Facades\Copilot;

$attachments = [
    [
        'type' => 'file',
        'path' => '/path/to/file.php',
        'displayName' => 'My File',// opzionale
    ],
    [
        'type' => 'directory',
        'path' => '/path/to/dir/',
        'displayName' => 'dir',// opzionale
    ],
    [
        'type' => 'selection',
        'filePath' => '/path/to/file.php',
        'displayName' => 'My File',// non omissibile qui
        'selection' => [
            'start' => ['line' => 1, 'character' => 10],
            'end' => ['line' => 5, 'character' => 10],
        ],
        'text' => '...',
    ],
    [
        'type' => 'blob',
        'data' => base64_encode(file_get_contents('/path/to/image.png')),
        'mimeType' => 'image/png',
        'displayName' => 'screenshot.png',// opzionale
    ],
];

$response = Copilot::run(prompt: '...', attachments: $attachments);
Poiché ricordare questo formato è difficile, sono disponibili degli helper per semplificarne l’uso.
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Support\Attachment;

$attachments = [
    Attachment::file(path: '/path/to/file.php', displayName: 'My File'),
    Attachment::directory(path: '/path/to/dir/', displayName: 'dir'),
    Attachment::selection(filePath: '/path/to/file.php', displayName: 'My File', selection: ['start' => ['line' => 1, 'character' => 10], 'end' => ['line' => 5, 'character' => 10]], text: '...'),
    Attachment::blob(data: base64_encode(file_get_contents('/path/to/image.png')), mimeType: 'image/png', displayName: 'screenshot.png'),
];

$response = Copilot::run(prompt: '...', attachments: $attachments);

Blob attachments

Il tipo blob viene utilizzato per allegare inline dati codificati in Base64. Puoi inviare direttamente dati binari come immagini senza I/O su disco.
use Revolution\Copilot\Support\Attachment;

// Allega un file immagine codificato in Base64
$attachment = Attachment::blob(
    data: base64_encode(file_get_contents('/path/to/image.png')),
    mimeType: 'image/png',
    displayName: 'screenshot.png',
);
selection non è ancora documentato nell’SDK ufficiale, quindi i dettagli non sono chiari. Anche github_reference mancano di informazioni ufficiali e sarà supportato in futuro.
Per le informazioni più recenti fai riferimento al repository GitHub.
Ultima modifica il 13 luglio 2026