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.

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

相关推荐
Moment24 分钟前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
爱敲代码的小鱼1 小时前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax
铅笔侠_小龙虾3 小时前
Flutter 实战: 计算器
开发语言·javascript·flutter
大模型玩家七七3 小时前
梯度累积真的省显存吗?它换走的是什么成本
java·javascript·数据库·人工智能·深度学习
2501_944711433 小时前
JS 对象遍历全解析
开发语言·前端·javascript
发现一只大呆瓜4 小时前
虚拟列表:支持“向上加载”的历史消息(Vue 3 & React 双版本)
前端·javascript·面试
孟健4 小时前
吹爆 OpenClaw!一个人 +6 个 AI 助理,我再也不想招人了
openai·agent·ai编程
SEO_juper4 小时前
2026内容营销破局指南:告别流量内卷,以价值赢信任
人工智能·ai·数字营销·2026
阔皮大师4 小时前
INote轻量文本编辑器
java·javascript·python·c#
lbb 小魔仙4 小时前
【HarmonyOS实战】React Native 表单实战:自定义 useReactHookForm 高性能验证
javascript·react native·react.js