$ npm install tbox-nodejs-sdk
npm install tbox-nodejs-sdk
Initialize client
import { TboxClient } from "tbox-nodejs-sdk";
const client = new TboxClient({
httpClientConfig: {
authorization: "TBox-your-token-xxx",
},
});
const emitter = client.chat({
appId: "your-app-id",
query: "今天杭州天气怎么样?",
userId: "user123",
});
emitter.on("data", (data) => {
console.log("Received data:", data);
});
emitter.on("end", () => {
console.log("Stream ended");
});
emitter.on("error", (error) => {
console.error("Stream error:", error);
});
emitter.on("abort", () => {
console.log("Stream aborted");
});
// To abort the stream
emitter.abort();
Note: After calling emitter.abort(), the stream will be immediately terminated and no further data events will be emitted. An abort event will be triggered to notify that the stream has been aborted.
const response = await client.chatSync({
appId: "your_app_id",
query: "今天杭州天气怎么样?",
userId: "user123",
});
const emitter = client.completion({
appId: "your-app-id",
inputs: { text: "苹果" },
userId: "user123",
});
emitter.on("data", (response) => {
console.log("Received completion data:", response);
});
emitter.on("end", () => {
console.log("Completion stream ended");
});
emitter.on("error", (error) => {
console.error("Error in completion:", error);
});
emitter.on("abort", () => {
console.log("Completion aborted");
});
// To abort the completion
emitter.abort();
Note: After calling emitter.abort(), the completion stream will be immediately terminated and no further data events will be emitted. An abort event will be triggered to notify that the stream has been aborted.
© 2010 - cnpmjs.org x YWFE | Home | YWFE