bdowson/simple-gemini 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bdowson/simple-gemini

最新稳定版本:v1.0.0

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:

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!

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-17