aisdk/google
Composer 安装命令:
composer require aisdk/google
包简介
Official Google Gemini provider for the PHP AI SDK.
README 文档
README
Official Google Gemini provider for the PHP AI SDK.
Installation
composer require aisdk/google
Basic Usage
use AiSdk\Generate; use AiSdk\Google; $result = Generate::text() ->model(Google::model('gemini-3.5-flash')) ->instructions('Write short, clear answers.') ->prompt('Explain closures in PHP.') ->run(); echo $result->text;
Configuration
| Variable | Description | Default |
|---|---|---|
GOOGLE_GENERATIVE_AI_API_KEY |
API key for authentication | Required |
GEMINI_API_KEY |
Fallback API key variable | Required |
GOOGLE_GENERATIVE_AI_BASE_URL |
Base URL for API requests | https://generativelanguage.googleapis.com/v1beta |
Google::create([ 'apiKey' => '...', 'baseUrl' => 'https://generativelanguage.googleapis.com/v1beta', ]);
Streaming
$stream = Generate::text('Tell me a story.') ->model(Google::model('gemini-3.5-flash')) ->stream(); foreach ($stream->chunks() as $chunk) { echo $chunk; } $result = $stream->run();
Image Generation
use AiSdk\Generate; use AiSdk\Google; $result = Generate::image() ->model(Google::image('gemini-3.1-flash-image')) ->prompt('A clean app icon for a PHP AI SDK') ->aspectRatio('1:1') ->run(); $result->output->save(__DIR__.'/icon.png');
Provider-Specific Options
$result = Generate::text('Hello') ->model(Google::model('gemini-3.5-flash')) ->providerOptions('google', [ 'raw' => [ 'generation_config' => ['temperature' => 0.2], 'store' => false, ], ]) ->run();
Testing
composer test
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-07