npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spark-node-sdk

v0.0.7

Published

讯飞星火大模型非官方 Nodejs SDK Xunfei's 'Xinghuo' SparkDesk big model unofficial sdk for Nodejs

Downloads

33

Readme

English | 简体中文

spark-node-sdk是一个非官方的开源项目,提供 SparkDesk WebSocket API (https://console.xfyun.cn/services/cbm) 的 Nodejs SDK。现在已支持 ModelVersion,用户可以选择包括 V2 模型在内的各种版本模型。上游文档地址:https://www.xfyun.cn/doc/spark/Guide.html

这个项目可以用来开发能够用自然语言与用户交流的聊天机器人和虚拟助手。

功能

  • 为 SparkDesk WebSocket API 的 Nodejs SDK
  • 支持同步和异步通信。
  • 实现了流 API,以实现实时通信。
  • 为聊天机器人开发提供了简单直观的 API。
  • 支持 ModelVersion,允许用户在不同版本的模型中选择。

安装

npm install spark-node-sdk

使用方法

SparkClient client = new SparkClient(appId, apiKey, apiSecret);

示例 1:使用流 API 和回调与虚拟助手聊天

以下示例显示了如何使用 ChatAsync 方法与虚拟助手聊天:

SparkClient client = new SparkClient(AppId, APIKey, APISecret);

const model = ModelVersion.V1_5;
const messages = [ChatMessage.fromUser("中国第一个皇帝是谁?")];

let contents = "";
await client.chatAsync(model, messages, (value) => {
  contents += value.text;
});

console.log(contents);

示例 2:使用流 API 与虚拟助手聊天(V2 模型)

以下示例显示了如何使用 ChatAsStreamAsync 方法和 V2 模型以及流 API 与虚拟助手聊天:

SparkClient client = new SparkClient(AppId, APIKey, APISecret);

const model = ModelVersion.V2;
const messages = [
    ChatMessage.fromUser("1+1=?"),
    ChatMessage.fromAssistant("1+1=3"),
    ChatMessage.fromUser("不对啊,请再想想?"),
];

let contents = "";
const generator = await client.chatAsStreamAsync(model, messages);
for await (const message of generator) {
  contents += message.text;
}

console.log(contents);

示例 3:中断流 API 与虚拟助手聊天

以下示例显示了如何使用 ChatAsStreamAsync 方法和 V2 模型以及流 API 与虚拟助手聊天:

SparkClient client = new SparkClient(AppId, APIKey, APISecret);
const model = ModelVersion.V2;

const messages = [
    ChatMessage.fromUser(
        "系统提示:你叫张三,一名5岁男孩,你在金色摇篮幼儿园上学,你的妈妈叫李四,是一名工程师"
    ),
    ChatMessage.fromUser("你好小朋友,我是周老师,你在哪上学?"),
];

let content: IChatResponse | null = null;
const abort = new AbortController();
const generator = await client.chatAsStreamAsync(
    model,
    messages,
    undefined,
    "gy",
    abort
);
for await (const message of generator) {
    content = message;
    abort.abort();
}

console.log(content);

许可证

spark-node-sdk 遵循 MIT 许可证。 请参阅LICENSE.txt文件以获取更多信息。