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

@khs1994/tencent-ai

v19.6.0-alpha.6

Published

Tencent AI SDK

Downloads

39

Readme

TencentAI JavaScript SDK

npm Build Status codecov install size code style: prettier Build Status Build Status

This repo fork from https://github.com/w89612b/qqai-api-sdk

微信订阅号

Installation

$ npm i @khs1994/tencent-ai --save

Usage

  • 可直接运行于 Node.js 浏览器 微信小程序 Deno

  • 一切逻辑均在微信小程序客户端完成,无需第三方服务器,保证用户隐私

  • Node.js 端文件相关 API 可传入 base64 编码、本地文件路径、图片 url

const { Translate, TencentAIError } = require('@khs1994/tencent-ai');

const App = {
  // 设置请求数据(应用密钥、接口请求参数)
  appkey: 'your-appkey', // process.env.NODE_TENCENT_AI_APP_KEY
  appid: 'your-appid', // process.env.NODE_TENCENT_AI_APP_ID
};

const translate = new Translate(App.appkey, App.appid);

// 文本翻译
translate.text('你好').then(
  res => {
    console.log(res);
  },
  e => {
    console.log(e);
  },
);

// Or Using async / await ES7

(async () => {
  try {
    let res = await translate.text('hello');
    console.log(res);
    // error demo
    res = await translate.text();
  } catch (e) {
    console.log(e);
  }
})();

微信小程序

$ npm i @khs1994/tencent-ai --save
  • 使用 npm 安装,之后在菜单栏选择构建 npm
  • 必须勾选 增强编译,设置方法:详情(IDE 右上角) -> 本地设置 -> 增强编译
  • 必须将 https://api.ai.qq.com 加入 request 合法域名(开发环境请忽略)
// 解构赋值
const { TencentAI } = require('@khs1994/tencent-ai');

// 以下两项请到 ai.qq.com 控制台查看
const app_key = '';
const app_id = '';

// 获取全部实例,也可以只获取特定实例,例如 NLP,具体参考上边例子
const ai = new TencentAI(app_key, app_id);

ai.nlp.textChat('hello', 'session_id').then(
  res => {
    // TODO
    console.log(res);
  },
  e => console.log(e),
);
  • 在小程序端调用文件相关的 API 时(人脸识别、OCR、音频),可以直接传入文件路径,无需转码。也可直接传入 base64 编码

  • 由于小程序限制,请不要传入 url(配置了请求域名除外)

TypeScript

import TencentAI from '@khs1994/tencent-ai';

const app_key = '';
const app_id = '';

const ai = new TencentAI(app_key, app_id);

ai.nlp.textChat('hello', '1').then(res => {
  console.log(res);
});

浏览器

如何安全的保存 密钥(app_key) 请自行实现

<script src="https://unpkg.com/@khs1994/[email protected]/dist/tencent-ai.min.js"></script>

<script>
  // 由于跨域限制,请事先搭建好代理服务器,并在第三个参数传入代理服务器地址
  let ai = new TencentAI.TencentAI(
    app_key,
    app_id,
    (proxy = 'https://domain.com/proxy_tencent_ai'),
  );

  // 浏览器端用法同上
</script>

代理服务器 Nginx 简单设置

location /proxy_tencent_ai {
  proxy_pass https://api.ai.qq.com/;
}

Deno

暂时只支持 js, ts 暂不支持。

ai.js

import TencentAI from 'https://unpkg.com/@khs1994/[email protected]/dist/mod.js';

const app_key = '';
const app_id = '';

const ai = new TencentAI(app_key, app_id);

// Deno 端用法同上
$ deno ai.js -A

CI/CD

PCIT Node.js 示例项目

Test

please set system env first

NODE_TENCENT_AI_APP_KEY=your-appkey

NODE_TENCENT_AI_APP_ID=your-appid
$ npm test