|
|
@@ -58,6 +58,11 @@ public class MedicalRecordQc123Service {
|
|
|
@Value("${knowledge.kid}")
|
|
|
private String knowledgeKid;
|
|
|
|
|
|
+ @Value("${llm.model}")
|
|
|
+ private String llmModel;
|
|
|
+
|
|
|
+ @Value("${llm.max-tokens}")
|
|
|
+ private Integer llmMaxTokens;
|
|
|
|
|
|
private static final String RULE_MATCHING_URL = "http://localhost:6039/rag/schemaNoReRetrieval";
|
|
|
// private static final String LLM_MODEL_URL = "http://60.164.133.40:19997/v1/chat/completions";
|
|
|
@@ -373,6 +378,11 @@ public class MedicalRecordQc123Service {
|
|
|
rule.getRuleCode(), type, batchSize, ruleFailures.size());
|
|
|
} catch (Exception e) {
|
|
|
log.error("❌ 规则 [{}] type={} 分批质控失败: {}", rule.getRuleCode(), type, e.getMessage());
|
|
|
+ // ✅ 如果是模型崩溃异常,立即终止整个病历的质控
|
|
|
+ if (e.getMessage() != null && (e.getMessage().contains("模型服务崩溃")
|
|
|
+ || e.getMessage().contains("模型返回非JSON格式,可能服务异常"))) {
|
|
|
+ throw e; // 重新抛出异常,终止质控
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -434,6 +444,11 @@ public class MedicalRecordQc123Service {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("❌ 规则 [{}] type={} 质控失败: {}", rule.getRuleCode(), type, e.getMessage());
|
|
|
+ // ✅ 如果是模型崩溃异常,立即终止整个病历的质控
|
|
|
+ if (e.getMessage() != null && (e.getMessage().contains("模型服务崩溃")
|
|
|
+ || e.getMessage().contains("模型返回非JSON格式,可能服务异常"))) {
|
|
|
+ throw e; // 重新抛出异常,终止质控
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -479,6 +494,11 @@ public class MedicalRecordQc123Service {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("❌ 规则 [{}] specific 质控失败: {}", rule.getRuleCode(), e.getMessage());
|
|
|
+ // ✅ 如果是模型崩溃异常,立即终止整个病历的质控
|
|
|
+ if (e.getMessage() != null && (e.getMessage().contains("模型服务崩溃")
|
|
|
+ || e.getMessage().contains("模型返回非JSON格式,可能服务异常"))) {
|
|
|
+ throw e; // 重新抛出异常,终止质控
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -981,6 +1001,11 @@ public class MedicalRecordQc123Service {
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
log.error("❌ 规则 [{}] type={} 分批质控失败", rule.getRuleCode(), qcType, ex);
|
|
|
+ // ✅ 如果是模型崩溃异常,立即重新抛出
|
|
|
+ if (ex.getMessage() != null && (ex.getMessage().contains("模型服务崩溃")
|
|
|
+ || ex.getMessage().contains("模型返回非JSON格式,可能服务异常"))) {
|
|
|
+ throw ex; // 重新抛出异常,终止质控
|
|
|
+ }
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
@@ -1223,25 +1248,13 @@ public class MedicalRecordQc123Service {
|
|
|
|
|
|
String jsonBody = JSON.toJSONString(
|
|
|
new HashMap<String, Object>() {{
|
|
|
- put("model", "qwen3-32B");
|
|
|
+ put("model", llmModel); // 从配置文件读取模型名称
|
|
|
put("stream", false);
|
|
|
put("temperature", 0.0);
|
|
|
put("messages", messages);
|
|
|
- put("max_tokens", 10240); // ✅ 限制最大输出token数
|
|
|
- put("chat_template_kwargs", "{\"enable_thinking\": false}");
|
|
|
-// new HashMap<String, Object>() {{
|
|
|
-// put("model", "deepseek-r1-70B"); // ✅ 改成 R1-70B
|
|
|
-// put("stream", false);
|
|
|
-// put("temperature", 0.0);
|
|
|
-// put("max_tokens", 8192);
|
|
|
-// put("messages", messages);
|
|
|
-// put("chat_template_kwargs", "{\"enable_thinking\": false}");
|
|
|
-//
|
|
|
-// // ✅ 禁用思考输出
|
|
|
-//// put("reasoning_mode", "disabled");
|
|
|
+ put("max_tokens", llmMaxTokens); // 从配置文件读取最大token数
|
|
|
+ put("chat_template_kwargs", "{\"enable_thinking\": false}"); // 默认不开启思考过程
|
|
|
}}
|
|
|
-
|
|
|
-
|
|
|
);
|
|
|
String modelUrl = getLlmModelUrl();
|
|
|
System.out.println("模型路径:"+ modelUrl);
|
|
|
@@ -1252,6 +1265,16 @@ public class MedicalRecordQc123Service {
|
|
|
throw new RuntimeException("调用大模型失败:返回为空");
|
|
|
}
|
|
|
|
|
|
+ // ✅ 检测模型崩溃的异常响应(包含 address、pid 等关键字)
|
|
|
+ if (response.contains("address=") && response.contains("pid=")) {
|
|
|
+ throw new RuntimeException("⚠️ 模型服务崩溃,响应异常: " + response);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 检测其他异常响应格式
|
|
|
+ if (!response.trim().startsWith("{") && !response.trim().startsWith("[")) {
|
|
|
+ throw new RuntimeException("⚠️ 模型返回非JSON格式,可能服务异常: " + response);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
JSONObject res = JSON.parseObject(response);
|
|
|
JSONArray choices = res.getJSONArray("choices");
|