Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit d3f82c6

Browse files
committed
fix: examples
1 parent 9578d7f commit d3f82c6

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

examples/chat.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
23

34
$cookie = "YOUR_COOKIE_HERE"; //@TODO change
45

56
if ($cookie == 'YOUR_COOKIE_HERE') {
6-
echo 'Please add your _U cookie to chat.php (line 3)' . PHP_EOL;
7+
echo 'Please add your _U cookie to chat.php (line 4)' . PHP_EOL;
78
exit(1);
89
}
910

10-
require __DIR__ . '/../vendor/autoload.php';
11-
1211
date_default_timezone_set("Europe/Paris");
1312

13+
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
14+
1415
$ai = new \MaximeRenou\BingAI\BingAI($cookie);
1516

1617
$conversation = $ai->createChatConversation();
1718

18-
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
19-
2019
echo 'Type "q" to quit' . PHP_EOL;
2120

2221
while (true) {
@@ -30,18 +29,16 @@
3029
$padding = 0;
3130

3231
list($text, $cards) = $conversation->ask($prompt, function ($text, $cards) use (&$padding) {
33-
// Erase the last line
34-
for ($i = 0; $i < $padding; $i++)
35-
echo chr(8);
32+
// Erase last line
33+
echo str_repeat(chr(8), $padding);
3634

3735
// Print partial answer
3836
echo "- $text";
39-
$padding = strlen($text) + 2;
37+
$padding = mb_strlen($text) + 2;
4038
});
4139

42-
// Erase the last line
43-
for ($i = 0; $i < $padding; $i++)
44-
echo chr(8);
40+
// Erase last line
41+
echo str_repeat(chr(8), $padding);
4542

4643
// Print final answer
4744
echo "- $text" . PHP_EOL;

examples/images.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
23

34
$cookie = "YOUR_COOKIE_HERE"; //@TODO change
45

5-
if ($cookie == 'YOUR_COOKIE_HERE') {
6-
echo 'Please add your _U cookie to images.php (line 3)' . PHP_EOL;
6+
if ($cookie == 'YOUR_COOKIE_HERE') {
7+
echo 'Please add your _U cookie to images.php (line 4)' . PHP_EOL;
78
exit(1);
89
}
910

10-
require __DIR__ . '/../vendor/autoload.php';
11+
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
1112

1213
$ai = new \MaximeRenou\BingAI\BingAI($cookie);
1314

14-
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
15-
1615
$boosts = $ai->getImageCreator()->getRemainingBoosts();
1716

1817
echo "You have $boosts remaining boosts." . PHP_EOL;
19-
2018
echo 'Type "q" to quit' . PHP_EOL;
2119

2220
echo PHP_EOL . "> ";
@@ -37,10 +35,10 @@
3735
foreach ($images as $image) {
3836
echo "- $image" . PHP_EOL;
3937
}
40-
41-
exit(0);
4238
}
4339
else {
4440
echo 'Generation failed' . PHP_EOL;
4541
exit(1);
4642
}
43+
44+
exit(0);

examples/multi.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
23

34
$cookie = "YOUR_COOKIE_HERE"; //@TODO change
45

56
if ($cookie == 'YOUR_COOKIE_HERE') {
6-
echo 'Please add your _U cookie to multi.php (line 3)' . PHP_EOL;
7+
echo 'Please add your _U cookie to multi.php (line 4)' . PHP_EOL;
78
exit(1);
89
}
910

10-
require __DIR__ . '/../vendor/autoload.php';
11+
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
1112

1213
$ai = new \MaximeRenou\BingAI\BingAI($cookie);
1314

1415
$conversation = $ai->createChatConversation()
1516
->withTone(\MaximeRenou\BingAI\Chat\Tone::Creative);
1617

17-
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for verbose
18-
1918
echo 'Type "q" to quit' . PHP_EOL;
2019

2120
while (true) {
@@ -29,20 +28,18 @@
2928
$padding = 0;
3029

3130
list($text, $cards) = $conversation->ask($prompt, function ($text, $cards) use (&$padding) {
32-
// Erase the last line
33-
for ($i = 0; $i < $padding; $i++)
34-
echo chr(8);
31+
// Erase last line
32+
echo str_repeat(chr(8), $padding);
3533

3634
$text = trim($text);
3735

3836
// Print partial answer
3937
echo "- $text";
40-
$padding = strlen($text) + 2;
38+
$padding = mb_strlen($text) + 2;
4139
});
4240

43-
// Erase the last line
44-
for ($i = 0; $i < $padding; $i++)
45-
echo chr(8);
41+
// Erase last line
42+
echo str_repeat(chr(8), $padding);
4643

4744
// Print final answer
4845
echo "- $text" . PHP_EOL;
@@ -57,9 +54,7 @@
5754
$creator = $ai->createImages($card->text);
5855
$creator->wait();
5956

60-
// Result
61-
for ($i = 0; $i < strlen($loader); $i++)
62-
echo chr(8);
57+
echo str_repeat(chr(8), strlen($loader));
6358

6459
if ($creator->hasFailed()) {
6560
echo "[Image generation failed]" . PHP_EOL;

0 commit comments

Comments
 (0)