tbox-nodejs-sdk
## Installation
Last updated a year ago by yunkun666 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install tbox-nodejs-sdk 
SYNC missed versions from official npm registry.

Tbox Node.js SDK

Installation

npm install tbox-nodejs-sdk

Usage

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.

Current Tags

  • 0.0.19                                ...           latest (a year ago)

18 Versions

  • 0.0.19                                ...           a year ago
  • 0.0.18                                ...           a year ago
  • 0.0.17                                ...           a year ago
  • 0.0.16                                ...           a year ago
  • 0.0.14                                ...           a year ago
  • 0.0.13                                ...           a year ago
  • 0.0.12                                ...           a year ago
  • 0.0.11                                ...           a year ago
  • 0.0.10                                ...           a year ago
  • 0.0.9                                ...           a year ago
  • 0.0.8                                ...           a year ago
  • 0.0.7                                ...           a year ago
  • 0.0.6                                ...           a year ago
  • 0.0.5                                ...           a year ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Total 65
Today 0
This Week 0
This Month 45
Last Day 0
Last Week 20
Last Month 20
Dependencies (3)
Dev Dependencies (6)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE