Pièces jointes de fichiers
Spécifiez fichiers ou répertoires sous forme de tableau comme suit.
use Revolution\Copilot\Facades\Copilot;
$attachments = [
[
'type' => 'file',
'path' => '/path/to/file.php',
'displayName' => 'My File',// facultatif
],
[
'type' => 'directory',
'path' => '/path/to/dir/',
'displayName' => 'dir',// facultatif
],
[
'type' => 'selection',
'filePath' => '/path/to/file.php',
'displayName' => 'My File',// requis
'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',// facultatif
],
];
$response = Copilot::run(prompt: '...', attachments: $attachments);
Comme ce format est difficile à mémoriser, un helper est fourni pour en faciliter l’usage.
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);
Pièces jointes de type Blob
Le type blob sert à attacher inline des données encodées en Base64. Vous pouvez envoyer directement des données binaires (images, etc.) sans passer par des E/S disque.
use Revolution\Copilot\Support\Attachment;
// Encode un fichier image en Base64 et l'attache
$attachment = Attachment::blob(
data: base64_encode(file_get_contents('/path/to/image.png')),
mimeType: 'image/png',
displayName: 'screenshot.png',
);
selection n’est pas encore documenté dans le SDK officiel, les détails restent flous. github_reference est également peu documenté officiellement et sera pris en charge ultérieurement.