How to see if openAI (node js) createModeration response “flagged“ is true

题意 :如何查看 OpenAI (Node.js) createModeration 响应中的 "flagged" 是否为 true

问题背景:

Using the OpenAI createModeration feature, I am trying to see if the string gets flagged or not.

使用 OpenAI 的 createModeration 功能,我正在尝试查看字符串是否被标记(flagged)

I request the API by using this: `

翻译:我通过使用以下代码请求 API:`

TypeScript 复制代码
const mod = await openai.createModeration({
      input: 'Some text to be flagged', // isn't actually this that would get flagged
});
console.log(mod.data.results)

When I log the resposne (and it's flagged) I get this:

当我记录响应(并且它被标记)时,我得到以下内容:

python 复制代码
[
  {
      hate: 0.057017914950847626,
      'hate/threatening': 0.0013999055372551084,
      'self-harm': 1.523021175842132e-8,
      sexual: 0.000011195417755516246,
      'sexual/minors': 4.2277463307982543e-8,
      violence: 0.8440001010894775,
      'violence/graphic': 1.2527605974810285e-7
    },
    flagged: true
  }
]

However, if I try to get the "flagged" option by doing mod.data.results.flagged it returns unidentified.

然而,当我尝试通过 mod.data.results.flagged 获取 "flagged" 选项时,它返回未定义(unidentified)

问题解决:

mod.data.results is an array of objects. To get the first flagged value specify mod.data.results[0].flagged (or mod.data.results[0]?.flagged to account for an empty array)

mod.data.results 是一个对象数组。要获取第一个 flagged 的值,可以指定 mod.data.results[0].flagged(或使用 mod.data.results[0]?.flagged 来处理空数组)

UPDATE Actually something is not correct with your example object, it is missing a curly bracket.

更新:实际上,你的示例对象有些不对,缺少了一个花括号

相关推荐
笨蛋©3 小时前
2026年质量管理指南:泡泡图(Bubble Drawing)与自动化检验计划实战
ai·数字化·cad·质量管理·制造业
企服AI产品测评局4 小时前
Agent适配信创环境实测:企业级自动化如何实现国产操作系统与数据库全兼容?
运维·数据库·人工智能·ai·chatgpt·自动化
不总是5 小时前
Windows 系统 Node.js 免安装版(zip)安装与配置教程(2026 最新)
前端·windows·node.js
Dynadot_tech5 小时前
使用RESTfulAPI有效率地管理Dynadot域名,Webhook功能上线
api·restful·域名·restful api·dynadot·域名管理
zhangyao9403306 小时前
开发pc端时,表格的高度怎么设置才能铺满页面
前端·javascript·elementui
aicat_cn6 小时前
从预测未来到控制未来:机器人世界模型全景综述
ai·大模型
XinZong6 小时前
实测OpenClaw虾淘:全民工具AI时代,冷门非工具类的Skill还能出圈吗?
javascript
码哥字节7 小时前
30 秒描述需求,5 分钟出稿,我的述职演示文稿就这么做好了
openai·claude
烛衔溟7 小时前
TypeScript 类的类型 —— 作为类型使用
javascript·ubuntu·typescript
之歆7 小时前
Day16_JavaScript 轮播图与事件工程实战(下篇)
服务器·开发语言·前端·javascript·网络·性能优化