php-bard-api
#ai #php #library #bard

php-bard-api

通过API返回Google bard响应的软件包

先决条件

  • PHP 8.1
  • 作曲家

安装

 composer require pj8912/php-bard-api

用法

<?php
require_once 'vendor/autoload.php';
use Pj8912\PhpBardApi\Bard;

$_ENV['_BARD_API_KEY'] = "Your Key";

$bard = new Bard();
$input_text = "Hello, Bard!";  // Input text for the conversation
$result = $bard->get_answer($input_text);  

// Access the result data
$conversation_id = $result["conversation_id"];
$response_id = $result["response_id"];
$factualityQueries = $result["factualityQueries"];
$textQuery = $result["textQuery"];
$choices = $result["choices"];

// reply for query 
$content = $result["content"];
print($content);
?>

github

https://github.com/pj8912/php-bard-api