Novo recurso: Enviar imagens no chat

Este é um cliente PHP não oficial da Bing AI , incluindo bate-papo (GPT-4) e criador de imagens (Dall-e) .
composer require maximerenou/bing-ai
Este programa de demonstração usa o bate -papo e o criador de imagens:

Fonte: examples/multi.php .
Primeiro, você precisa fazer login no bing.com e obter seu cookie _U .
❗ Certifique -se de enviar uma primeira mensagem para bate -papo antes de usar seu cookie (desvio Captcha)
use MaximeRenou BingAI BingAI ;
// $cookie - your "_U" cookie from bing.com
$ ai = new BingAI ( $ cookie );
$ valid = $ ai -> checkCookie (); Demonstração : clone este repo, edite e execute examples/chat.php .
use MaximeRenou BingAI BingAI ;
use MaximeRenou BingAI Chat Prompt ;
// $cookie - your "_U" cookie from bing.com
$ ai = new BingAI ( $ cookie );
$ conversation = $ ai -> createChatConversation ();
// $text - Text-only version of Bing's answer
// $cards - Message objects array
list ( $ text , $ cards ) = $ conversation -> ask ( new Prompt ( " Hello World " ));
$cardscontém todas as "mensagens" trocadas com o Bing AI. Pode ser texto (prompt ou resposta), sinais, sugestões, solicitações de geração de imagens, etc. VerifiqueMessage.phppara saber mais sobre seu formato.
Você pode anexar uma imagem à sua mensagem:
$ prompt = new Prompt ( " How cute is this animal? " );
$ prompt -> withImage ( ' /path/to/panda.png ' );
//or: $prompt->withImage($raw_image_data, true);
$ conversation -> ask ( $ prompt , ...);Experimente! Digite
$imageno final da sua mensagem comexamples/chat.php.
Você pode passar uma função como segundo argumento para obter progressão em tempo real:
// $text - Incomplete text version
// $cards - Incomplete messages fleet
list ( $ final_text , $ final_cards ) = $ conversation -> ask ( $ prompt , function ( $ text , $ cards ) {
echo $ text ;
}); $ conversation = $ ai -> createChatConversation ()
-> withLocation ( $ latitude , $ longitude , $ radius ) // Optional
-> withPreferences ( ' fr-FR ' , ' fr-FR ' , ' FR ' ); // Optional use MaximeRenou BingAI Chat Tone ;
$ conversation = $ ai -> createChatConversation ()
-> withTone (Tone::Creative); // Optional
// Choices:
// Tone::Balanced (default)
// Tone::Creative
// Tone::PreciseSe você deseja retomar uma conversa anterior, pode recuperar seus identificadores:
// Get current identifiers
$ identifiers = $ conversation -> getIdentifiers ();
// ...
// Resume conversation with $identifiers parameter, and number of previous questions asked
$ conversation = $ ai -> resumeChatConversation ( $ identifiers , 1 ); $ subject = " Internet memes " ;
$ tone = ' funny ' ;
$ type = ' blog post ' ;
$ length = ' short ' ;
$ prompt = new Prompt ( " Please write a * $ length * * $ type * in a * $ tone * style about ` $ subject `. Please wrap the $ type in a markdown codeblock. " );
$ conversation -> ask ( $ prompt -> withoutCache (), ...)Para evitar respostas como "eu já escrevi [...]", você pode desativar o cache para o seu prompt com
withoutCache().
Bing está limitando as mensagens contam por conversas. Você pode monitorá -lo chamando getRemainingMessages() após cada interação.
$ remaining = $ conversation -> getRemainingMessages ();
if ( $ remaining === 0 ) {
// You reached the limit
}Após cada interação, você também deve verificar se foi expulso da conversa:
if ( $ conversation -> kicked ()) {
// You have been kicked, you should start a new conversation
}Você pode combinar os dois cheques com:
if ( $ conversation -> ended ()) {
// You reached the limit or have been kicked
} Demonstração : Clone este repo, edite e execute examples/images.php .
use MaximeRenou BingAI BingAI ;
// $cookie - your "_U" cookie from bing.com
$ ai = new BingAI ( $ cookie );
$ creator = $ ai -> createImages ( " A 3D teddy bear " );
$ creator -> wait ();
// Finally, get images URLs
if (! $ creator -> hasFailed ()) {
$ images = $ creator -> getImages ();
}A geração de imagens pode se tornar mais lenta depois de consumir todos os seus "impulsionamentos". Verifique a seção abaixo para permanecer ciente dos seus impulsionamentos restantes.
$ creator = $ ai -> getImageCreator ();
$ remaining_boosts = $ creator -> getRemainingBoosts (); $ prompt = " A 3D teddy bear " ;
$ creator = $ ai -> createImages ( $ prompt );
$ generation_id = $ creator -> getGenerationId ();
// ...
$ creator = $ ai -> getImageCreator ();
$ creator -> resume ( $ generation_id , $ prompt ); do {
sleep ( 1 );
} while ( $ creator -> isGenerating ());O uso do Bing AI fora do Bing.com pode violar os termos do Bing. Use -o por sua conta e risco. Bing é uma marca registrada da Microsoft.