TypeSafe System One APIを使用してモデルをクエリーする
TypeSafe の System One API は、アプリケーションの状態を型付きの質問に対して評価し、構造化された回答を返します。Databricks では、Unity Gateway を介して System One 対応のモデルサービスにリクエストを送信します。Databricks のルートは、System One のリクエストおよびレスポンスの形式を使用します。
アプリケーションで生成された文章ではなく、コンパクトで構造化された決定が必要な場合は、System One APIを使用します。応答時間が重要な場合(例えば、リクエストのエスカレーションが必要かどうかを判断する、ルーティングラベルを選択する、ルブリックに対してスコア付けするなど)に適しています。応答時間は、モデルサービスとリクエスト負荷によって異なります。
SQLでのテーブル行に対する判定については、 ai_decide関数を参照してください。
要件
- Unity CatalogおよびUnity Gatewayが有効化されているワークスペース。
- System One 互換モデルをバックエンドとする Unity Catalog モデルサービス。この例では
openjev-qwen35-4bモデルサービスを使用しています。完全修飾名はsystem.ai.openjev-qwen35-4bです。 - モデルサービスの実行権限。
System One ルートには Unity Catalog モデルサービスが必要です。モデルプロバイダーサービスまたは非 Unity Catalog サービングEndpointはサポートされていません。
モデルサービスをクエリーする
リクエストボディには、完全修飾モデルサービス名、評価する状態、および1つ以上の名前付きの質問が含まれます。各質問では、noul、choice、または score のいずれかのタイプを使用します。
次のリクエストには、各タイプの質問が1つずつ含まれます。
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
リクエストの model フィールドには、完全修飾された Unity Catalog モデルサービス名 (system.ai.openjev-qwen35-4b) を使用します。
リクエストフィールド
フィールド | Type | 説明 |
|---|---|---|
| String |
|
| 文字列、オブジェクト、または配列 | 評価するコンテンツ。レコード、会話、またはアプリケーションの状態に対して、テキストには文字列を使用し、構造化データには構造化データを使用します。 |
| オブジェクト | 質問 ID と質問定義の空ではないマップ。レスポンスでは、 |
各質問には、type、オプションの instructions、およびタイプ固有の criteria があります。
Noul questions
A noul question returns the probability that the answer is yes.オプションの criteria オブジェクトは、true と false の意味を記述します。instructions を指定するか、true または false の説明を提供します。応答には、0 (いいえ) から 1 (はい) までの noul 数が含まれます。
選択に関する質問
choice 質問は、criteria オブジェクトから 1 つのオプションを選択します。各オプションは、説明、または追加の説明が不要な場合は null にマッピングされます。1 から 255 個のオプションを定義します。レスポンスには、選択した choice、すべてのオプションの確率、および confidence 値が含まれます。
質問のスコアリング
score の質問は、順序付けられた criteria 配列に対して状態を評価します。レスポンスには、確率加重された score、レベルのインデックスを基準にマッピングする legend、各レベルの確率、および confidence の値が含まれます。1 から 10 までのレベルを定義します。
応答形式
応答には、モデル識別子と answers 内の各質問に対する1つの回答が含まれます。トークンの使用量は 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 422 を返し、無効なリクエストを記述する detail 配列を含めます。