> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel AI SDK 整合

> 說明如何在 Laravel Copilot SDK 中啟用實驗性的 Laravel AI SDK 整合，並使用文字生成與串流。

## Laravel AI SDK 整合

* 實驗性實作
* 僅支援文字生成，其他功能尚未支援。

僅在安裝 Laravel AI SDK 時才會啟用的 opt-in 功能。

```shell theme={null}
composer require laravel/ai
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
```

於 `config/ai.php` 中新增設定。

```php theme={null}
// config/ai.php
    'default' => 'copilot',

    'providers' => [
        'copilot' => [
            'driver' => 'copilot',
            'key' => '',
        ],
    ],
```

使用 `agent()` 輔助函式的方式如下。

```php theme={null}
use function Laravel\Ai\agent;

$response = agent(
    instructions: 'You are an expert at software development.',
)->prompt('Tell me about Laravel');

echo $response->text;
```

也支援串流。除 `TextDelta` 以外尚未實作。

```php theme={null}
use Laravel\Ai\Streaming\Events\TextDelta;

use function Laravel\Ai\agent;

$stream = agent(
    instructions: 'You are an expert at software development.',
)->stream('Tell me about Laravel');

foreach ($stream as $event) {
    if ($event instanceof TextDelta) {
        echo $event->delta;
    }
}
```

也可以像一般 Laravel AI SDK 一樣建立 Agent 類別，但僅支援部分功能。

<Info>
  最新資訊請參考 [GitHub 儲存庫](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [Laravel AI SDK 整合 - VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/ai-sdk.md)
- [Engine API 模式:Talk(文字語音合成)- VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/engine-talk.md)
- [VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/index.md)
- [Laravel AI SDK 的 Amazon Bedrock 驅動](/zh-TW/packages/laravel-amazon-bedrock.md)
- [Laravel AI Agent 支援 MCP 伺服器](/zh-TW/blog/ai-sdk-mcp-client.md)
