PHP code example of maximerenou / bing-ai

1. Go to this page and download the library: Download maximerenou/bing-ai library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maximerenou / bing-ai example snippets


use MaximeRenou\BingAI\BingAI;

// $cookie - your "_U" cookie from bing.com
$ai = new BingAI($cookie);
$valid = $ai->checkCookie();

use MaximeRenou\BingAI\BingAI;
use MaximeRenou\BingAI\Chat\Prompt;

// $cookie - your "_U" cookie from bing.com
$ai = new BingAI($cookie);

$conversation = $ai->createChatConversation();

// $text - Text-only version of Bing's answer
// $cards - Message objects array
list($text, $cards) = $conversation->ask(new Prompt("Hello World"));

$prompt = new Prompt("How cute is this animal?");
$prompt->withImage('/path/to/panda.png');
//or: $prompt->withImage($raw_image_data, true);

$conversation->ask($prompt, ...);

// $text - Incomplete text version
// $cards - Incomplete messages fleet
list($final_text, $final_cards) = $conversation->ask($prompt, function ($text, $cards) {
    echo $text;
});

$conversation = $ai->createChatConversation()
    ->withLocation($latitude, $longitude, $radius) // Optional
    ->withPreferences('fr-FR', 'fr-FR', 'FR'); // Optional

use MaximeRenou\BingAI\Chat\Tone;

$conversation = $ai->createChatConversation()
    ->withTone(Tone::Creative); // Optional

// Choices:
// Tone::Balanced (default)
// Tone::Creative
// Tone::Precise

// Get current identifiers
$identifiers = $conversation->getIdentifiers();

// ...
// Resume conversation with $identifiers parameter, and number of previous questions asked
$conversation = $ai->resumeChatConversation($identifiers, 1);

$subject = "Internet memes";
$tone = 'funny';
$type = 'blog post';
$length = 'short';

$prompt = new Prompt("Please write a *$length* *$type* in a *$tone* style about `$subject`. Please wrap the $type in a markdown codeblock.");

$conversation->ask($prompt->withoutCache(), ...)

$remaining = $conversation->getRemainingMessages();

if ($remaining === 0) {
    // You reached the limit
}

if ($conversation->kicked()) {
    // You have been kicked, you should start a new conversation
}

if ($conversation->ended()) {
    // You reached the limit or have been kicked
}

use MaximeRenou\BingAI\BingAI;

// $cookie - your "_U" cookie from bing.com
$ai = new BingAI($cookie);

$creator = $ai->createImages("A 3D teddy bear");

$creator->wait();

// Finally, get images URLs
if (! $creator->hasFailed()) {
    $images = $creator->getImages();
}

$creator = $ai->getImageCreator();

$remaining_boosts = $creator->getRemainingBoosts();

$prompt = "A 3D teddy bear";
$creator = $ai->createImages($prompt);
$generation_id = $creator->getGenerationId();

// ...

$creator = $ai->getImageCreator();
$creator->resume($generation_id, $prompt);

do {
    sleep(1);
} while ($creator->isGenerating());