bdowson/simple-gemini
Composer 安装命令:
composer require bdowson/simple-gemini
包简介
A lightweight PHP package to send prompts to Google's Gemini AI and retrieve responses.
README 文档
README
Simple Gemini is a lightweight PHP package that lets you send prompts to Google's Gemini AI and retrieve generated responses. It handles authentication using your Google service account credentials and makes API calls to the Google Cloud AI Platform.
Note: You must have a valid Google service account JSON file with the necessary permissions and your Google Cloud project must be properly configured.
Table of Contents
Installation
Install the package via Composer:
composer require bdowson/simple-gemini
Usage
Below is a simple example to get you started:
<?php require 'vendor/autoload.php'; use SimpleGemini\SimpleGemini; use SimpleGemini\Exceptions\SimpleGeminiException; try { $googleCredentialsPath = '/path/to/credentials.json'; $project = 'your-project-id'; $location = 'asia-southeast1'; $model = 'gemini-1.5-flash-002'; // Optional: Specify generation configuration and safety settings $generationConfig = [ 'maxOutputTokens' => 8000, // Additional configuration parameters (e.g., temperature, topP, etc.) can be added here. ]; $safetySettings = [ // Optional safety settings can be specified here. ]; // Instantiate the SimpleGemini client $simpleGemini = new SimpleGemini( $googleCredentialsPath, $project, $location, $model, $generationConfig, $safetySettings ); // Send a prompt and get the generated response $prompt = "Write me a poem about software development"; $response = $simpleGemini->prompt($prompt); echo "AI Response:\n" . $response . "\n"; } catch (SimpleGeminiException $e) { echo "An error occurred: " . $e->getMessage() . "\n"; }
Configuration
When creating a new instance of SimpleGemini, you need to provide:
-
Google Credentials Path:
The file path to your Google service account JSON file. -
Project:
Your Google Cloud project ID. -
Location:
The location/region where your model is hosted. See here for supported locations: https://cloud.google.com/vertex-ai/docs/general/locations#available-regions -
Model:
The name of the model you want to use. See here for supported models: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#supported-models -
Generation Config (Optional):
An array of configuration options for text generation. For example:$generationConfig = [ 'maxOutputTokens' => 8000, 'temperature' => 1, // You can also include other parameters like 'topP', 'topK', etc. ];
For more options, see here: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig
-
Safety Settings (Optional):
An array specifying safety settings for the generated content. Available settings: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#safetysetting
To DOs
- Automated testing
- Improve documentation
License
This project is licensed under the GNU General Public License. See the LICENSE file for details.
Support
If you encounter issues or have suggestions, please open an issue on this repo
Happy coding!
bdowson/simple-gemini 适用场景与选型建议
bdowson/simple-gemini 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「ai」 「Gemini」 「llm」 「google-ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bdowson/simple-gemini 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bdowson/simple-gemini 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bdowson/simple-gemini 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
AI Agent templates for Laravel development - Skills, Agents, and Workflows for enhanced coding assistance
AI discussion summaries for Flarum with real-time streaming.
Alfabank REST API integration
Official Google Gemini provider for the PHP AI SDK.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-17