定制 potato/ai-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

potato/ai-bridge

Composer 安装命令:

composer require potato/ai-bridge

包简介

Multi-LLM AI Connector

README 文档

README

A simple PHP package to interact with various AI engines, providing a unified interface for sending prompts and receiving responses.

Installation

Install the package via Composer:

composer require potato/ai-bridge

Usage

The main entry point of the package is the Potato\AiBridge\Agent class. You can create an agent for a specific AI engine and use it to send prompts.

Here is a basic example of how to use the package:

<?php

// 1. Require the Composer autoloader
require_once __DIR__ . '/vendor/autoload.php';

// 2. Use the Agent class
use Potato\AiBridge\Agent;

// 3. Create an agent for your desired AI engine (e.g., 'gemini' or 'gpt')
$apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
$agent = Agent::create('gemini', $apiKey);

// 4. Define the model and the instructions for the AI
$model = 'gemini-pro'; // Specify the model you want to use
$instructions = [
    'You are a helpful assistant.',
    'Translate the following English text to French: "Hello, world!"',
];

// 5. Send the prompt to the AI and get the response
try {
    $response = $agent->prompt($model, $instructions);
    echo $response;
} catch (Exception $e) {
    // Handle potential exceptions, e.g., network errors or invalid API keys
    echo 'An error occurred: ' . $e->getMessage();
}

Instructions

The prompt method takes an array of strings as instructions. These instructions are concatenated into a single prompt that is sent to the AI engine. Each string in the array will be treated as a separate line in the prompt.

Supported Engines

Currently, the following AI engines are supported:

  • GPT (gpt)
  • Gemini (gemini)

You can select the engine when creating the Agent instance.

Testing

The package comes with a suite of tests written with PHPUnit. To run the tests, execute the following command from the root directory of the project:

./vendor/bin/phpunit

This will run all the unit tests and ensure that the package is working correctly.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-13