وحدة NPM لإنشاء chatbot googlebard باستخدام واجهة برمجة تطبيقات Bard argenered. مع وظائف واجهة برمجة التطبيقات ذات الهندسة العكسية ، فإنه يمكّن المطورين من تسخير الإمكانات الكاملة للبارد.
__Secure-{account_number}PSID .__Secure-1PSIDbard.google.com/u/{account_number} ./u/2 ، فابحث عن ملف تعريف الارتباط المسمى __Secure-2PSID ./u/3 ، فابحث عن ملف تعريف الارتباط المسمى __Secure-3PSID .لتثبيت الحزمة ، قم بتشغيل الأمر التالي:
npm install googlebard import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies ) ;
// other code - scroll below to view different functionalities availableinMemory : اختياري - إذا لم يحفظ TRUE محادثات على القرصsavePath : اختياري - المسار لحفظ المحادثات (على سبيل المثال ./conversations.json ')proxy : اختياري - تعاملات تكوينات الوكيل import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
proxy : {
host : process . env . PROXY_HOST ,
port : process . env . PROXY_PORT ,
auth : {
username : process . env . PROXY_USERNAME ,
password : process . env . PROXY_PASSWORD ,
} ,
protocol : "http" ,
} ,
} ) ;
// other code لطرح أسئلة BOT ، يمكنك استخدام الوظيفة bot.ask(<prompt>, <conversation_id>:optional) . ويرد استخدامه أدناه:
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies ) ;
let conversationId = "some_random_id" ; // optional: to make it remember the conversation
let response = await bot . ask ( "What is my name?" , conversationId ) ; // conversationId is optional
console . log ( response ) ; >> I don't know your name. I am a large language model, also known as a conversational AI or cha...
conversation_id مرة أخرى للروبوت أن يتذكر ما قلته سابقًا في المحادثة import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" , // this is being done to save crucial information about the conversation so the bot remembers it
} ) ;
let conversationId = "test_id" ;
let response = await bot . ask ( "My name is Mehul" , conversationId ) ;
console . log ( response ) ; >> Hi Mehul, it's nice to meet you! I'm Bard...
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
} ) ;
let conversationId = "test_id" ;
let response = await bot . ask ( "What is my name?" , conversationId )
console . log ( response ) ; >> I know your name is Mehul. You told me earlier.
لطرح أسئلة BOT ومحاكاة دفق الاستجابة ، يمكنك إما تنفيذه من خلال المنطق المخصص أو استخدام bot.askStream(<callback>, <content>, <conversation_id>:optional) . ويرد استخدامه أدناه:
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
} ) ;
let conversationId = "test_id" ;
await bot . askStream (
( res ) => {
console . log ( res ) ;
} , // returns the response
"Hello?" ,
conversationId ,
) ; >> Your
name
is
Mehul.
I
will
remember
that
for
the
next
time
we
speak.
لإعادة تعيين محادثة ، يمكنك استخدام وظيفة bot.resetConversation(<conversation_id>) . تتيح هذه الوظيفة للمستخدم جعل الروبوت ينسى المحادثات السابقة شريطة أن تكون جميعها تحت نفس conversation_id . ويرد استخدامه أدناه:
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
} ) ;
let conversationId = "test_id" ; // notice id is the same as that used in the above example
let response = await bot . ask ( "what is my name?" , conversationId ) ;
console . log ( response ) ; >> You told me your name is Mehul.
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
} ) ;
let conversationId = "test_id" ;
bot . resetConversation ( conversationId ) // resetting conversation
let response = await bot . ask ( "what is my name?" , conversationId ) ;
console . log ( response ) ; >> I understand that you are trying to get me to say your name, but...
لاسترداد جميع المحادثات الخاصة بك ، يمكنك إما تنفيذ الوظيفة من خلال منطق مخصص أو ببساطة استخدام bot.getAllConversations() . يرد استخدامه أدناه:
import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
savePath : "./conversations.json" ,
} ) ;
let response = bot . getAllConversations ( )
console . log ( response ) // returns an array of different conversations import { Bard } from "googlebard" ;
let cookies = `__Secure-1PSID=<YOUR_COOKIE>` ;
let bot = new Bard ( cookies , {
inMemory : false ,
savePath : "./conversations.json" ,
} ) ;
let conversationId = "test_id" ;
await bot . waitForLoad ( ) ;
let response = bot . getConversationById ( conversationId ) ;
console . log ( response ) ; // returns an object تمت إضافة مثال بسيط إلى دليل examples الذي يوضح كيف يمكن استخدام Googlebard لإنشاء chatbot CLI. المزيد من هذه الأمثلة لم تتم إضافة بعد ، لذلك ترقبوا!