diff --git a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java index 13e376c..53958bb 100644 --- a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java +++ b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java @@ -156,10 +156,24 @@ public class SswLLMClient { usage.getInteger("output_tokens"), maxTokens); } } else { - content = respJson.getJSONArray("choices") - .getJSONObject(0) - .getJSONObject("message") - .getString("content"); + // v0.20+ P0 修复: OpenAI 响应 schema 完整 null-check, 防 fastjson NPE + // 背景: LLM 限流/超时/错误响应可能只有 {"error":...} 而无 choices, 链式调用炸 + JSONArray choicesArr = respJson.getJSONArray("choices"); + if (choicesArr == null || choicesArr.isEmpty()) { + throw new RuntimeException("OpenAI 响应无 choices: " + respJson.toJSONString()); + } + JSONObject choice0 = choicesArr.getJSONObject(0); + if (choice0 == null) { + throw new RuntimeException("OpenAI choices[0] 为空: " + respJson.toJSONString()); + } + JSONObject message = choice0.getJSONObject("message"); + if (message == null) { + throw new RuntimeException("OpenAI choices[0].message 为空: " + respJson.toJSONString()); + } + content = message.getString("content"); + if (content == null) { + throw new RuntimeException("OpenAI choices[0].message.content 为空: " + respJson.toJSONString()); + } JSONObject usage = respJson.getJSONObject("usage"); if (usage != null) { log.info("[SswLLMClient] usage: prompt={} completion={}/{}",