Decisions API 現已正式推出。請參閱公開測試以來的新增功能。
Decisions API 可評估文字、圖片和 JSON,並傳回具有明確型別的答案,速度約為 Responses API 的 10 倍。你可以取得條件成立的機率、從固定選項中選出的值,或依評分規準算出的分數。應用程式可根據這些答案為內容分類、分派請求,以及安排工作的優先順序。
撰寫程式碼前,可以先在 Playground 試用 Decisions API,測試不同的問題和輸入。
將請求傳送至 POST /v1/decisions,並使用目前唯一支援的模型 gpt-6-luna。
自公開測試開始以來,Decisions API 新增了以下功能:
每個請求包含三個部分:
| 欄位 |
用途 |
model |
用來評估請求的模型。目前僅支援 gpt-6-luna。 |
input |
各問題共用的佐證資料,可以是文字字串,也可以是依序列出訊息、工具呼叫和工具輸出的陣列。 |
questions |
要評估的問題,包括各問題的類型、指示,以及允許的選項或評分等級。 |
回應包含一個 answers 陣列。為每個問題指定唯一的 name,API 會在回應中傳回相同的名稱,方便你辨識對應的答案。
| 類型 |
用途 |
主要結果 |
predicate |
檢查條件是否成立,例如是否有可見損傷,或某段文字是否相關。 |
probability:條件成立的估計機率,介於 0 到 1 之間。 |
choice |
選擇一個選項,例如部門或內容類別。 |
choice:你提供的其中一個值。 |
score |
依照有順序的等級評估輸入,例如問題的嚴重程度。 |
score:以各等級的機率為權重,計算等級索引的加權平均值。 |
choice 和 score 都會傳回各個離散選項的機率。對於沒有先後順序的類別(例如部門),請使用 choice。對於有順序的等級(例如嚴重程度),請使用 score。它會依機率對各等級的數值索引取加權平均,因此分數可能落在兩個等級之間。
如果應用程式需要上述任一類型的答案,請使用 Decisions。如果需要產生符合自訂 JSON 結構描述的物件,例如包含擷取欄位或文字說明的物件,請搭配 Responses API 使用結構化輸出。如果需要模型提出工具呼叫請求並指定引數,請使用函式呼叫。
在 input 中傳入對話記錄,讓模型根據上下文評估請求。請依序列出訊息,以及任何函式或自訂工具的呼叫與輸出。使用 call_id 將每個工具輸出與對應的呼叫配對。
支援的內容取決於訊息角色或項目類型:
| 輸入項目 |
支援的內容 |
| 使用者訊息 |
文字、圖片和 JSON |
| 開發人員或系統訊息 |
僅限輸入文字。系統訊息會視為開發人員訊息。 |
| 助理訊息 |
輸出文字或拒絕回覆 |
| 函式或自訂工具的輸出 |
與對應工具呼叫相關聯的文字和圖片 |
工具呼叫及其輸出可作為回答問題的依據。Decisions 會傳回具有明確型別的答案,再由應用程式執行答案所指定的動作。目前不支援檔案、音訊和項目參照。如需查看可接受的輸入欄位,請參閱建立決策的 API 參考文件。
使用 input_json 內容區塊即可直接傳入結構化佐證資料,無須先轉換成字串。將 JSON 物件或陣列放入 data,與其他文字或圖片區塊一起放在使用者訊息中。在訊息內容中,input_json 僅適用於 user 角色。
例如,將下列 JSON 請求主體傳送至 POST /v1/decisions,即可對照訂單記錄評估客服工單:
12345678910111213141516171819202122232425262728{
"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?"
}
]
}
role 或 image_url 等 JSON 鍵出現在 data 中時,都只是一般資料,不會建立訊息或擷取圖片。答案仍採用所選的問題類型,JSON 輸入不會改變回應格式。
使用 predicate 問題檢查產品照片中是否有可見損傷。這個請求同時提供圖片和指示,要求模型查看是否有裂痕、破口或凹痕。
「
請在下次續訂前取消我的訂閱。
我可以保留目前的方案,改成按年付費嗎?
我已經不需要這項服務了。要怎麼停止後續扣款?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22IMAGE_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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35import { 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}`);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39import 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}")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52package 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")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51import 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());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41require "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
以下是回應範例節錄:
123456789{
"answers": [
{
"type": "predicate",
"name": "visible_damage",
"probability": 0.92
}
]
}
probability 是模型估計條件成立的機率。你可以自行設定門檻,根據這個機率標記需要審查的照片。
請使用內嵌的 base64 資料 URL 或可公開存取的 HTTP 或 HTTPS URL 提供圖片。此端點不支援 file_id 輸入。在使用者訊息中結合 input_text 和 input_image 區塊,即可讓模型依照指示或其他上下文評估圖片。
將所有問題共用的佐證資料放在 input 中。如要為每個問題提供不同的圖片,請將其 instructions 設為由 input_text 和 input_image 區塊組成的非空陣列。條件判斷、選擇和評分問題都支援這種用法。純文字指示仍可使用字串。
例如,將下列 JSON 請求主體傳送至 POST /v1/decisions,即可將待比對圖片與共用的參考圖片比對。請將兩個範例圖片 URL 換成可公開存取的圖片 URL,或使用 base64 圖片資料 URL:
12345678910111213141516171819202122232425262728293031323334{
"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 這類看不出含義的識別碼。
選項說明應簡潔明瞭,如下列範例所示。
「
這個月我被扣了兩次款。可以退還多收的款項嗎?
每次匯出 CSV 都會出現錯誤,重新整理頁面後還是一樣。
我的手機遺失了,現在無法通過兩步驟驗證。
NORTHLINE STUDIO № 1042
付款方:Cedar & Co.
設計服務$1,200.00
應付金額$1,200.00
NORTHLINE STUDIO № 6853
感謝您的購買。
設計服務$1,200.00
實付總額$1,200.00
NORTHLINE STUDIO 01 / 03
締約雙方:Northline Studio 與 Cedar & Co.
服務提供方同意提供為期十二個月的設計服務。
服務提供方簽名客戶簽名
以下請求會判斷客訴應分派給哪個部門:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18curl 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."}
]
}]
}'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29import 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})`
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26from 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})")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53package 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")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47import 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());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42require "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
以下是回應範例節錄:
12345678910111213141516{
"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 評估輸入。請定義每個等級的判定標準,並由低到高排列。
「
可以新增深色模式嗎?這樣我晚上工作時會方便一些。
有一位同事一直無法匯出 CSV,團隊其他人仍可正常匯出。
所有客戶都無法結帳。我們已經有 20 分鐘沒能處理任何訂單了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17curl 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."}
]
}]
}'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35import 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})`);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34from 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})")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40package 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")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41import 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());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38require "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
以下是回應範例節錄:
123456789101112131415{
"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 陣列中,即可針對共用輸入進行評估。例如,對於一張產品照片,可以在同一個請求中檢查是否有損傷,並判斷產品類別。每個問題都可以使用不同的類型。
如果決策取決於先前的答案,請分別傳送請求。例如,先檢查是否有損傷,再根據結果決定是否需要詢問維修類別。
請根據可觀察的條件撰寫問題。將不同的判斷事項拆成不同問題,讓各選項的意義明確區隔,並為相鄰的評分等級訂定不同的判定標準。
條件判斷問題會傳回條件成立的估計機率。選擇和評分問題的答案則包含機率分布,以及獨立的 confidence 欄位。
使用應用程式中已標註的範例,為分派、篩選或審查設定門檻。選擇門檻時,請考量偽陽性和偽陰性的代價。
透過提示詞快取,多次傳送請求時,只要共用 input 的前綴相符,就能重複使用該前綴,並享有快取讀取優惠費率。例如,可以將參考文件或圖片保留在 input 中,每次請求只更換問題。questions 中的內容(包括問題專屬的圖片)不在可重複使用的前綴範圍內。
預設情況下,Decisions 會在共用 input 的結尾設定隱含的快取中斷點。既有請求無須修改請求主體即可使用快取。可重複使用的前綴必須至少包含 1,024 個 Token,問題內容不計入此門檻。請確保各請求的前綴完全相同,以便重複使用。
使用 prompt_cache_key 即可依呼叫端提供的鍵劃分快取的重複使用範圍。如需自行指定快取邊界,請將 prompt_cache_breakpoint: {"mode": "explicit"} 加入共用 input 中的文字或圖片內容區塊。將 prompt_cache_options.mode 設為 "explicit",即可只使用已標記的邊界。在明確指定邊界的模式下,如果請求中沒有標記任何邊界,就不會使用提示詞快取。問題指示不支援快取中斷點。
查看 usage.input_tokens_details.cached_tokens 可取得從快取讀取的 Token 數量,查看 usage.input_tokens_details.cache_write_tokens 則可取得寫入快取的 Token 數量。這兩項數量均已計入 usage.input_tokens,請勿重複加總。如需瞭解快取概念,請參閱提示詞快取指南。如需查看請求支援的控制選項,請參閱 Decisions 參考文件。
使用 GET /v1/organization/usage/decisions 取得組織的 Decisions Token 用量和請求數。請使用具有 api.usage.read 權限的管理員 API 金鑰進行驗證。
選擇時間範圍和每個統計區間的長度,再依專案、API 金鑰或模型篩選結果或將結果分組。num_model_requests 欄位統計的是請求數,即使一個請求包含多個問題,也只計算一次。如需瞭解篩選和分頁方式,請參閱 Decisions 用量參考文件。
使用 gpt-6-luna 時,未快取輸入的費率為每 100 萬個 Token 0.10 美元。命中提示詞快取的輸入適用優惠費率,寫入快取則會收費。快取讀取與寫入的費率均與 gpt-6-luna 的標準提示詞快取費率相同。輸出 Token 不收費。
區域處理附加費與長上下文輸入的費率倍數均適用。上述費率適用於 /v1/decisions。其他使用 gpt-6-luna 的請求則依相應的模型與處理層級費率計費。
符合資格的客戶可在 Decisions API 使用零資料保留(ZDR),也可將此 API 用於受 HIPAA 規範的情境。所有支援的 API 區域均提供資料駐留。美國和歐洲(歐洲經濟區及瑞士)支援區域處理。如需瞭解資格要求、必要協議和限制,請參閱資料控制。
將語音連接至 Decisions,即可根據口頭請求選擇動作,或在使用者或 GPT-Live 說話時即時做出反應。