| 13 | |
| 14 | public class DecisionModelUsage { |
| 15 | public static void main(String[] args) throws Exception { |
| 16 | Map<String, Object> state = new HashMap<>(); |
| 17 | state.put("ticket_id", "T-1001"); |
| 18 | state.put("content", "订单支付后超过 24 小时仍未到账,用户无法继续使用核心服务,要求立即处理。"); |
| 19 | |
| 20 | Map<String, String> options = new LinkedHashMap<>(); |
| 21 | options.put("billing", "支付、退款和账单问题"); |
| 22 | options.put("technical", "产品故障和集成问题"); |
| 23 | |
| 24 | List<String> levels = |
| 25 | Arrays.asList( |
| 26 | "轻微问题,不影响功能", |
| 27 | "部分功能受影响,但存在替代方案", |
| 28 | "核心功能不可用,没有替代方案", |
| 29 | "造成严重业务或安全影响"); |
| 30 | |
| 31 | Map<String, DecisionQuestion> questions = new LinkedHashMap<>(); |
| 32 | questions.put("department", DecisionQuestion.choice("应该由哪个团队处理?", options)); |
| 33 | questions.put("escalate", DecisionQuestion.noul("是否需要立即通知值班人员?")); |
| 34 | questions.put("severity", DecisionQuestion.score("这个问题有多严重?", levels)); |
| 35 | |
| 36 | DecisionModelParam param = |
| 37 | DecisionModelParam.builder() |
| 38 | .model(DecisionModelParam.Models.DECISION_MODEL_PREVIEW) |
| 39 | .state(state) |
| 40 | .questions(questions) |
| 41 | .build(); |
| 42 | |
| 43 | // A workspace id is required: pass it here (new DecisionModel("your-workspace-id")) |
| 44 | // or set the DASHSCOPE_WORKSPACE environment variable before running. |
| 45 | // For a fully custom endpoint, use DecisionModel.withBaseUrl(baseUrl) instead. |
| 46 | DecisionModel decisionModel = new DecisionModel(); |
| 47 | DecisionModelResult result = decisionModel.call(param); |
| 48 | System.out.println(JsonUtils.toJson(result)); |
| 49 | } |
| 50 | } |