
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
qianfan-sdktest
Advanced tools
[![license][license-image]][license-url] [![codecov][codecov-image]][codecov-url] [![NPM version][npm-image]][npm-url] [![NPM downloads][download-image]][download-url] [![docs][docs-image]][docs-url] [![Feedback Issue][issue-image]][issue-url] [![Feedback
针对百度智能云千帆大模型平台,我们推出了一套 JavaScript SDK(下称千帆 SDK),方便用户通过代码接入并调用千帆大模型平台的能力。
npm install @baiducloud/qianfan
# or
yarn add @baiducloud/qianfan
在使用千帆 SDK 之前,用户需要 百度智能云控制台 - 安全认证 页面获取 Access Key 与 Secret Key,并在 千帆控制台 中创建应用,选择需要启用的服务,具体流程参见平台 说明文档。
env 读取
const QIANFAN_AK = process.env.QIANFAN_AK || '';
const QIANFAN_SK = process.env.QIANFAN_SK || '';
const QIANFAN_ACCESS_KEY = process.env.QIANFAN_ACESS_KEY || '';
const QIANFAN_SECRET_KEY = process.env.QIANFAN_SECRET_KEY || '';
默认 IAM 认证方式,如果使用 AK/SK 方式鉴权,需要传入 Type 参数, 参数值如下:'AK'
// AK/SK
const client = new ChatCompletion(QIANFAN_AK, QIANFAN_SK, 'AK');
// IAM
const client = new ChatCompletion(QIANFAN_ACCESS_KEY, QIANFAN_SECRET_KEY);
// TO DO!!!
// 下期优化支持 env 和手动传入
可以使用 ChatCompletion 对象完成对话相关操作
import {ChatCompletion} from "@baiducloud/qianfan";
// AK/SK 测试
const client = new ChatCompletion(QIANFAN_AK, QIANFAN_SK, 'AK');
// IAM 测试
// const client = new ChatCompletion(QIANFAN_ACCESS_KEY, QIANFAN_SECRET_KEY);
async function main() {
const resp = await client.chat({
messages: [
{
role: "user",
content: "今天深圳天气",
},
],
}, "ERNIE-Bot-turbo");
}
main();
参数传入 strean 为 true 时,返回流式结果
// 流式 测试
async function main() {
const stream = await client.chat({
messages: [
{
role: "user",
content: "等额本金和等额本息有什么区别?"
},
],
stream: true,
}, "ERNIE-Bot-turbo");
for await (const chunk of stream as AsyncIterableIterator<any>) {
// process.stdout.write(chunk);
}
}
对于不需要对话,仅需要根据 prompt 进行补全的场景来说,用户可以使用 Completions 来完成这一任务。
import {Completions} from "@baiducloud/qianfan";
// AK/SK 测试
// const client = new Completions(QIANFAN_AK, QIANFAN_SK, 'AK');
// IAM 测试
const client = new Completions(QIANFAN_ACCESS_KEY, QIANFAN_SECRET_KEY);
async function main() {
const resp = await client.completions({
prompt: 'Introduce the city Beijing',
}, "SQLCoder-7B");
}
main();
参数传入 strean 为 true 时,返回流式结果
// 流式
async function main() {
const stream = await client.completions({
prompt: 'Introduce the city Beijing',
stream: true,
}, "SQLCoder-7B");
for await (const chunk of stream as AsyncIterableIterator<any>) {
process.stdout.write(chunk);
}
}
main();
千帆 SDK 同样支持调用千帆大模型平台中的模型,将输入文本转化为用浮点数表示的向量形式。转化得到的语义向量可应用于文本检索、信息推荐、知识挖掘等场景。
import {Embedding} from "@baiducloud/qianfan";
// AK/SK 测试
const client = new Embedding(QIANFAN_AK, QIANFAN_SK, 'AK');
// IAM 测试
// const client = new Embedding(QIANFAN_ACCESS_KEY, QIANFAN_SECRET_KEY);
async function main() {
const resp = await client.embedding({
input: [ 'Introduce the city Beijing'],
}, "Embedding-V1");
}
main();
FAQs
[![license][license-image]][license-url] [![codecov][codecov-image]][codecov-url] [![NPM version][npm-image]][npm-url] [![NPM downloads][download-image]][download-url] [![docs][docs-image]][docs-url] [![Feedback Issue][issue-image]][issue-url] [
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.