คุณสมบัติใหม่: ส่งภาพในการแชท

นี่คือไคลเอนต์ PHP ที่ไม่เป็นทางการสำหรับ Bing AI รวมถึง การแชท (GPT-4) และ ผู้สร้างภาพ (Dall-E)
composer require maximerenou/bing-ai
โปรแกรมสาธิตนี้ใช้ทั้งการแชทและผู้สร้างภาพ:

ที่มา: examples/multi.php
ก่อนอื่นคุณต้องลงชื่อเข้าใช้ Bing.com และรับคุกกี้ _U ของคุณ
❗ตรวจสอบให้แน่ใจว่าคุณส่งข้อความแรกไปยัง Bing Chat ก่อนที่จะใช้คุกกี้ของคุณ (Captcha Bypass)
use MaximeRenou BingAI BingAI ;
// $cookie - your "_U" cookie from bing.com
$ ai = new BingAI ( $ cookie );
$ valid = $ ai -> checkCookie (); ตัวอย่าง : โคลน repo นี้แก้ไขและเรียกใช้ 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 , ...);ลองดูสิ พิมพ์
$imageที่ส่วนท้ายของข้อความของคุณด้วยexamples/chat.php
คุณอาจผ่านฟังก์ชั่นเป็นอาร์กิวเมนต์ที่สองเพื่อให้ได้ความก้าวหน้าแบบเรียลไทม์:
// $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
} ตัวอย่าง : โคลน repo นี้แก้ไขและเรียกใช้ 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 AI นอก Bing.com อาจละเมิดข้อกำหนด Bing ใช้มันตามความเสี่ยงของคุณเอง Bing เป็นเครื่องหมายการค้าของ Microsoft