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

Commit ed26b4a

Browse files
committed
add README.md
1 parent 95d8079 commit ed26b4a

File tree

8 files changed

+384
-193
lines changed

8 files changed

+384
-193
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Bing AI
2+
3+
## Install
4+
5+
composer require maximerenou/bing-ai
6+
7+
## Usage
8+
9+
Edit and run `examples/chat.php` to test it.
10+
11+
```php
12+
use MaximeRenou\BingAI\BingAI;
13+
use MaximeRenou\BingAI\Chat\Prompt;
14+
15+
// $cookie - your "_U" cookie from bing.com
16+
$ai = new BingAI;
17+
$conversation = $ai->createChatConversation($cookie)
18+
->withLocation($latitude, $longitude, $radius) // Optional
19+
->withPreferences('fr-FR', 'fr-FR', 'FR'); // Optional
20+
21+
// Example 1: sync
22+
// $text - Text-only version of Bing's answer
23+
// $messages - Message objects array
24+
list($text, $messages) = $conversation->ask(new Prompt("Hello World"));
25+
26+
// Example 2: async
27+
// $text - Incomplete text version
28+
// $messages - Incomplete messages fleet
29+
list($final_text, $final_messages) = $conversation->ask($prompt, function ($text, $cards) {
30+
echo $text;
31+
});
32+
33+
```
34+
35+
If you want to resume a previous conversation, you can retrieve its identifiers:
36+
```php
37+
// Get current identifiers
38+
$identifiers = $conversation->getIdentifiers();
39+
40+
// ...
41+
// Resume conversation with $identifiers parameter
42+
$conversation = $ai->createChatConversation($cookie, $identifiers);
43+
```

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"ratchet/pawl": "^0.4.1"
16+
"ratchet/pawl": "^0.4.1",
17+
"ext-curl": "*"
1718
}
1819
}

examples/chat.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
$cookie = "YOUR_COOKIE_HERE"; //@TODO change
4+
35
require __DIR__ . '/../vendor/autoload.php';
46

57
date_default_timezone_set("Europe/Paris");
68

7-
$cookie = "COOKIE_HERE";
8-
$id = null;
9-
109
$ai = new \MaximeRenou\BingAI\BingAI();
1110

12-
$conversation = $ai->createChatConversation($cookie, $id)
11+
$conversation = $ai->createChatConversation($cookie)
1312
->withPreferences('fr-FR', 'fr-FR', 'FR');
1413

14+
\MaximeRenou\BingAI\Tools::$debug = true;
15+
1516
echo 'Type "q" to quit' . PHP_EOL;
1617

1718
while (true) {
@@ -23,9 +24,9 @@
2324

2425
echo PHP_EOL;
2526

26-
$message = new \MaximeRenou\BingAI\Chat\Message($text);
27+
$prompt = new \MaximeRenou\BingAI\Chat\Prompt($text);
2728

28-
list($text, $cards) = $conversation->send($message, function ($text, $cards) {
29+
list($text, $cards) = $conversation->ask($prompt, function ($text, $cards) {
2930
echo "- $text \r";
3031
});
3132

0 commit comments

Comments
 (0)