@@ -8,6 +8,8 @@ class Conversation
88{
99 const END_CHAR = ' ' ;
1010
11+ protected $ cookie ;
12+
1113 // Conversation IDs
1214 public $ id ;
1315 public $ client_id ;
@@ -31,8 +33,10 @@ class Conversation
3133
3234 public function __construct ($ cookie , $ identifiers = null , $ invocations = 0 )
3335 {
36+ $ this ->cookie = $ cookie ;
37+
3438 if (! is_array ($ identifiers ))
35- $ identifiers = $ this ->createIdentifiers ($ cookie );
39+ $ identifiers = $ this ->createIdentifiers ();
3640
3741 $ this ->id = $ identifiers ['conversationId ' ];
3842 $ this ->client_id = $ identifiers ['clientId ' ];
@@ -87,10 +91,10 @@ public function ended()
8791 return $ this ->kicked || $ this ->getRemainingMessages () <= 0 ;
8892 }
8993
90- public function createIdentifiers ($ cookie )
94+ public function createIdentifiers ()
9195 {
9296 $ data = Tools::request ("https://www.bing.com/turing/conversation/create " , [
93- 'cookie: _U= ' . $ cookie ,
97+ 'cookie: _U= ' . $ this -> cookie ,
9498 'method: GET ' ,
9599 'accept: application/json ' ,
96100 "accept-language: {$ this ->region }, {$ this ->locale };q=0.9 " ,
@@ -106,6 +110,50 @@ public function createIdentifiers($cookie)
106110 return $ data ;
107111 }
108112
113+ public function uploadImage ($ image_data )
114+ {
115+ $ image_encoded = base64_encode ($ image_data );
116+
117+ $ form = [
118+ 'knowledgeRequest ' => json_encode ([
119+ "imageInfo " => (object ) [],
120+ "knowledgeRequest " => [
121+ "invokedSkills " => ["ImageById " ],
122+ "subscriptionId " => "Bing.Chat.Multimodal " ,
123+ "invokedSkillsRequestData " => [
124+ "enableFaceBlur " => true
125+ ],
126+ "convoData " => [
127+ "convoid " => '' , // $this->id ?
128+ "convotone " => 'Precise ' // $this->tone ?
129+ ]
130+ ]
131+ ]),
132+ 'imageBase64 ' => $ image_encoded
133+ ];
134+
135+ Tools::debug ("Image upload request: " . print_r ($ form , true ));
136+
137+ $ data = Tools::request ("https://www.bing.com/images/kblob " , [
138+ 'cookie: _U= ' . $ this ->cookie ,
139+ 'method: POST ' ,
140+ 'Content-Type: multipart/form-data ' ,
141+ 'referer: https://www.bing.com ' ,
142+ ], $ form );
143+
144+ Tools::debug ("Image upload response: $ data " );
145+
146+ $ data = json_decode ($ data , true );
147+
148+ if (! is_array ($ data ) || empty ($ data ['blobId ' ]) || empty ($ data ['processedBlobId ' ]))
149+ throw new \Exception ("Failed to upload image " );
150+
151+ return [
152+ 'originalImageUrl ' => 'https://www.bing.com/images/blob?bcid= ' . $ data ['blobId ' ],
153+ 'imageUrl ' => 'https://www.bing.com/images/blob?bcid= ' . $ data ['processedBlobId ' ],
154+ ];
155+ }
156+
109157 public function ask (Prompt $ message , $ callback = null )
110158 {
111159 $ this ->invocations ++;
@@ -211,9 +259,17 @@ public function handlePacket($raw, $connection, $message, $callback)
211259 'weasgv2 ' ,
212260 'dv3sugg ' ,
213261 'inputlanguage ' ,
214- 'rediscluster '
262+ 'rediscluster ' ,
263+
264+ // V3 options
265+ "iyxapbing " ,
266+ "iycapbing " ,
267+ "enpcktrk " ,
268+ "logosv1 " ,
269+ "iyolojb " ,
215270 ];
216271
272+
217273 if ($ this ->tone === Tone::Creative) {
218274 $ options = array_merge ($ options , [
219275 'h3imaginative ' ,
@@ -226,24 +282,51 @@ public function handlePacket($raw, $connection, $message, $callback)
226282 $ options = array_merge ($ options , [
227283 'h3precise ' ,
228284 'clgalileo ' ,
229- 'gencontentv5 '
285+ 'gencontentv5 ' ,
286+
287+ // V3 options
288+ 'gencontentv3 ' ,
230289 ]);
231290 }
232291 else {
233292 $ options = array_merge ($ options , [
234293 'galileo ' ,
235294 'visualcreative ' ,
295+
296+ // V3 options
297+ 'harmonyv3 ' ,
298+ 'saharagenconv5 ' ,
236299 ]);
237300 }
238301
239302 if (! $ message ->cache ) {
240303 $ options [] = "nocache " ;
241304 }
242305
306+ $ message_data = [
307+ 'locale ' => $ message ->locale ?? $ this ->locale ,
308+ 'market ' => $ message ->market ?? $ this ->market ,
309+ 'region ' => $ message ->region ?? $ this ->region ,
310+ 'location ' => $ location ,
311+ 'locationHints ' => $ locationHints ,
312+ 'timestamp ' => date ('Y-m-d ' ) . 'T ' . date ('H:i:sP ' ),
313+ 'author ' => 'user ' ,
314+ 'inputMethod ' => 'Keyboard ' ,
315+ 'text ' => $ message ->text ,
316+ 'messageType ' => 'Chat ' ,
317+ ];
318+
319+ if (! empty ($ message ->image )) {
320+ $ message_data = array_merge ($ message_data , $ this ->uploadImage ($ message ->image ));
321+ $ message ->image = null ;
322+ }
323+
243324 $ params = [
244325 'arguments ' => [
245326 [
246327 'source ' => 'cib ' ,
328+ 'verbosity ' => 'verbose ' ,
329+ 'scenario ' => 'SERP ' ,
247330 'optionsSets ' => $ options ,
248331 'allowedMessageTypes ' => [
249332 'Chat ' ,
@@ -257,25 +340,19 @@ public function handlePacket($raw, $connection, $message, $callback)
257340 'ActionRequest ' ,
258341 'GenerateContentQuery ' ,
259342 'SearchQuery ' ,
343+
344+ // V3
345+ 'Context ' ,
346+ 'Progress ' ,
260347 ],
261348 'sliceIds ' => [],
262349 'traceId ' => $ trace_id ,
263350 'isStartOfSession ' => $ this ->invocations == 0 ,
264- 'message ' => [
265- 'locale ' => $ message ->locale ?? $ this ->locale ,
266- 'market ' => $ message ->market ?? $ this ->market ,
267- 'region ' => $ message ->region ?? $ this ->region ,
268- 'location ' => $ location ,
269- 'locationHints ' => $ locationHints ,
270- 'timestamp ' => date ('Y-m-d ' ) . 'T ' . date ('H:i:sP ' ),
271- 'author ' => 'user ' ,
272- 'inputMethod ' => 'Keyboard ' ,
273- 'text ' => $ message ->text ,
274- 'messageType ' => 'Chat ' ,
275- ],
351+ 'message ' => $ message_data ,
276352 'conversationSignature ' => $ this ->signature ,
277353 'participant ' => ['id ' => $ this ->client_id ],
278- 'conversationId ' => $ this ->id
354+ 'conversationId ' => $ this ->id ,
355+ 'spokenTextMode ' => 'None ' ,
279356 ]
280357 ],
281358 'invocationId ' => "{$ this ->invocations }" ,
0 commit comments