tbox-nodejs-sdk
v0.0.19
Published
## Installation
Downloads
15,785
Readme
Tbox Node.js SDK
Installation
npm install tbox-nodejs-sdkUsage
Initialize client
import { TboxClient } from "tbox-nodejs-sdk";
const client = new TboxClient({
httpClientConfig: {
authorization: "TBox-your-token-xxx",
},
});Stream chat
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.
Sync chat
const response = await client.chatSync({
appId: "your_app_id",
query: "今天杭州天气怎么样?",
userId: "user123",
});Completion
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.
