Decisions API 现已正式发布。查看自公开测试版以来的新变化。
Decisions API 评估文本、图片和 JSON,并以约为 Responses API 10 倍的速度返回具有明确类型的答案。你可以获取某个条件成立的概率、从固定集合中选择的选项,或按照评分标准计算的分数。使用这些答案,可以在应用中对内容分类、分发请求,并确定工作的优先级。
编写代码前,可以在 Playground 中试用 Decisions API,尝试不同的问题和输入。
使用目前唯一受支持的模型 gpt-6-luna,向 POST /v1/decisions 发送请求。
新变化
自公开测试版推出以来,Decisions API 新增了以下能力:
- 提示词缓存。 在请求之间复用共享输入,并享受缓存折扣。
- 问题指令中的图片。 为每个问题提供自己的图片,与共享依据进行比较。
- JSON 输入。 通过
input_json内容部分直接传入结构化数据。 - 每次请求支持更多问题。 每次请求最多可提出 400 个问题,公开测试版的上限为 200 个。
- 托管图片输入。 除内嵌的 base64 data URL 外,还可以传入可公开访问的 HTTP 或 HTTPS 图片 URL。
- 对话历史。 评估消息,以及函数调用、自定义工具调用和它们的输出。
- 组织用量报告。 跟踪词元用量和请求数量。
- 原生 GPT-Live 集成。 让 Live 直接调用 Decisions,或在输入或输出转写文本到达时触发决策。
- Private Link。 通过私有连接发送 Decisions 请求。
决策如何工作
一个请求包含三个部分:
| 字段 | 用途 |
|---|---|
model |
评估请求的模型。目前仅支持 gpt-6-luna。 |
input |
各问题共享的依据:文本字符串,或由消息、工具调用和工具输出组成的有序数组。 |
questions |
需要评估的内容,包括每个问题的类型、指令,以及允许的选项或评分等级。 |
响应包含一个 answers 数组。为每个问题指定唯一的 name,以便识别对应答案;API 会在响应中返回该名称。
选择问题类型
| 类型 | 用途 | 主要结果 |
|---|---|---|
predicate |
检查一个条件,例如是否有可见损坏,或文本片段是否相关。 | probability:条件成立的概率估计,范围为 0 到 1。 |
choice |
选择一个选项,例如部门或内容类别。 | choice:你提供的值之一。 |
score |
按照有序等级对输入评分,例如问题严重程度。 | score:等级索引按概率加权后的平均值。 |
choice 和 score 都会返回各个离散选项的概率。对于部门这类没有顺序的类别,使用 choice。对于严重程度这类有序等级,使用 score;它会计算各等级数字索引按概率加权后的平均值,得到可能处于等级之间的分数。
当应用需要这些答案类型之一时,使用 Decisions。如果需要生成遵循自定义 JSON Schema 的对象,例如提取字段或书面解释,应在 Responses API 中使用结构化输出;如果需要模型请求带参数的工具调用,则使用函数调用。
评估对话
在 input 中传入对话历史,以结合上下文评估请求。按顺序包含消息、任何函数或自定义工具调用及其输出。使用 call_id 将每个工具输出与对应调用关联起来。
支持的内容取决于消息角色或条目类型:
| 输入条目 | 支持的内容 |
|---|---|
| 用户消息 | 文本、图片和 JSON |
| 开发者或系统消息 | 仅输入文本;系统消息按开发者消息处理 |
| 助手消息 | 输出文本或拒绝 |
| 函数或自定义工具输出 | 文本和图片,与匹配的工具调用关联 |
工具调用和输出为你的问题提供依据。Decisions 返回具有明确类型的答案;应用执行这些答案所选择的动作。不支持文件、音频和条目引用。有关可接受的输入字段,请参阅创建决策参考。
评估 JSON 数据
使用 input_json 内容部分传入结构化依据,无须先将其转换为字符串。将 JSON 对象或数组放入 data,与文本或图片部分一起置于用户消息中。在消息内容中,input_json 仅支持 user 角色。
例如,向 POST /v1/decisions 发送以下 JSON 请求体,结合订单记录评估一张支持工单:
{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Evaluate the ticket using the order evidence."
},
{
"type": "input_json",
"data": {
"ticket": { "body": "Please refund the duplicate charge." },
"order": { "charges": [49, 49] }
}
}
]
}
],
"questions": [
{
"type": "predicate",
"name": "duplicate_charge",
"instructions": "Does the ticket describe a duplicate charge supported by the order?"
}
]
}
data 内部的 role 或 image_url 等 JSON 键只是普通数据:它们不会创建消息或获取图片。答案仍使用所选的问题类型;JSON 输入不会改变响应格式。
检查图片是否有可见损坏
使用 predicate 问题检查产品照片是否存在可见损坏。此请求将图片与查找裂纹、破损或凹痕的指令结合起来。
这件物品有凹痕吗?





概率
1.00
请在下次续费前取消我的订阅。
我可以切换为按年计费,并保留当前套餐吗?
我不再需要这个了。怎样停止之后的扣费?
概率
1.00
问题
30 天后还能退货吗?
答案
收货后 30 天内接受退货。超过这个时间,商品就不符合退款条件。
请从账户中的订单页面发起退货。
标准配送需要三到五个工作日。
概率
0.90
检查图片是否有可见损坏
IMAGE_BASE64="$(base64 < product.png | tr -d '\r\n')"
curl https://api.openai.com/v1/decisions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{
"model": "gpt-6-luna",
"input": [{
"role": "user",
"content": [
{"type": "input_text", "text": "Inspect the product in this photo."},
{"type": "input_image", "image_url": "data:image/png;base64,$IMAGE_BASE64"}
]
}],
"questions": [{
"type": "predicate",
"name": "visible_damage",
"instructions": "Does the product have visible damage, such as a crack, tear, or dent? Ignore shadows and damage to the packaging."
}]
}
JSON
import { readFile } from "node:fs/promises";
import OpenAI from "openai";
const client = new OpenAI();
const imageBase64 = (await readFile("product.png")).toString("base64");
const decision = await client.decisions.create({
model: "gpt-6-luna",
input: [
{
role: "user",
content: [
{ type: "input_text", text: "Inspect the product in this photo." },
{
type: "input_image",
image_url: `data:image/png;base64,${imageBase64}`,
},
],
},
],
questions: [
{
type: "predicate",
name: "visible_damage",
instructions:
"Does the product have visible damage, such as a crack, tear, or dent? Ignore shadows and damage to the packaging.",
},
],
});
const answer = decision.answers[0];
if (answer.type === "refusal") {
console.log(`Refused: ${answer.name}`);
} else if (answer.type === "predicate") {
console.log(`Visible damage probability: ${answer.probability}`);
}
import base64
from pathlib import Path
from openai import OpenAI
client = OpenAI()
image_base64 = base64.b64encode(Path("product.png").read_bytes()).decode("ascii")
decision = client.decisions.create(
model="gpt-6-luna",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "Inspect the product in this photo."},
{
"type": "input_image",
"image_url": f"data:image/png;base64,{image_base64}",
},
],
}
],
questions=[
{
"type": "predicate",
"name": "visible_damage",
"instructions": (
"Does the product have visible damage, such as a crack, tear, or dent? "
"Ignore shadows and damage to the packaging."
),
}
],
)
answer = decision.answers[0]
if answer.type == "refusal":
print(f"Refused: {answer.name}")
elif answer.type == "predicate":
print(f"Visible damage probability: {answer.probability}")
package main
import (
"context"
"encoding/base64"
"fmt"
"os"
"github.com/openai/openai-go/v3"
)
func main() {
image, err := os.ReadFile("product.png")
if err != nil {
panic(err)
}
client := openai.NewClient()
decision, err := client.Decisions.New(context.Background(), openai.DecisionNewParams{
Model: "gpt-6-luna",
Input: openai.DecisionNewParamsInputUnion{
OfDecisionInputMessageArray: []openai.DecisionInputMessageParam{{
Content: openai.DecisionInputMessageContentUnionParam{
OfParts: []openai.DecisionInputPartUnionParam{
{OfInputText: &openai.DecisionInputTextParam{Text: "Inspect the product in this photo."}},
{OfInputImage: &openai.DecisionInputImageParam{
ImageURL: "data:image/png;base64," + base64.StdEncoding.EncodeToString(image),
}},
},
},
}},
},
Questions: []openai.DecisionNewParamsQuestionUnion{{
OfPredicate: &openai.DecisionNewParamsQuestionPredicate{
Name: openai.String("visible_damage"),
Instructions: openai.DecisionNewParamsQuestionPredicateInstructionsUnion{
OfString: openai.String("Does the product have visible damage, such as a crack, tear, or dent? Ignore shadows and damage to the packaging."),
},
},
}},
})
if err != nil {
panic(err)
}
switch answer := decision.Answers[0].AsAny().(type) {
case openai.DecisionAnswerPredicate:
fmt.Println(answer.Probability)
case openai.DecisionAnswerRefusal:
fmt.Printf("Decision refused for %s\n", answer.Name)
default:
panic("unexpected answer type")
}
}
import com.openai.models.decisions.DecisionCreateParams;
import com.openai.models.decisions.DecisionInputImage;
import com.openai.models.decisions.DecisionInputItem;
import com.openai.models.decisions.DecisionInputMessage;
import com.openai.models.decisions.DecisionInputPart;
import com.openai.models.decisions.DecisionInputText;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.List;
String imageBase64 =
Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("product.png")));
var message =
DecisionInputMessage.User.builder()
.contentOfParts(
List.of(
DecisionInputPart.ofInputText(
DecisionInputText.builder()
.text("Inspect the product in this photo.")
.build()),
DecisionInputPart.ofInputImage(
DecisionInputImage.builder()
.imageUrl("data:image/png;base64," + imageBase64)
.build())))
.build();
var decision =
client
.decisions()
.create(
DecisionCreateParams.builder()
.model("gpt-6-luna")
.inputOfDecisionInputItems(
List.of(
DecisionInputItem.ofDecisionInputMessage(
DecisionInputMessage.ofUser(message))))
.addQuestion(
DecisionCreateParams.Question.Predicate.builder()
.name("visible_damage")
.instructions(
"Does the product have visible damage, such as a crack, tear, or"
+ " dent? Ignore shadows and damage to the packaging.")
.build())
.build());
var answer = decision.answers().get(0);
if (answer.isRefusal()) {
System.out.println("Refused: " + answer.asRefusal().name().orElse("visible_damage"));
} else {
System.out.println(answer.asPredicate().probability());
}
require "base64"
require "openai"
image_base64 = Base64.strict_encode64(File.binread("product.png"))
client = OpenAI::Client.new
decision = client.decisions.create(
model: "gpt-6-luna",
input: [
{
role: :user,
content: [
{
type: :input_text,
text: "Inspect the product in this photo."
},
{
type: :input_image,
image_url: "data:image/png;base64,#{image_base64}"
}
]
}
],
questions: [
{
type: :predicate,
name: "visible_damage",
instructions: "Does the product have visible damage, such as a crack, tear, or dent? Ignore shadows and damage to the packaging."
}
]
)
answer = decision.answers.fetch(0)
case answer
when OpenAI::Models::Decision::Answer::Predicate
puts(answer.probability)
when OpenAI::Models::Decision::Answer::Refusal
warn("Decision refused for #{answer.name}")
else
raise("Unexpected answer type: #{answer.type}")
end
响应摘录示例:
{
"answers": [
{
"type": "predicate",
"name": "visible_damage",
"probability": 0.92
}
]
}
probability 是模型对条件成立概率的估计。根据自行选择的阈值,用它标记需要复查的照片。
可以通过内嵌的 base64 data URL 或可公开访问的 HTTP 或 HTTPS URL 提供图片。此端点不支持 file_id 输入。在用户消息中组合 input_text 和 input_image 部分,即可将图片与指令或其他上下文一起评估。
在问题指令中加入图片
将所有问题共享的依据放入 input。若要为每个问题提供不同的图片,将其 instructions 设为由 input_text 和 input_image 部分组成的非空数组。此方式适用于 predicate、choice 和 score 问题。纯文本指令仍可使用字符串。
例如,向 POST /v1/decisions 发送以下 JSON 请求体,将候选图片与共享的参考图片进行比较。请将两个示例图片 URL 替换为可公开访问的图片,或使用 base64 图片 data URL:
{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "The shared image is reference image A."
},
{
"type": "input_image",
"image_url": "https://example.com/reference.jpg"
}
]
}
],
"questions": [
{
"type": "predicate",
"name": "candidate_matches_reference",
"instructions": [
{
"type": "input_text",
"text": "Is candidate image B a derivative or variant of reference image A, including recompression or resizing?"
},
{
"type": "input_image",
"image_url": "https://example.com/candidate.jpg"
}
]
}
]
}
在问题指令中加入图片时:
- 为每张候选图片添加一个问题。每个问题都将自己的候选图片与同一张共享参考图片进行评估比较。
- 直接在
instructions中提供内容部分,不要添加消息包装或role。 - 问题中的图片与
input中的图片共用请求的图片数量限制。
从固定选项中选择
choice 问题会从你提供的选项中选择一个值。使用彼此不同的值,并通过描述解释每个选项的适用情况。
模型会看到每个选项的 value,以及提供时的 description。这两个字段都是提示词的一部分,因此即使描述保持不变,更改 value 也可能改变结果。
选择字符串 value 时,优先使用 "billing" 和 "technical" 这样有意义的标签,而不是 UUID 这类不透明的标识符。
保持选项描述简洁直接,如下面的示例所示。
汽车应该选择哪条车道?

车道 10.03
车道 20.94
车道 30.03
这个月我被扣了两次费用。可以退还多收的款项吗?
每次导出 CSV 都会报错,即使刷新页面后也是如此。
我的手机丢了,无法通过两步验证。
账单1.00
技术支持0.00
账户访问0.00
NORTHLINE STUDIO № 1042
发票
账单接收方:Cedar & Co.
设计服务$1,200.00
应付金额$1,200.00
付款截止日 10 月 21 日

NORTHLINE STUDIO № 6853
已收款
感谢购买。
设计服务$1,200.00
实付总额$1,200.00
Visa 尾号 4242 · 已批准

NORTHLINE STUDIO 01 / 03
服务协议
Northline Studio 与 Cedar & Co. 之间
服务提供方同意提供为期十二个月的设计服务。
服务提供方签名客户签名

发票1.00
收据0.00
合同0.00
此请求将客户投诉分发给相应部门:
分发客户投诉
curl https://api.openai.com/v1/decisions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": "I was charged twice for my order.",
"questions": [{
"type": "choice",
"name": "department",
"instructions": "Which department should handle this complaint?",
"choices": [
{"value": "billing", "description": "Payments, invoices, and refunds."},
{"value": "technical", "description": "Problems using the product."},
{"value": "shipping", "description": "Delivery and tracking."},
{"value": "other", "description": "Requests outside these categories."}
]
}]
}'
import OpenAI from "openai";
const client = new OpenAI();
const decision = await client.decisions.create({
model: "gpt-6-luna",
input: "I was charged twice for my order.",
questions: [
{
type: "choice",
name: "department",
instructions: "Which department should handle this complaint?",
choices: [
{ value: "billing", description: "Payments, invoices, and refunds." },
{ value: "technical", description: "Problems using the product." },
{ value: "shipping", description: "Delivery and tracking." },
{ value: "other", description: "Requests outside these categories." },
],
},
],
});
const answer = decision.answers[0];
if (answer.type === "refusal") {
console.log(`Refused: ${answer.name}`);
} else if (answer.type === "choice") {
console.log(
`Department: ${answer.choice} (confidence: ${answer.confidence})`
);
}
from openai import OpenAI
client = OpenAI()
decision = client.decisions.create(
model="gpt-6-luna",
input="I was charged twice for my order.",
questions=[
{
"type": "choice",
"name": "department",
"instructions": "Which department should handle this complaint?",
"choices": [
{"value": "billing", "description": "Payments, invoices, and refunds."},
{"value": "technical", "description": "Problems using the product."},
{"value": "shipping", "description": "Delivery and tracking."},
{"value": "other", "description": "Requests outside these categories."},
],
}
],
)
answer = decision.answers[0]
if answer.type == "refusal":
print(f"Refused: {answer.name}")
elif answer.type == "choice":
print(f"Department: {answer.choice} (confidence: {answer.confidence})")
package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
func main() {
client := openai.NewClient()
decision, err := client.Decisions.New(context.Background(), openai.DecisionNewParams{
Model: "gpt-6-luna",
Input: openai.DecisionNewParamsInputUnion{OfString: openai.String("I was charged twice for my order.")},
Questions: []openai.DecisionNewParamsQuestionUnion{{
OfChoice: &openai.DecisionNewParamsQuestionChoice{
Name: openai.String("department"),
Instructions: openai.DecisionNewParamsQuestionChoiceInstructionsUnion{
OfString: openai.String("Which department should handle this complaint?"),
},
Choices: []openai.DecisionNewParamsQuestionChoiceChoice{
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("billing")},
Description: openai.String("Payments, invoices, and refunds."),
},
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("technical")},
Description: openai.String("Problems using the product."),
},
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("shipping")},
Description: openai.String("Delivery and tracking."),
},
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("other")},
Description: openai.String("Requests outside these categories."),
},
},
},
}},
})
if err != nil {
panic(err)
}
switch answer := decision.Answers[0].AsAny().(type) {
case openai.DecisionAnswerChoice:
fmt.Println(answer.Choice.AsString(), answer.Confidence, answer.Probabilities)
case openai.DecisionAnswerRefusal:
fmt.Printf("Decision refused for %s\n", answer.Name)
default:
panic("unexpected answer type")
}
}
import com.openai.models.decisions.DecisionChoiceOption;
import com.openai.models.decisions.DecisionCreateParams;
import com.openai.models.decisions.DecisionCreateParams.Question.Choice;
var decision =
client
.decisions()
.create(
DecisionCreateParams.builder()
.model("gpt-6-luna")
.input("I was charged twice for my order.")
.addQuestion(
Choice.builder()
.name("department")
.instructions("Which department should handle this complaint?")
.addChoice(
DecisionChoiceOption.builder()
.value("billing")
.description("Payments, invoices, and refunds.")
.build())
.addChoice(
DecisionChoiceOption.builder()
.value("technical")
.description("Problems using the product.")
.build())
.addChoice(
DecisionChoiceOption.builder()
.value("shipping")
.description("Delivery and tracking.")
.build())
.addChoice(
DecisionChoiceOption.builder()
.value("other")
.description("Requests outside these categories.")
.build())
.build())
.build());
var answer = decision.answers().get(0);
if (answer.isRefusal()) {
System.out.println("Refused: " + answer.asRefusal().name().orElse("department"));
} else {
var choice = answer.asChoice();
System.out.println(choice.choice().asString());
System.out.println(choice.probabilities());
System.out.println(choice.confidence());
}
require "openai"
client = OpenAI::Client.new
decision = client.decisions.create(
model: "gpt-6-luna",
input: "I was charged twice for my order.",
questions: [
{
type: :choice,
name: "department",
instructions: "Which department should handle this complaint?",
choices: [
{
value: "billing",
description: "Payments, invoices, and refunds."
},
{
value: "technical",
description: "Problems using the product."
},
{
value: "shipping",
description: "Delivery and tracking."
},
{
value: "other",
description: "Requests outside these categories."
}
]
}
]
)
answer = decision.answers.fetch(0)
case answer
when OpenAI::Models::Decision::Answer::Choice
puts(answer.choice, answer.confidence, answer.probabilities)
when OpenAI::Models::Decision::Answer::Refusal
warn("Decision refused for #{answer.name}")
else
raise("Unexpected answer type: #{answer.type}")
end
响应摘录示例:
{
"answers": [
{
"type": "choice",
"name": "department",
"choice": "billing",
"probabilities": [
{ "value": "billing", "probability": 0.95 },
{ "value": "technical", "probability": 0.02 },
{ "value": "shipping", "probability": 0.01 },
{ "value": "other", "probability": 0.02 }
],
"confidence": 0.93
}
]
}
答案的 choice 字段包含一个已提供的值,这里是 "billing"。它还包含一个选项的 probabilities 数组和一个 confidence 字段。有关设置阈值的指导,请参阅解读答案。
当你的类别无法覆盖所有可能的输入时,加入 "other" 这样的兜底选项。应用可以将该结果发送到通用审核队列。
按评分标准打分
score 问题会按照 2–10 个有序的 levels 评估输入。为每个等级定义标准,并按从低到高的顺序排列。
这个包裹损坏得有多严重?



0.00/ 2
0 · 无1 · 轻微2 · 严重
无损坏1.00
轻微损坏0.00
严重损坏0.00
可以添加深色模式吗?我晚上工作时会很有用。
一位同事的 CSV 导出一直失败。团队其他人仍然可以导出。
所有客户都无法结账。我们已经有 20 分钟没有处理任何订单了。
0.00/ 2
0 · 低1 · 中2 · 高
低1.00
中0.00
高0.00
按严重程度等级为问题评分
curl https://api.openai.com/v1/decisions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": "Export fails in Safari but works in Chrome.",
"questions": [{
"type": "score",
"name": "severity",
"instructions": "How severe is this issue?",
"levels": [
{"label": "Cosmetic", "description": "Appearance only; no lost functionality."},
{"label": "Workaround available", "description": "A task fails, but another way works."},
{"label": "Fully blocked", "description": "A task fails with no workaround."}
]
}]
}'
import OpenAI from "openai";
const client = new OpenAI();
const decision = await client.decisions.create({
model: "gpt-6-luna",
input: "Export fails in Safari but works in Chrome.",
questions: [
{
type: "score",
name: "severity",
instructions: "How severe is this issue?",
levels: [
{
label: "Cosmetic",
description: "Appearance only; no lost functionality.",
},
{
label: "Workaround available",
description: "A task fails, but another way works.",
},
{
label: "Fully blocked",
description: "A task fails with no workaround.",
},
],
},
],
});
const answer = decision.answers[0];
if (answer.type === "refusal") {
console.log(`Refused: ${answer.name}`);
} else if (answer.type === "score") {
console.log(`Severity: ${answer.score} (confidence: ${answer.confidence})`);
}
from openai import OpenAI
client = OpenAI()
decision = client.decisions.create(
model="gpt-6-luna",
input="Export fails in Safari but works in Chrome.",
questions=[
{
"type": "score",
"name": "severity",
"instructions": "How severe is this issue?",
"levels": [
{
"label": "Cosmetic",
"description": "Appearance only; no lost functionality.",
},
{
"label": "Workaround available",
"description": "A task fails, but another way works.",
},
{
"label": "Fully blocked",
"description": "A task fails with no workaround.",
},
],
}
],
)
answer = decision.answers[0]
if answer.type == "refusal":
print(f"Refused: {answer.name}")
elif answer.type == "score":
print(f"Severity: {answer.score} (confidence: {answer.confidence})")
package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
func main() {
client := openai.NewClient()
decision, err := client.Decisions.New(context.Background(), openai.DecisionNewParams{
Model: "gpt-6-luna",
Input: openai.DecisionNewParamsInputUnion{OfString: openai.String("Export fails in Safari but works in Chrome.")},
Questions: []openai.DecisionNewParamsQuestionUnion{{
OfScore: &openai.DecisionNewParamsQuestionScore{
Name: openai.String("severity"),
Instructions: openai.DecisionNewParamsQuestionScoreInstructionsUnion{
OfString: openai.String("How severe is this issue?"),
},
Levels: []openai.DecisionNewParamsQuestionScoreLevel{
{Label: "Cosmetic", Description: openai.String("Appearance only; no lost functionality.")},
{Label: "Workaround available", Description: openai.String("A task fails, but another way works.")},
{Label: "Fully blocked", Description: openai.String("A task fails with no workaround.")},
},
},
}},
})
if err != nil {
panic(err)
}
switch answer := decision.Answers[0].AsAny().(type) {
case openai.DecisionAnswerScore:
fmt.Println(answer.Score, answer.Confidence, answer.Probabilities)
case openai.DecisionAnswerRefusal:
fmt.Printf("Decision refused for %s\n", answer.Name)
default:
panic("unexpected answer type")
}
}
import com.openai.models.decisions.DecisionCreateParams;
import com.openai.models.decisions.DecisionCreateParams.Question.Score;
var decision =
client
.decisions()
.create(
DecisionCreateParams.builder()
.model("gpt-6-luna")
.input("Export fails in Safari but works in Chrome.")
.addQuestion(
Score.builder()
.name("severity")
.instructions("How severe is this issue?")
.addLevel(
Score.Level.builder()
.label("Cosmetic")
.description("Appearance only; no lost functionality.")
.build())
.addLevel(
Score.Level.builder()
.label("Workaround available")
.description("A task fails, but another way works.")
.build())
.addLevel(
Score.Level.builder()
.label("Fully blocked")
.description("A task fails with no workaround.")
.build())
.build())
.build());
var answer = decision.answers().get(0);
if (answer.isRefusal()) {
System.out.println("Refused: " + answer.asRefusal().name().orElse("severity"));
} else {
var score = answer.asScore();
System.out.println(score.score());
System.out.println(score.probabilities());
System.out.println(score.confidence());
}
require "openai"
client = OpenAI::Client.new
decision = client.decisions.create(
model: "gpt-6-luna",
input: "Export fails in Safari but works in Chrome.",
questions: [
{
type: :score,
name: "severity",
instructions: "How severe is this issue?",
levels: [
{
label: "Cosmetic",
description: "Appearance only; no lost functionality."
},
{
label: "Workaround available",
description: "A task fails, but another way works."
},
{
label: "Fully blocked",
description: "A task fails with no workaround."
}
]
}
]
)
answer = decision.answers.fetch(0)
case answer
when OpenAI::Models::Decision::Answer::Score
puts(answer.score, answer.confidence, answer.probabilities)
when OpenAI::Models::Decision::Answer::Refusal
warn("Decision refused for #{answer.name}")
else
raise("Unexpected answer type: #{answer.type}")
end
响应摘录示例:
{
"answers": [
{
"type": "score",
"name": "severity",
"score": 1.1,
"probabilities": [
{ "value": 0, "label": "Cosmetic", "probability": 0.1 },
{ "value": 1, "label": "Workaround available", "probability": 0.7 },
{ "value": 2, "label": "Fully blocked", "probability": 0.2 }
],
"confidence": 0.55
}
]
}
等级索引从 0 开始。这里,0 表示外观问题,1 表示存在替代办法,2 表示完全受阻。返回的 score 是按概率加权后的平均值,因此可能落在等级之间。在这个例子中,0.1、0.7 和 0.2 的概率得到 1.1 分。
答案还包含 confidence 和每个等级的 probabilities。该分数概括了各等级上的概率分布。如果要选择单个类别,请使用 choice。
提出多个问题
每次请求包含 1 到 400 个问题。将相互独立的问题放入同一个 questions 数组,以评估共享输入。对于产品照片,一次请求可以检查损坏情况并对产品类别分类。每个问题可以使用不同的类型。
对于依赖先前答案的决策,请分别发送请求。例如,先检查是否损坏,再根据结果决定是否请求一个维修类别。
围绕可观察的标准编写问题。将不同的关注点拆成不同的问题,让各选项具有明确不同的含义,并为相邻的评分等级定义不同的标准。
解读答案
predicate 返回条件成立的概率估计。choice 和 score 答案返回概率分布,以及单独的 confidence 字段。
使用应用中的带标签示例,为路由、过滤或审核设置阈值。根据误报和漏报的成本选择阈值。
使用提示词缓存复用共享输入
提示词缓存让重复请求能够复用共享 input 中匹配的前缀,并享受优惠的缓存读取价格。例如,将参考文档或图片保留在 input 中,每次请求只更改问题。questions 中的内容,包括特定问题的图片,都不属于可复用前缀。
默认情况下,Decisions 在共享 input 的末尾设置一个隐式缓存断点。现有请求无须更改请求体即可受益。可复用前缀必须至少包含 1,024 个词元;问题内容不计入这一阈值。确保各请求中的前缀完全相同,以便复用。
使用 prompt_cache_key,按调用方提供的键划分缓存复用。若要控制边界,在共享 input 的文本或图片内容部分添加 prompt_cache_breakpoint: {"mode": "explicit"}。将 prompt_cache_options.mode 设为 "explicit",即可仅使用标记的边界。在显式模式下,没有标记边界的请求不会使用提示词缓存。问题指令中不支持断点。
查看 usage.input_tokens_details.cached_tokens 了解缓存读取,查看 usage.input_tokens_details.cache_write_tokens 了解缓存写入。这两项计数均包含在 usage.input_tokens 中;不要再将它们加到该总数上。缓存概念请参阅提示词缓存指南,支持的请求控制项请参阅 Decisions 参考。
监控用量
使用 GET /v1/organization/usage/decisions 获取组织的 Decisions 词元用量和请求数量。使用具有 api.usage.read 权限的管理员 API 密钥进行身份验证。
选择时间范围和时间桶宽度,然后按项目、API 密钥或模型筛选或分组结果。num_model_requests 字段统计请求,而非单个问题:包含多个问题的请求也只计为一次。有关筛选条件和分页,请参阅 Decisions 用量参考。
价格与可用性
使用 gpt-6-luna 时,未缓存输入的费用为每 100 万词元 $0.10。提示词缓存命中享受优惠的输入价格;缓存写入会收费。缓存读取和缓存写入费率与标准 gpt-6-luna 提示词缓存费率相同。输出词元不收费。
区域处理附加费和长上下文输入价格倍数同样适用。这些费率适用于 /v1/decisions;其他使用 gpt-6-luna 的请求遵循相应的模型和处理档位价格。
Decisions API 为符合资格的客户提供零数据保留(ZDR)和 HIPAA 使用支持。所有受支持的 API 区域均可使用数据驻留。美国和欧洲(EEA + 瑞士)支持区域处理。有关资格要求、所需协议和限制,请参阅数据控制。
添加语音控制
将语音接入 Decisions,根据口头请求选择动作,或在用户或 GPT-Live 说话时作出响应。