DEV Community

Cover image for php-bard-api
John Pinto
John Pinto

Posted on

2 1

php-bard-api

php-bard-api

A package that returns Response of Google Bard through API

Prerequisites

  • PHP 8.1
  • composer

Install

 composer require pj8912/php-bard-api
Enter fullscreen mode Exit fullscreen mode

Usage

<?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);
?>
Enter fullscreen mode Exit fullscreen mode

Github

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

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay