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

Commit 300d663

Browse files
committed
update infos for packagist
fix: invocations
1 parent ed26b4a commit 300d663

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# Bing AI
1+
# Bing AI client
2+
3+
> For now you need to have access to Bing Chat open beta. Or grab the cookie from someone who has access.
4+
5+
This is Composer package for using Bing AI technology.
6+
7+
It comes with no warranty of continuous stability, and has been made using reverse engineering.
28

39
## Install
410

511
composer require maximerenou/bing-ai
612

7-
## Usage
13+
## Chat AI Usage
814

915
Edit and run `examples/chat.php` to test it.
1016

@@ -26,18 +32,24 @@ list($text, $messages) = $conversation->ask(new Prompt("Hello World"));
2632
// Example 2: async
2733
// $text - Incomplete text version
2834
// $messages - Incomplete messages fleet
29-
list($final_text, $final_messages) = $conversation->ask($prompt, function ($text, $cards) {
35+
list($final_text, $final_messages) = $conversation->ask($prompt, function ($text, $messages) {
3036
echo $text;
3137
});
3238

3339
```
3440

41+
Every "card" from Bing AI is fetched. Check `Message.php` to learn more about its format.
42+
3543
If you want to resume a previous conversation, you can retrieve its identifiers:
3644
```php
3745
// Get current identifiers
3846
$identifiers = $conversation->getIdentifiers();
3947

4048
// ...
41-
// Resume conversation with $identifiers parameter
42-
$conversation = $ai->createChatConversation($cookie, $identifiers);
43-
```
49+
// Resume conversation with $identifiers parameter, and number of previous questions
50+
$conversation = $ai->createChatConversation($cookie, $identifiers, 1);
51+
```
52+
53+
---------------------------------------
54+
55+
Bing is a trademark of Microsoft. This repository is not official.

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "maximerenou/bing-ai",
3+
"description": "Bing AI adapter",
34
"type": "library",
45
"autoload": {
56
"psr-4": {
@@ -13,6 +14,7 @@
1314
}
1415
],
1516
"require": {
17+
"php": ">=8.1",
1618
"ratchet/pawl": "^0.4.1",
1719
"ext-curl": "*"
1820
}

composer.lock

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

examples/chat.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
$conversation = $ai->createChatConversation($cookie)
1212
->withPreferences('fr-FR', 'fr-FR', 'FR');
1313

14-
\MaximeRenou\BingAI\Tools::$debug = true;
14+
\MaximeRenou\BingAI\Tools::$debug = false; // Set true for
15+
verbose
1516

1617
echo 'Type "q" to quit' . PHP_EOL;
1718

@@ -33,4 +34,4 @@
3334
echo "- $text" . PHP_EOL;
3435
}
3536

36-
exit(0);
37+
exit(0);

src/BingAI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function __construct()
1111
//
1212
}
1313

14-
public function createChatConversation($cookie, $data = null)
14+
public function createChatConversation($cookie, $data = null, $invocations = 0)
1515
{
16-
return new Conversation($cookie, $data);
16+
return new Conversation($cookie, $data, $invocations);
1717
}
1818
}

src/Chat/Conversation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ class Conversation
3838

3939
//
4040

41-
public function __construct($cookie, $identifiers = null)
41+
public function __construct($cookie, $identifiers = null, $invocations = 0)
4242
{
4343
if (! is_array($identifiers))
4444
$identifiers = $this->createIdentifiers($cookie);
4545

4646
$this->id = $identifiers['conversationId'];
4747
$this->client_id = $identifiers['clientId'];
4848
$this->signature = $identifiers['conversationSignature'];
49+
$this->invocations = $invocations - 1;
4950
}
5051

5152
public function getIdentifiers()

src/Chat/Message.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class Message implements \JsonSerializable
66
{
77
public static function fromPrompt(Prompt $prompt)
88
{
9-
$message = new self(true);
9+
$message = new self();
1010
$message->text = $prompt->text;
1111
$message->type = MessageType::Prompt;
1212
return $message;
1313
}
1414

1515
public static function fromData($data)
1616
{
17-
$message = new self($data['author'] == 'user', $data);
17+
$message = new self($data);
1818
$message->id = $data['messageId'];
1919

2020
switch ($data['messageType'] ?? '') {
@@ -31,7 +31,7 @@ public static function fromData($data)
3131
$message->type = MessageType::RenderRequest;
3232
break;
3333
default:
34-
$message->type = MessageType::Answer;
34+
$message->type = $data['author'] == 'user' ? MessageType::Prompt : MessageType::Answer;
3535
}
3636

3737
if (! empty($data['text']))
@@ -47,7 +47,6 @@ public static function fromData($data)
4747
public $type;
4848

4949
public function __construct(
50-
public $local = false,
5150
public $data = null
5251
) {}
5352

@@ -67,7 +66,6 @@ public function toArray()
6766
'text' => $this->text,
6867
'formatted_text' => $this->toText(),
6968
'type' => $this->type,
70-
'local' => $this->local,
7169
'data' => $this->data
7270
];
7371
}

0 commit comments

Comments
 (0)