{"id":16597880,"url":"https://github.com/khs1994/tencent-ai-js","last_synced_at":"2025-10-29T13:30:24.934Z","repository":{"id":57124683,"uuid":"149774420","full_name":"khs1994/tencent-ai-js","owner":"khs1994","description":"Tencent AI 腾讯 AI JavaScript SDK","archived":false,"fork":false,"pushed_at":"2019-12-28T16:06:30.000Z","size":969,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T01:32:19.507Z","etag":null,"topics":["ai","library","nodejs","tencent-ai"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@khs1994/tencent-ai","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khs1994.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS.md","security":null,"support":null}},"created_at":"2018-09-21T14:26:03.000Z","updated_at":"2020-05-28T09:46:06.000Z","dependencies_parsed_at":"2022-08-31T08:11:43.057Z","dependency_job_id":null,"html_url":"https://github.com/khs1994/tencent-ai-js","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khs1994%2Ftencent-ai-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khs1994%2Ftencent-ai-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khs1994%2Ftencent-ai-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khs1994%2Ftencent-ai-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khs1994","download_url":"https://codeload.github.com/khs1994/tencent-ai-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238825811,"owners_count":19537132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","library","nodejs","tencent-ai"],"created_at":"2024-10-12T00:06:57.326Z","updated_at":"2025-10-29T13:30:24.511Z","avatar_url":"https://github.com/khs1994.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TencentAI JavaScript SDK\n\n[![npm](https://img.shields.io/npm/v/@khs1994/tencent-ai.svg)](https://www.npmjs.com/package/@khs1994/tencent-ai) [![Build Status](https://travis-ci.com/khs1994/tencent-ai-js.svg?branch=master)](https://travis-ci.com/khs1994/tencent-ai-js) [![codecov](https://codecov.io/gh/khs1994/tencent-ai-js/branch/master/graph/badge.svg)](https://codecov.io/gh/khs1994/tencent-ai-js) [![install size](https://packagephobia.now.sh/badge?p=@khs1994/tencent-ai)](https://packagephobia.now.sh/result?p=@khs1994/tencent-ai) [![code style: prettier](https://badgen.now.sh/badge/code%20style/prettier/ff69b4)](https://github.com/prettier/prettier) [![Build Status](https://ci.khs1994.com/github/khs1994/tencent-ai-js/status?branch=master)](https://ci.khs1994.com/github/khs1994/tencent-ai-js) [![Build Status](https://drone.khs1994.com/api/badges/khs1994/tencent-ai-js/status.svg)](https://drone.khs1994.com/khs1994/tencent-ai-js)\n\n**This repo fork from https://github.com/w89612b/qqai-api-sdk**\n\n- [Tencent AI News](https://github.com/khs1994/tencent-ai-news)\n\n## 微信订阅号\n\n\u003cp align=\"center\"\u003e\n\u003cimg width=\"200\" src=\"https://user-images.githubusercontent.com/16733187/46847944-84a96b80-ce19-11e8-9f0c-ec84b2ac463e.jpg\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003e关注项目作者微信订阅号，接收项目最新动态\u003c/strong\u003e\u003c/p\u003e\n\n## Installation\n\n```bash\n$ npm i @khs1994/tencent-ai --save\n```\n\n## Usage\n\n- 可直接运行于 `Node.js` `浏览器` `微信小程序` `Deno`\n\n- 一切逻辑均在微信小程序客户端完成，无需第三方服务器，保证用户隐私\n\n- Node.js 端文件相关 API 可传入 base64 编码、本地文件路径、图片 url\n\n```js\nconst { Translate, TencentAIError } = require('@khs1994/tencent-ai');\n\nconst App = {\n  // 设置请求数据（应用密钥、接口请求参数）\n  appkey: 'your-appkey', // process.env.NODE_TENCENT_AI_APP_KEY\n  appid: 'your-appid', // process.env.NODE_TENCENT_AI_APP_ID\n};\n\nconst translate = new Translate(App.appkey, App.appid);\n\n// 文本翻译\ntranslate.text('你好').then(\n  res =\u003e {\n    console.log(res);\n  },\n  e =\u003e {\n    console.log(e);\n  },\n);\n\n// Or Using async / await ES7\n\n(async () =\u003e {\n  try {\n    let res = await translate.text('hello');\n    console.log(res);\n    // error demo\n    res = await translate.text();\n  } catch (e) {\n    console.log(e);\n  }\n})();\n```\n\n### 微信小程序\n\n```bash\n$ npm i @khs1994/tencent-ai --save\n```\n\n- 使用 npm 安装，之后在菜单栏选择构建 npm\n- 必须勾选 [`增强编译`](https://developers.weixin.qq.com/miniprogram/dev/devtools/codecompile.html#%E5%A2%9E%E5%BC%BA%E7%BC%96%E8%AF%91)，设置方法：`详情`（IDE 右上角） -\u003e `本地设置` -\u003e `增强编译`\n- 必须将 `https://api.ai.qq.com` 加入 request 合法域名（开发环境请忽略）\n\n```js\n// 解构赋值\nconst { TencentAI } = require('@khs1994/tencent-ai');\n\n// 以下两项请到 ai.qq.com 控制台查看\nconst app_key = '';\nconst app_id = '';\n\n// 获取全部实例，也可以只获取特定实例，例如 NLP，具体参考上边例子\nconst ai = new TencentAI(app_key, app_id);\n\nai.nlp.textChat('hello', 'session_id').then(\n  res =\u003e {\n    // TODO\n    console.log(res);\n  },\n  e =\u003e console.log(e),\n);\n```\n\n- 在小程序端调用文件相关的 API 时(人脸识别、OCR、音频)，可以直接传入文件路径，无需转码。也可直接传入 base64 编码\n\n- 由于小程序限制，请不要传入 url（配置了请求域名除外）\n\n### TypeScript\n\n```ts\nimport TencentAI from '@khs1994/tencent-ai';\n\nconst app_key = '';\nconst app_id = '';\n\nconst ai = new TencentAI(app_key, app_id);\n\nai.nlp.textChat('hello', '1').then(res =\u003e {\n  console.log(res);\n});\n```\n\n### 浏览器\n\n\u003e 如何安全的保存 **密钥（app_key）** 请自行实现\n\n```html\n\u003cscript src=\"https://unpkg.com/@khs1994/tencent-ai@19.6.0-alpha.5/dist/tencent-ai.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  // 由于跨域限制，请事先搭建好代理服务器，并在第三个参数传入代理服务器地址\n  let ai = new TencentAI.TencentAI(\n    app_key,\n    app_id,\n    (proxy = 'https://domain.com/proxy_tencent_ai'),\n  );\n\n  // 浏览器端用法同上\n\u003c/script\u003e\n```\n\n代理服务器 Nginx 简单设置\n\n```nginx\nlocation /proxy_tencent_ai {\n  proxy_pass https://api.ai.qq.com/;\n}\n```\n\n## Deno\n\n\u003e 暂时只支持 `js`, `ts` 暂不支持。\n\n`ai.js`\n\n```js\nimport TencentAI from 'https://unpkg.com/@khs1994/tencent-ai@19.6.0-alpha.6/dist/mod.js';\n\nconst app_key = '';\nconst app_id = '';\n\nconst ai = new TencentAI(app_key, app_id);\n\n// Deno 端用法同上\n```\n\n```bash\n$ deno ai.js -A\n```\n\n## CI/CD\n\n[PCIT](https://github.com/pcit-ce/pcit) Node.js 示例项目\n\n## Test\n\nplease set system env first\n\n```bash\nNODE_TENCENT_AI_APP_KEY=your-appkey\n\nNODE_TENCENT_AI_APP_ID=your-appid\n```\n\n```bash\n$ npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhs1994%2Ftencent-ai-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhs1994%2Ftencent-ai-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhs1994%2Ftencent-ai-js/lists"}