リクエストパラメーター Content-Type · String · ヘッダー · 必須 リクエストの種類: application/json. Authorization · String · ヘッダー · 必須 API キー。形式: Bearer $DASHSCOPE_API_KEY. model · String · 本文 · 必須 モデル名: decision-model-preview. state · String / Object / Array · 本文 · 必須 判断対象となる業務の状態です。チケットのテキスト、会話、構造化オブジェクトなどを指定します。オブジェクトはモデルに送信される前にシリアライズされます。 questions · Object · 本文 · 必須 質問のマップです。キーは呼び出し側で定義する質問 ID、値は次のフィールドを含む質問オブジェクトです。 質問オブジェクトのプロパティ type · String · 必須 質問の種類:
choice: 単一選択
noul: はい/いいえ
score: 順序尺度
instructions · String · 任意 質問の説明または判断基準です。 criteria · Object / Array · 型によって異なる
choice: 選択肢名 → 選択肢の説明のマップです(1~255 項目。すべての選択肢とフォールバック用の other を指定することを推奨します)。
noul: 任意の {"true":…, "false":…} の説明です。
score: 低い段階から高い段階への説明の配列です(2~10 段階。明確に区別できる 3~7 段階を推奨します)。
制限と推奨事項
- 質問数に固定の上限はありません(推奨:≤ 16。レイテンシは質問数にほぼ比例して増加します)。
choice の選択肢:≤ 255。
score の段階数:2~255(3~7 を推奨)。
- コンテキスト:最大 65536 トークン。長すぎる
state は拒否されるか切り詰められます。
| リクエスト例 DashScope SDK はすでに意思決定モデルをサポートしています(TypeSafe System One プロトコルとの互換):
- Python:DashScope SDK 2.0.1 以降(意思決定モデルは 2.0.1 で追加された機能で、旧バージョンには
client.decision インターフェースがなく、AttributeError が発生します)。インストールコマンド:pip install -U "dashscope>=2.0.1"。SDK のインストールも参照してください。SDK はワークスペースとリージョンから /compatible-mode/v1/systemone エンドポイントを自動的に構築します。
- Java:DashScope SDK 2.23.3 以降(意思決定モデルは 2.23.3 で追加された機能で、旧バージョンには
com.alibaba.dashscope.decision パッケージがありません)。Maven 座標:com.alibaba:dashscope-sdk-java:2.23.3(Gradle:implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: '2.23.3')。API キーはデフォルトで環境変数 DASHSCOPE_API_KEY から読み取られます。
- 呼び出しが失敗した場合、Python SDK は
DashScopeError 例外を、Java SDK は ApiException をスローします。
汎用の TypeSafe SDK(typesafe-sdk)を使用することもできます。base_url を Bailian ゲートウェイに設定すると、SDK は /v1/systemone を自動的に追加し、レスポンスを解析します。インストールコマンド:pip install typesafe-sdk。 チケットの振り分け1 件のリクエストで、担当チームの割り当て(choice)、エスカレーション(noul)、重大度(score)の 3 つを同時に判断します。次の例ではシンガポールリージョンを使用します。 DashScope Pythonimport os
import dashscope
# 以下はシンガポールリージョンの設定です。"{WorkspaceId}" を実際のワークスペース ID に置き換えてください。設定はリージョンごとに異なります。
# 意思決定モデルのエンドポイントは常にワークスペースゲートウェイの compatible-mode パス配下にあり、SDK がワークスペースとリージョンから自動的に構築します。
client = dashscope.Client(
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
result = client.decision.create(
model="decision-model-preview",
state={"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited."},
questions={
"department": {"type": "choice", "instructions": "Which team should handle this?",
"criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
"escalate": {"type": "noul", "instructions": "Should on-call staff be notified immediately?"},
"severity": {"type": "score", "instructions": "How severe is this issue?",
"criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
"Core functionality unavailable, no workaround", "Severe business or security impact"]},
},
)
print(result.answers["department"].choice) # 選択されたオプション
print(result.answers["escalate"].noul) # P(yes)
print(result.answers["severity"].score) # 確率で重み付けされたレベルインデックス
print(result.usage.input_tokens, result.latency_ms)
DashScope Javaimport com.alibaba.dashscope.decision.DecisionModel;
import com.alibaba.dashscope.decision.DecisionModelParam;
import com.alibaba.dashscope.decision.DecisionModelResult;
import com.alibaba.dashscope.decision.DecisionQuestion;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class DecisionDemo {
public static void main(String[] args) throws Exception {
// API キーはデフォルトで環境変数 DASHSCOPE_API_KEY から読み取られます。
// コンストラクターにはワークスペース ID とリージョンを渡します。SDK は
// https://{WorkspaceId}.{region}.maas.aliyuncs.com/compatible-mode/v1/systemone を構築します
Map<String, Object> state = new HashMap<>();
state.put("ticket_id", "T-1001");
state.put("content", "More than 24 hours after payment, the order has not been credited. The user cannot continue using core services and demands immediate handling.");
Map<String, String> options = new LinkedHashMap<>();
options.put("billing", "Payment, refund, and billing issues");
options.put("technical", "Product failure and integration issues");
List<String> levels = Arrays.asList(
"Minor issue, no impact on functionality",
"Some functionality affected, but a workaround exists",
"Core functionality unavailable, no workaround",
"Severe business or security impact");
Map<String, DecisionQuestion> questions = new LinkedHashMap<>();
questions.put("department", DecisionQuestion.choice("Which team should handle this?", options));
questions.put("escalate", DecisionQuestion.noul("Should on-call staff be notified immediately?"));
questions.put("severity", DecisionQuestion.score("How severe is this issue?", levels));
DecisionModelParam param = DecisionModelParam.builder()
.model(DecisionModelParam.Models.DECISION_MODEL_PREVIEW)
.state(state)
.questions(questions)
.build();
DecisionModel decisionModel = new DecisionModel("{WorkspaceId}", "ap-southeast-1");
DecisionModelResult result = decisionModel.call(param);
System.out.println(JsonUtils.toJson(result));
}
}
TypeSafe Pythonimport os
from typesafe_sdk import TypeSafeClient
client = TypeSafeClient(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode",
)
result = client.system_one(
model="decision-model-preview",
state={"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited."},
questions={
"department": {"type": "choice", "instructions": "Which team should handle this?",
"criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
"escalate": {"type": "noul", "instructions": "Should on-call staff be notified immediately?"},
"severity": {"type": "score", "instructions": "How severe is this issue?",
"criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
"Core functionality unavailable, no workaround", "Severe business or security impact"]},
},
)
print(result.answers["department"]) # choice, confidence, probabilities
print(result.answers["escalate"]) # noul P(yes)
print(result.answers["severity"]) # score, legend, probabilities
curlcurl -sS -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "decision-model-preview",
"state": {"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited. The user cannot continue using core services and demands immediate handling."},
"questions": {
"department": {"type": "choice", "instructions": "Which team should handle this?",
"criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
"escalate": {"type": "noul", "instructions": "Should on-call staff be notified immediately?"},
"severity": {"type": "score", "instructions": "How severe is this issue?",
"criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
"Core functionality unavailable, no workaround", "Severe business or security impact"]}
}
}'
はい/いいえの判定noul の質問は P(yes) を返します。0 は「いいえ」、1 は「はい」を表します。次の例ではシンガポールリージョンを使用します。
DashScope Pythonimport os
import dashscope
client = dashscope.Client(
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
result = client.decision.create(
model="decision-model-preview",
state="Is this comment asking for a refund?",
questions={"refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}},
)
print(result.answers["refund"].noul) # P(yes)
DashScope Javaimport com.alibaba.dashscope.decision.DecisionModel;
import com.alibaba.dashscope.decision.DecisionModelParam;
import com.alibaba.dashscope.decision.DecisionModelResult;
import com.alibaba.dashscope.decision.DecisionQuestion;
import java.util.LinkedHashMap;
import java.util.Map;
public class DecisionDemo {
public static void main(String[] args) throws Exception {
Map<String, DecisionQuestion> questions = new LinkedHashMap<>();
questions.put("refund", DecisionQuestion.noul("Is the user asking for a refund?"));
DecisionModelParam param = DecisionModelParam.builder()
.model(DecisionModelParam.Models.DECISION_MODEL_PREVIEW)
.state("Is this comment asking for a refund?")
.questions(questions)
.build();
DecisionModel decisionModel = new DecisionModel("{WorkspaceId}", "ap-southeast-1");
DecisionModelResult result = decisionModel.call(param);
System.out.println(result.getAnswers().get("refund").getNoul()); // P(yes)
}
}
TypeSafe Pythonimport os
from typesafe_sdk import TypeSafeClient
client = TypeSafeClient(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode",
)
result = client.system_one(
model="decision-model-preview",
state="Is this comment asking for a refund?",
questions={"refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}},
)
print(result.answers["refund"]) # noul P(yes)
curlcurl -sS -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "decision-model-preview",
"state": "Is this comment asking for a refund?",
"questions": {
"refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}
}
}'
|