跳到正文
hackernews100· chiefstorm·· 12 小時前精選AI 評分72

Decisions API 公開測試

Decisions API is in public beta

AI 導讀

Decisions API 正式進入公開測試,提供快速判斷文本或影像條件的功能。

  • - 速度:比 Responses API 快 10 倍。
  • - 回答型別:predicate(條件機率)、choice(選項機率)、score(等級加權平均)。
推薦理由

OpenAI 公開測試 Decisions API,可快速判斷文本、影像條件,幫助開發者實現自動分類與路由。

正文 · AI 翻譯

Decisions API 會評估文字、圖片或兩者,並回傳型別化答案,速度約為 Responses API 的 10 倍。可取得某條件為真的機率、固定集合中的選擇,或依據評分標準的分數。使用這些答案來分類內容、路由請求,並在您的應用程式中優先處理工作。

在 Playground 試用 Decisions API,先實驗問題與輸入,再撰寫程式碼。

The Decisions API is in public beta, and we expect to GA in the coming weeks. gpt-6-luna is the only model currently available. Use the dedicated POST /v1/decisions endpoint.

要執行下列 SDK 範例,請使用以下版本或更新的 OpenAI SDK:Python 3.26.0、JavaScript 7.30.0、Go 3.73.0、Ruby 0.101.0 與 Java 4.78.0。參見 OpenAI SDK 以取得安裝說明。

請求由三個部分組成:

欄位 目的
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 的 Structured Outputs;若需模型發出帶引數的工具呼叫,請使用 function calling。

使用 predicate 型別的問題檢查產品照片是否有可見損壞。此請求將圖片與尋找裂痕、撕裂或凹陷的說明結合。

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

範例回應摘錄:

{
  "answers": [
    {
      "type": "predicate",
      "name": "visible_damage",
      "probability": 0.92
    }
  ]
}

probability 為模型估計條件為真的機率。可根據您設定的閾值,使用它來標記需審核的照片。

圖片必須以 inline base64 資料 URL 方式呈現。此端點不支援託管的 HTTP 或 HTTPS 圖片 URL 以及 file_id 輸入。可在使用者訊息中結合 input_text 與 input_image 部分,以同時評估圖片與說明或其他背景。

choice 型別的問題會從您提供的選項中選擇一個值。請使用獨特的值與說明,說明每個選項適用的情況。

此請求將客戶投訴路由至:

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."}
      ]
    }]
  }'

範例回應摘錄:

{
  "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 型別的問題會將輸入評估於有序的 levels。為每個等級定義標準,並按升序排列。

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."}
      ]
    }]
  }'

示例回覆片段:

{
  "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 選擇單一類別。

將獨立的問題放在同一個 questions 陣列中,以評估共享輸入。對於產品照片,你可以在一次請求中檢查是否有損壞並分類產品類別。每個問題可以使用不同的型別。

對於依賴先前答案的決策,請傳送獨立的請求。例如,先檢查是否有損壞,然後使用結果決定是否請求維修類別。

根據可觀測的標準編寫問題。將不同的關注點分開到不同的問題,賦予選項明確的含義,並定義分數等級,使相鄰等級具有不同的標準。

判斷式返回條件為真的估計機率。選擇與分數答案返回機率分佈以及獨立的 confidence 欄位。

使用來自你應用程式的標記範例來設定路由、篩選或審查的閾值。根據偽陽性與偽陰性的成本來選擇閾值。

使用 gpt-6-luna 時,輸入成本為 $0.10 每 1M 代幣。你只需為輸入代幣付費:不會收取快取讀取、快取寫入或輸出代幣費用。

區域處理溢價和長上下文輸入定價乘數適用。這些費率適用於 /v1/decisions;其他使用 gpt-6-luna 的請求則遵循適用的 模型與處理層級定價。

Decisions API 支援零資料保留 (ZDR) 與符合條件客戶的 HIPAA 使用。資料居留與區域處理在美國與歐洲(EEA + 瑞士)皆受支援。請參閱 資料控制 以瞭解資格要求、所需協議與限制。

使用 Live API 的客戶端代理 從語音請求中選擇動作,並將結果回報給使用者。

來源:hackernews100 · developers.openai.com