This commit is contained in:
2026-06-09 16:19:15 +08:00
parent 4151e4963b
commit fdbde938f9
7 changed files with 134 additions and 56 deletions
@@ -272,13 +272,13 @@ class CalculationService:
if quality_checks:
detailed_cavity_json["quality_checks"] = quality_checks
undercut_regions = quality_checks.get("undercut_regions")
if undercut_regions:
detailed_cavity_json["undercut_regions"] = undercut_regions
undercut_summary = quality_checks.get("undercut_summary")
if undercut_summary:
detailed_cavity_json["undercut_regions"] = [] # 详情在 scheme 级别
side_actions = quality_checks.get("side_actions")
if side_actions:
detailed_cavity_json["side_actions"] = side_actions
side_action_summary = quality_checks.get("side_action_summary")
if side_action_summary:
detailed_cavity_json["side_actions"] = {"summary": side_action_summary}
# 添加型腔关键信息
detailed_cavity_json["mold_cavities"]["cavity_key_info"] = {
+27 -7
View File
@@ -336,7 +336,7 @@ class LLMService:
volume=f"{analysis_result.get('geometry_data', {}).get('volume', 0):.1f} mm³",
surface_area=f"{analysis_result.get('geometry_data', {}).get('surface_area', 0):.1f} mm²",
bbox=json.dumps(analysis_result.get("geometry_data", {}).get("bounding_box", {}), ensure_ascii=False),
features=features or "无特征检测数据",
features=trimmed or "无特征检测数据",
quality_metrics=json.dumps(analysis_result.get("quality_metrics", {}), ensure_ascii=False, indent=2),
schemes=schemes_text or "无分模方案数据",
mold_material=mfg.get("mold_material", "自动选择"),
@@ -350,13 +350,12 @@ class LLMService:
)
def _build_side_action_prompt(self, analysis_result, detailed_cavity_json) -> str:
features = json.dumps(
analysis_result.get("detected_features", []),
ensure_ascii=False,
indent=2,
features = self._prioritize_features_for_side_action(
analysis_result.get("detected_features", [])
)
if len(features) > 2500:
features = features[:2500] + "\n... (已截断)"
trimmed = json.dumps(features, ensure_ascii=False, indent=2)
if len(trimmed) > 2500:
trimmed = trimmed[:2500] + "\n... (已截断)"
best_scheme = {}
if detailed_cavity_json:
@@ -449,6 +448,27 @@ class LLMService:
content = resp.json()["choices"][0]["message"]["content"]
return content.strip() if content else None
@staticmethod
def _prioritize_features_for_side_action(
features: List[Dict[str, Any]],
) -> List[Dict[str, Any]]:
"""按倒扣/抽芯相关性排序,优先保留关键特征,避免 prompt 截断丢失重要信息。
优先级:draft_angle > high_curvature > thin_wall/thick_wall/wall_non_uniform > 其它
"""
high_priority = {"draft_angle", "high_curvature"}
medium_priority = {"thin_wall", "thick_wall", "wall_non_uniform", "undercut"}
high, medium, rest = [], [], []
for f in features:
ft = f.get("feature_type", "")
if ft in high_priority:
high.append(f)
elif ft in medium_priority:
medium.append(f)
else:
rest.append(f)
return high + medium + rest
@staticmethod
def _parse_json_response(raw):
try:
@@ -47,7 +47,8 @@ class ProcessingService:
self.multi_scheme_planner = MultiSchemeMoldPlanner()
self.cad_exporter = CADExporter()
self._export_shapes_cache: Dict[str, Dict[str, Dict[str, Any]]] = {}
self._occ_executor = ThreadPoolExecutor(max_workers=2, thread_name_prefix="occ")
# OCC 非线程安全,max_workers=1 保证所有 OCC 操作序列化执行,避免偶发崩溃
self._occ_executor = ThreadPoolExecutor(max_workers=1, thread_name_prefix="occ")
# ─── 对外入口 ───