node.js - 无法使用节点 js 在谷歌对话流中创建自定义实体
问题描述
下面出现错误
(节点:14284)UnhandledPromiseRejectionWarning:错误:3 INVALID_ARGUMENT:com.google.apps.framework.request.BadRequestException:必须提供要添加的实体。在 Object.callErrorFromStatus (E:\workspace\dailogFlowApi\node_modules@grpc\grpc-js\build\src\call.js:31:26) 在 Object.onReceiveStatus (E:\workspace\dailogFlowApi\node_modules@grpc\grpc- js\build\src\client.js:179:52) 在 Object.onReceiveStatus (E:\workspace\dailogFlowApi\node_modules@grpc\grpc-js\build\src\client-interceptors.js:336:141) 在 Object .onReceiveStatus (E:\workspace\dailogFlowApi\node_modules@grpc\grpc-js\build\src\client-interceptors.js:299:181) 在 E:\workspace\dailogFlowApi\node_modules@grpc\grpc-js\build\ src\call-stream.js:145:78 在 processTicksAndRejections (internal/process/task_queues.js:79:11) (node:14284) UnhandledPromiseRejectionWarning: 未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志--unhandled-rejections=strict
(见https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。(拒绝 id:1)(节点:14284)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。
exports.createEntityTypeService = (entity) => {
return new Promise(async (resolve, reject) => {
try {
let projectPath = entityClient.agentPath(projectId);
let entityPath = entityClient.entityTypePath(projectId, entity);
let entityValues = ["testEntity1","test", "testEntity2"];
const entities = [];
entityValues.forEach((entityValue) => {
entities.push({
value: entityValue,
synonyms: [entityValue],
});
});
let entityReuest = {
parent: projectPath,
languageCode:'en-US',
enitityType: {
name: entityPath,
entityOverrideMode:"@",
entities: entities,
},
};
let response = await entityClient.createEntityType(entityReuest);
console.log(response);
resolve(response);
} catch (error) {
reject(error);
}
});
};```
解决方案
您正在使用createEntityType()并且为entityType
. 因此,您遇到 INVALID_ARGUMENT 的错误。
根据文档,entityType的参数如下:
autoExpansionMode - EntityType 自动扩展模式。
displayName - 实体类型显示名称。
enableFuzzyExtraction - EntityType 启用模糊提取。
实体- EntityType 实体。
kind - EntityType 种类。
name - 实体类型名称。
在您的代码中entityType
应该看起来像这样。只需确保为每个参数提供正确的值。
enitityType: {
name: entityPath,
entities: entities,
autoExpansionMode: autoExpansionMode,
displayName: displayName
enableFuzzyExtraction: enableFuzzyExtraction
kind: kind
}
推荐阅读
- android - 如何在 Android Studio 上将 Kotlin 版本从 1.2.51 升级到 1.3
- neo4j - Neo4j中数组属性的高效查询
- unreal-engine4 - 如何将动画应用于单个蓝图中的大量静态网格演员?UE4
- r - 如何在R中读取一个txt文件,该文件指示每页中的页码和段落
- azure - 无法创建集合信息 - 尝试在本地测试 Cosmos DB 触发器时出错
- python - 如何解决请求无法通过 VPN 工作?
- reactjs - 为什么我在使用 webpack 运行“npm run build”时得到散列的 .jpeg 文件
- oracle - toad for oracle 中的外部表数据错误
- nginx - nginx反向代理背后的grafana
- python - 在 Python 中使用 openpyxl 进行 Excel 条件格式设置 - 边框