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.

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

相关推荐
To_OC4 小时前
我被 useState 坑了两次之后,终于把它的脾气摸透了
前端·javascript·react.js
幸福指北5 小时前
🚀 开源了,一个人 + AI 肝出一个 AI 终端 | AShell 技术分享
运维·人工智能·ai·终端
人间凡尔赛6 小时前
2026多智能体系统深度解析:从GPT-5.6 Ultra到开源框架,构建你的Agent军团
ai·agent·多智能体·langgraph·crewai·gpt-5.6
万邦科技Lafite6 小时前
1688 item_get API 一键获取商品信息实战指南
api·电商开放平台·淘宝开放平台·1688开放平台·api开放接口
AI办公探索者7 小时前
仓储物流AI任务执行的技术拆解:从WMS自动化到多设备协同的落地路径
运维·人工智能·ai·自动化
天然玩家7 小时前
【生产力】GPT-5.6 发布:前沿智能、智能体协作与更高性价比
llm·openai·gpt5.6
灵感__idea7 小时前
《AI工程》:构建应用,需要哪些技术?(解惑篇)
aigc·openai·ai编程
武雄(小星Ai)7 小时前
2026 AI编程工具横评:Trae、Cursor、Copilot、Claude Code实测对比
ai·copilot·cursor·编程工具·trae·claude code·对比评测
VIP_CQCRE9 小时前
最近发现一个小工具:把 Ace Data Cloud 接入 AI 助手
ai·开发工具·mcp
kyriewen9 小时前
我review了一份Vibe Coding写的前端代码——能跑,但5个地方迟早要命
前端·javascript·ai编程