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.

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

相关推荐
万俟淋曦5 分钟前
【论文速递】2025年第30周(Jul-20-26)(Robotics/Embodied AI/LLM)
人工智能·深度学习·ai·机器人·论文·robotics·具身智能
鸡吃丸子19 分钟前
Next.js 入门指南
开发语言·javascript·next.js
罚时大师月色32 分钟前
Vue+ts 如何实现父组件和子组件通信
javascript·vue.js·ecmascript
漂流瓶jz1 小时前
快速定位源码问题:SourceMap的生成/使用/文件格式与历史
前端·javascript·前端工程化
fury_1231 小时前
vue3:数组的.includes方法怎么使用
前端·javascript·vue.js
默 语1 小时前
AI驱动软件测试全流程自动化:从理论到实践的深度探索
运维·人工智能·驱动开发·ai·自动化·ai技术·测试全流程
weixin_405023371 小时前
包资源管理器NPM 使用
前端·npm·node.js
宁&沉沦1 小时前
Cursor 科技感的登录页面提示词
前端·javascript·vue.js
CoderJia程序员甲2 小时前
GitHub 热榜项目 - 日榜(2025-10-18)
ai·开源·大模型·github·ai教程
Dragonir2 小时前
React+Three.js 实现 Apple 2025 热成像 logo
前端·javascript·html·three.js·页面特效