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_OC3 小时前
LC 207 课程表:刚学图论那会儿,我连这是拓扑排序都没看出来
javascript·算法·leetcode
To_OC3 小时前
LC 208 实现 Trie 前缀树:曾被名字劝退,写完发现是送分题
javascript·算法·leetcode
天渺工作室4 小时前
实现一个adblock/adblock plus等浏览器广告拦截器检测插件
前端·javascript
kyriewen12 小时前
2026 年了,还在用 Node.js?Bun 迁移实战:20 分钟搞定,附踩坑记录
前端·javascript·node.js
用户479492835691517 小时前
翻完 lark-cli 的 17 万行 Go 代码,我学到了什么
后端·openai
minglie18 小时前
一个置换问题
javascript
默_笙18 小时前
🌀 别再手动写 Prompt 了!我让 AI 自己循环改到满意为止
javascript
donecoding18 小时前
3 条命令搞定闭环 Monorepo:Lerna 版本管理 + 拓扑构建 + 自定义分发
前端·前端框架·node.js
To_OC1 天前
LC 994 腐烂的橘子:人人都说是 BFS 入门题,我却写了三遍才过
javascript·算法·leetcode
To_OC1 天前
LC 200 岛屿数量:经典 DFS 入门题,我第一次写居然连方向都搞错了
javascript·算法·leetcode