檔案附件
以下方式將檔案或目錄以陣列指定。use Revolution\Copilot\Facades\Copilot;
$attachments = [
[
'type' => 'file',
'path' => '/path/to/file.php',
'displayName' => 'My File',// 可省略
],
[
'type' => 'directory',
'path' => '/path/to/dir/',
'displayName' => 'dir',// 可省略
],
[
'type' => 'selection',
'filePath' => '/path/to/file.php',
'displayName' => 'My File',// 此處不可省略
'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',// 可省略
],
];
$response = Copilot::run(prompt: '...', attachments: $attachments);
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 附件
blob 類型用於將 Base64 編碼的資料以 inline 方式附加。可以在不做磁碟 I/O 的情況下直接傳送圖像等二進位資料。
use Revolution\Copilot\Support\Attachment;
// 將圖像檔以 Base64 編碼後附加
$attachment = Attachment::blob(
data: base64_encode(file_get_contents('/path/to/image.png')),
mimeType: 'image/png',
displayName: 'screenshot.png',
);
selection 在官方 SDK 尚無文件,因此細節不明。github_reference 也因官方資訊不足,將於後續支援。最新資訊請參考 GitHub 儲存庫。