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 ) ; Führen Sie zum Installieren des Pakets den folgenden Befehl in Ihrem Terminal aus:
npm install sydney-aiZunächst müssen Sie das Paket importieren:
import ChatBot from "sydney-ai" ;Hier ist ein Beispiel für die Verwendung des Pakets in Ihrem Node.js -Code:
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" ) ; Dies ist der Konstruktor zum Erstellen einer neuen Chatbot -Instanz. Der token -Parameter ist erforderlich, und es ist ein Bing _U -Cookie, mit dem Gespräche erstellt und mit Bing kommuniziert wurden. Der options ist optional und kann verwendet werden, um zusätzliche Optionen für den Chatbot anzugeben.
Diese Methode wird verwendet, um dem Chatbot eine Frage zu stellen. Der message ist erforderlich, und es ist die Frage, die Sie dem Chatbot stellen möchten. Der conversation ist optional und der Name der Konversation, die Sie mit dem Chatbot beginnen möchten. Wenn dieser Parameter nicht bereitgestellt wird, wird die Standardkonversation verwendet.