php bing ai
1.2
新功能:在聊天中发送图像

这是用于Bing AI的非正式PHP客户端,包括CHAT(GPT-4)和Image Creator(DALL-E) 。
composer require maximerenou/bing-ai
此演示程序同时使用聊天和图像创建者:

资料来源: examples/multi.php 。
首先,您需要在bing.com上登录并获取_U cookie。
❗在使用cookie之前,请确保您向bing聊天发送第一条消息(CAPTCHA旁路)
use MaximeRenou BingAI BingAI ;
// $cookie - your "_U" cookie from bing.com
$ ai = new BingAI ( $ cookie );
$ valid = $ ai -> checkCookie ();演示:克隆此仓库,编辑和运行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 " ));
$cards包含与Bing AI交换的所有“消息”。它可以是文本(提示或答案),信号,建议,图像生成请求等。查看Message.php以了解有关其格式的更多信息。
您可以将图像附加到您的消息:
$ prompt = new Prompt ( " How cute is this animal? " );
$ prompt -> withImage ( ' /path/to/panda.png ' );
//or: $prompt->withImage($raw_image_data, true);
$ conversation -> ask ( $ prompt , ...);试试!使用
examples/chat.php在消息末尾键入$image。
您可以将函数作为第二个参数,以获得实时进展:
// $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::Precise如果您想恢复以前的对话,可以检索其标识符:
// 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 (), ...)为了防止诸如“我已经写过[...]”之类的答案,您可以禁用
withoutCache()提示的高速缓存。
bing是限制信息计数。您可以在每次互动后通过调用getRemainingMessages()来监视它。
$ remaining = $ conversation -> getRemainingMessages ();
if ( $ remaining === 0 ) {
// You reached the limit
}每次互动后,您还应该检查是否已从对话中踢开:
if ( $ conversation -> kicked ()) {
// You have been kicked, you should start a new conversation
}您可以将两个检查结合在一起:
if ( $ conversation -> ended ()) {
// You reached the limit or have been kicked
}演示:克隆此回购,编辑和运行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 ();
}消耗所有“增强”后,图像产生可能会变慢。检查下面的部分,以了解您的剩余提升。
$ 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 ());在bing.com之外使用bing ai可能会违反bing条款。使用它自己的风险。 Bing是微软的商标。