1、在“微信开发工具”的某云函数上点击右键,选择“在外部终端窗口”打开
2、在函数命令行运行“npm install tencentcloud-sdk-nodejs --save”
3、上传并部署云函数(云端安装依赖)
4、修改官方文档 demo 中的参数即可运行了
const tencentcloud = require("tencentcloud-sdk-nodejs");
const NlpClient = tencentcloud.nlp.v20190408.Client;
const models = tencentcloud.nlp.v20190408.Models;
const Credential = tencentcloud.common.Credential;
const ClientProfile = tencentcloud.common.ClientProfile;
const HttpProfile = tencentcloud.common.HttpProfile;
let cred = new Credential("secretid", "secretkey");
let httpProfile = new HttpProfile();
httpProfile.endpoint = "nlp.tencentcloudapi.com";
let clientProfile = new ClientProfile();
clientProfile.httpProfile = httpProfile;
let client = new NlpClient(cred, "", clientProfile);
let req = new models.WordEmbeddingRequest();
let params = '{\"Text\":\"中国\"}'
req.from_json_string(params);
client.WordEmbedding(req, function(errMsg, response) {
if (errMsg) {
console.log(errMsg);
return;
}
console.log(response.to_json_string());
});
网友评论