piscesCat / Bard-AI-Reverse-PHP

PHP Reverse Google Bard AI
MIT License
2 stars 1 forks source link

foreach() argument must be of type array|object, null given #1

Open stprasst opened 1 year ago

stprasst commented 1 year ago

Hi, i try the usage example and got foreach() argument must be of type array|object, null given
in this line : $answer = $bard->getAnswer('Hello');

piscesCat commented 1 year ago

Hi,

i try the usage example and got

foreach() argument must be of type array|object, null given

in this line :

$answer = $bard->getAnswer('Hello');

Idk what is the problem from your code, I send you this code.

image

<?php
require './vendor/autoload.php';

use KhaiPhan\Google\Bard;

header("Content-Type: text/plain");

session_start();

$message = 'images of cat';

$cookie = 'WghOI**********-*******.';
$i = array();
if (isset($_SESSION['i'])) {
    $i = $_SESSION['i'];
}
$ai = new Bard($cookie, $i);
$response = $ai->getAnswer($message);
$session = array (
    'conversation_id' => $response['conversation_id'],
    'response_id' => $response['response_id'],
    'choice_id' => $response['choice_id'],
    'request_id' => $response['request_id'],
    'session_id' => $response['session_id']
);
$_SESSION['i'] = $session;

var_dump($response);
jonvicbarcenas commented 1 year ago

Hi how to make it conversational?

piscesCat commented 1 year ago

Hi how to make it conversational?

according to the code i sent above, i used PHP session to save the conversation data, bard will continue the conversation after each new question to create new conversation just remove $i or set session_id, conversation_id,... value to null

$ai = new Bard($cookie);
$i = array (
    'conversation_id' => null,
    'response_id' => null,
    'choice_id' => null,
    'request_id' => null,
    'session_id' => null
);
jonvicbarcenas commented 1 year ago

Im using it as an api for facebook chatbot, each thread is different conversation

piscesCat commented 1 year ago

Im using it as an api for facebook chatbot, each thread is different conversation

you can use cache or database to save conversation