File attachments
按如下方式以数组形式指定文件或目录。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 attachments
blob 类型用于以内联方式附加 Base64 编码的数据。可以在没有磁盘 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 仓库。