adachsoft/ai-integration-gemini-via-openai 问题修复 & 功能扩展

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

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

adachsoft/ai-integration-gemini-via-openai

Composer 安装命令:

composer require adachsoft/ai-integration-gemini-via-openai

包简介

Gemini provider for adachsoft/ai-integration using the official OpenAI-compatible endpoint.

README 文档

README

Gemini provider for adachsoft/ai-integration using the official OpenAI-compatible chat completions endpoint exposed by Google.

This package exposes a ready-to-use SPI provider that can be registered under the id gemini-via-openai in the core ToolCallingChatFacadeBuilder and used for tool-calling chat scenarios.

Installation

composer require adachsoft/ai-integration adachsoft/ai-integration-gemini-via-openai

Configuration

Set the following environment variable (for example in your .env file at the project root):

  • GOOGLE_GEMINI_API_KEY – API key for the Gemini OpenAI-compatible endpoint.

Usage

use AdachSoft\AiIntegration\PublicApi\Builder\ToolCallingChatFacadeBuilder;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ChatMessageDto;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\Collection\ChatMessageDtoCollection;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\Collection\ToolDefinitionDtoCollection;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ToolCallingChatRequestDto;
use AdachSoft\AiIntegration\PublicApi\ToolCalling\Dto\ToolDefinitionDto;
use AdachSoft\AiIntegrationGeminiViaOpenAi\GeminiViaOpenAiToolCallingChatSpiFactory;

$apiKey = getenv('GOOGLE_GEMINI_API_KEY');

$spi = GeminiViaOpenAiToolCallingChatSpiFactory::create($apiKey);

$facade = ToolCallingChatFacadeBuilder::create()
    ->withSpiProvider('gemini-via-openai', $spi)
    ->build();

$tools = new ToolDefinitionDtoCollection([
    new ToolDefinitionDto(
        name: 'echo_tool',
        description: 'Echoes back the provided input string.',
        parametersSchema: [
            'type' => 'object',
            'properties' => [
                'text' => [
                    'type' => 'string',
                    'description' => 'Text to echo back',
                ],
            ],
            'required' => ['text'],
        ],
    ),
]);

$messages = new ChatMessageDtoCollection([
    ChatMessageDto::createUserMessage('Call echo_tool with some example text.'),
]);

$request = new ToolCallingChatRequestDto(
    providerId: 'gemini-via-openai',
    modelId: 'gemini-2.0-flash',
    messages: $messages,
    tools: $tools,
);

$response = $facade->chat($request);

Smoke test

A simple smoke script is provided for manual end-to-end verification:

echo "GOOGLE_GEMINI_API_KEY=your_api_key_here" >> .env
php bin/smoke-gemini-via-openai-tool-chat

The script will perform a single tool-calling chat request using the gemini-2.0-flash model and print the response in JSON form.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固