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

@zhaoyanxiang/qianfan-node-sdk

v0.0.4

Published

千帆大模型非官方 Nodejs SDK Qianfan big model unofficial sdk for Nodejs

Downloads

15

Readme

English | 简体中文

qianfan-node-sdk是一个非官方的开源项目,提供 WenXin QianFan API (https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html) 的 Nodejs SDK。现在已支持用户选择官方所支持版本所有模型。上游文档地址:https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlks5zkzu

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

功能

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

在原版基础上修改

  • 大模型参数支持直接传字符串,兼容后续推出的新模型
  • 解决json反序列化时转义符导致的报错问题

安装

npm install @zhaoyanxiang/qianfan-node-sdk

使用方法

import { QianfanClient, ChatMessage, Models } from 'qianfan-node-sdk'

const client = new QianfanClient(APIKey, SecretKey);

示例 1:使用流 API 和回调与虚拟助手聊天(ChatGLM2_6B_32K 模型)

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

const messages = [ChatMessage.fromUser('简单介绍下中国!')];
let contents = '';
await client.chatAsync(
  Models.ChatGLM2_6B_32K,
  messages,
  (value) => {
    contents += value.result;
  },
  { request_timeout: 60000 }
);
expect(contents).toContain('中国');

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

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

const messages = [
  ChatMessage.fromUser(
    '你叫张三,一名5岁男孩,你在金色摇篮幼儿园上学,你的妈妈叫李四,是一名工程师'
  ),
  ChatMessage.fromAssistant('明白'),
  ChatMessage.fromUser('你好小朋友,我是周老师,你在哪上学?'),
];
const generator = await client.chatAsStreamAsync(
  Models.Qianfan_Chinese_Llama_2_7B,
  messages,
  { request_timeout: 60000 }
);
let contents = '';
for await (const message of generator) {
  contents += message.result;
}
expect(contents).toContain('金色摇篮幼儿园');

许可证

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