npm install sydney-ai import ChatBot from "sydney-ai" ;
const bot = new ChatBot ( process . env . TOKEN ) ;
let response = await bot . ask ( "Hello" ) ;
console . log ( response ) ; Untuk menginstal paket, jalankan perintah berikut di terminal Anda:
npm install sydney-aiPertama -tama Anda perlu mengimpor paket:
import ChatBot from "sydney-ai" ;Berikut adalah contoh cara menggunakan paket dalam kode node.js Anda:
import ChatBot from "sydney-ai" ;
// creating the bot with default options
const bot = new ChatBot ( process . env . TOKEN ) ;
// asking a question with default conversation
let response = await bot . ask ( "Hello" ) ;
console . log ( response ) ;
// asking a question with a specific conversation
let response2 = await bot . ask ( "Hello" , "conversation name" ) ;
console . log ( response2 ) ;
//asking a question with a stream default conversation (streamResponse contains the final response)
let streamResponse = await bot . askStream ( res => {
console . log ( res ) ;
} , "Hello" ) ;
// asking a question with a stream specific conversation (streamResponse2 contains the final response)
let streamResponse2 = await bot . askStream ( res => {
console . log ( res ) ;
} , "Hello" , "conversation name" ) ; Ini adalah konstruktor untuk membuat instance chatbot baru. Parameter token diperlukan, dan cookie Bing _U yang digunakan untuk membuat percakapan dan berkomunikasi dengan Bing. Parameter options adalah opsional, dan dapat digunakan untuk menentukan opsi tambahan untuk chatbot.
Metode ini digunakan untuk mengajukan pertanyaan chatbot. Parameter message diperlukan, dan itu adalah pertanyaan yang ingin Anda tanyakan pada chatbot. Parameter conversation adalah opsional, dan itu adalah nama percakapan yang ingin Anda mulai dengan chatbot. Jika parameter ini tidak disediakan, percakapan default akan digunakan.