TypeSafe 的 System One API 會根據型別化問題評估應用程式狀態,並回傳結構化答案。 在 Azure Databricks 上,透過 Unity Gateway 向一個啟用 System One 的模型服務發送請求。 Databricks 路由使用 System One 的請求與回應格式。
當應用程式需要簡潔且結構化的決策,而非生成的散文時,請使用 System One API。 當回應時間很重要時,例如判斷請求是否需要升級、選擇路由標籤,或依照評分標準為其評分,這種情況很適合。 回應時間取決於模型服務與請求負載。
關於 SQL 中資料表列的決策,請參見 ai_decide 函式。
Requirements
- 一個支援 Unity Catalog 與 Unity Gateway 的工作區。
- 一個由 System One 相容模型支援的 Unity 目錄模型服務。 範例中使用
openjev-qwen35-4b了模型服務,其完全限定名稱為system.ai.openjev-qwen35-4b。 - 允許執行模型服務。
System One 路由需要 Unity Catalog 模型服務。 它不支援模型提供者服務或非 Unity Catalog 供應端點。
查詢模型服務
請求主體包含完整限定模型服務名稱、要評估的狀態,以及一個或多個具名問題。 每個問題都使用 noul、choice 或 score 類型之一。
以下請求包含每種類型的一個問題:
curl \
-u token:$DATABRICKS_TOKEN \
-X POST \
-H "Content-Type: application/json" \
-d '{
"model": "system.ai.openjev-qwen35-4b",
"state": {
"message": "My card was charged twice for the same order and I need a refund.",
"channel": "support"
},
"questions": {
"is_billing": {
"type": "noul",
"instructions": "Is this a billing-related request?",
"criteria": {
"true": "The message concerns a charge, payment, invoice, or refund.",
"false": "The message does not concern billing."
}
},
"intent": {
"type": "choice",
"instructions": "Which intent best matches the message?",
"criteria": {
"refund": "The customer requests a refund.",
"duplicate_charge": "The customer reports being charged more than once.",
"other": "Another request."
}
},
"urgency": {
"type": "score",
"instructions": "How urgent is the request?",
"criteria": [
"Can wait",
"Needs attention soon",
"Urgent"
]
}
}
}' \
https://<workspace_host>/ai-gateway/typesafe/v1/systemone
請在請求的 system.ai.openjev-qwen35-4b 欄位中使用完整限定的 Unity 目錄模型服務名稱 model。
請求欄位
| Field | 類型 | Description |
|---|---|---|
model |
String | Unity 目錄模型服務的完整限定名稱,例如 system.ai.openjev-qwen35-4b。 |
state |
字串、物件或陣列 | 內容需要評估。 使用字串表示文字或結構化資料,用於記錄、對話或應用程式狀態。 |
questions |
物體 | 問題 ID 到問題定義的非空映射。 回應在 answers 物件中使用相同的 ID。 |
每個問題都有type、可選的instructions,以及特定類型的criteria:
Noul 問題集
noul 是否題回傳答案是肯定的機率。 可選 criteria 物件描述了 true 和 false 的意義。 提供 instructions,或提供 true 或 false 的描述。 回應包含 noul 從0(否)到1(是)的數字。
選擇題
一個choice問題會從criteria物件中選取一個選項。 每個選項對應到描述,或在不需要額外描述時對應到 null。 定義 1 到 255 之間的選項。 回應包含所選的 choice、每個選項的機率,以及一個 confidence 值。
評分題目
一個 score 問題根據有序 criteria 陣列評估狀態。 回應包含一個經 score 機率加權的 legend、將等級索引對應到標準、各等級的機率,以及一個 confidence 值。 請定義1到10級。
回應格式
回應包含模型識別碼及 answers 中每個問題的一個答案。 代幣使用情況顯示於 usage,以及 input_tokens 和 output_tokens:
{
"model": "<returned-model-id>",
"answers": {
"is_billing": {
"type": "noul",
"noul": 0.98
},
"intent": {
"type": "choice",
"choice": "duplicate_charge",
"confidence": 0.965,
"probabilities": {
"refund": 0.023,
"duplicate_charge": 0.977,
"other": 0.0002
}
},
"urgency": {
"type": "score",
"score": 1.902,
"confidence": 0.852,
"legend": {
"0": "Can wait",
"1": "Needs attention soon",
"2": "Urgent"
},
"probabilities": {
"0": 0.0069,
"1": 0.0845,
"2": 0.9086
}
}
},
"usage": {
"input_tokens": 238,
"output_tokens": 0
}
}
此回應基於上述請求,數值為四捨五入。 答案、機率、信心值、令牌數量及回傳的模型識別碼會依請求與後端而異。 回應 model 值會識別後端回報的模型,且可能與請求的完整限定模型服務名稱不同。
請求錯誤
對於請求驗證錯誤,路由會回傳 HTTP detail 和描述無效請求的 422 陣列。