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

Commit 04dcd34

Browse files
committed
feat: php 7.1 support
1 parent e6e2a1f commit 04dcd34

File tree

9 files changed

+55
-132
lines changed

9 files changed

+55
-132
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ _It comes with no warranty of continuous stability._
1010

1111
composer require maximerenou/bing-ai
1212

13+
Currently, the required PHP minimum version is PHP **7.1**. cURL extension is required.
14+
1315
## Usage
1416

1517
- [Chat AI](#chat-ai)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=8.1",
17+
"php": ">=7.1",
1818
"ratchet/pawl": "^0.4.1",
1919
"ext-curl": "*"
2020
}

composer.lock

Lines changed: 26 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Chat/Conversation.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,24 @@ class Conversation
99
const END_CHAR = '';
1010

1111
// Conversation IDs
12-
1312
public $id;
14-
1513
public $client_id;
16-
1714
public $signature;
1815

1916
// User preferences
20-
2117
public $locale = 'en-US';
22-
2318
public $market = 'en-US';
24-
2519
public $region = 'US';
26-
2720
public $geolocation = null;
2821

2922
// Conversation data
30-
3123
protected $invocations = -1;
32-
3324
protected $current_started;
34-
3525
protected $current_text;
36-
3726
protected $current_messages;
38-
3927
protected $user_messages_count;
40-
4128
protected $max_messages_count;
4229

43-
//
44-
4530
public function __construct($cookie, $identifiers = null, $invocations = 0)
4631
{
4732
if (! is_array($identifiers))
@@ -156,8 +141,14 @@ public function ask(Prompt $message, $callback = null)
156141
public function handlePacket($raw, $connection, $message, $callback)
157142
{
158143
$objects = explode(self::END_CHAR, $raw);
159-
$objects = array_map(fn ($object) => json_decode($object, true), $objects);
160-
$objects = array_filter($objects, fn ($value) => is_array($value));
144+
145+
$objects = array_map(function ($object) {
146+
return json_decode($object, true);
147+
}, $objects);
148+
149+
$objects = array_filter($objects, function ($value) {
150+
return is_array($value);
151+
});
161152

162153
if (count($objects) === 0) {
163154
return;

src/Chat/Message.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public static function fromData($data)
4545
public $id;
4646
public $text;
4747
public $type;
48+
public $data;
4849

49-
public function __construct(
50-
public $data = null
51-
) {}
50+
public function __construct($data = null)
51+
{
52+
$this->data = $data;
53+
}
5254

5355
public function toText()
5456
{

src/Chat/MessageType.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace MaximeRenou\BingAI\Chat;
44

5-
enum MessageType: string
5+
class MessageType
66
{
7-
case Answer = "answer";
8-
case Prompt = "prompt";
9-
case SearchQuery = "search_query";
10-
case SearchResult = "search_result";
11-
case Loader = "loader";
12-
case RenderRequest = "render_request";
7+
const Answer = "answer";
8+
const Prompt = "prompt";
9+
const SearchQuery = "search_query";
10+
const SearchResult = "search_result";
11+
const Loader = "loader";
12+
const RenderRequest = "render_request";
1313
}

src/Chat/Prompt.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
class Prompt
66
{
77
public $cache = true;
8-
98
public $locale;
10-
119
public $market;
12-
1310
public $region;
11+
public $text;
1412

15-
public function __construct(
16-
public $text
17-
) {}
13+
public function __construct($text)
14+
{
15+
$this->text = $text;
16+
}
1817

1918
public function withPreferences($locale = 'en-US', $market = 'en-US', $region = 'US')
2019
{

src/Images/ImageCreator.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77
class ImageCreator
88
{
99
private $cookie;
10-
1110
private $generation_id;
12-
1311
private $prompt;
14-
1512
private $failed = false;
16-
1713
private $generating = false;
18-
1914
private $images = [];
2015

2116
public function __construct($cookie)

src/Tools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Tools
66
{
7-
public static bool $debug = false;
7+
public static $debug = false;
88

99
public static function generateUUID()
1010
{

0 commit comments

Comments
 (0)