Files
2026-09-24 10:40:57 +08:00

55 lines
2.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""按用户要求:不手写代码建这个零件,直接调用生产管线(generate_from_description_best),
文字描述+参考图,跟真实用户在网页端的使用方式一致。"""
import base64
import sys
from pathlib import Path
from dotenv import load_dotenv
BASE_DIR = Path(__file__).resolve().parent.parent
load_dotenv(BASE_DIR / ".env")
sys.path.insert(0, str(BASE_DIR))
from engine.pipeline import PipelineError, generate_from_description_best # noqa: E402
TEXT = (
"一个钣金安装支架,整体是L形折弯件,厚度3mm。"
"主体是一块竖直的板,宽40mm,从底部折弯处往上量总高约165mm。"
"主体顶部是圆弧形收边(圆角半径R20),顶部均匀分布3个Ø4.2mm的安装孔。"
"主体上部(顶部往下约60mm范围内)中心有一个Ø32mm的大圆孔。"
"主体中段(大圆孔下方到约125mm高度之间)有若干镂空造型作为减重孔,"
"包括一个不规则的类似齿状/波浪边缘的镂空图案,和一个三角形/楔形的镂空孔,"
"具体镂空造型不必精确复刻,做出大致对应位置的减重孔即可。"
"主体下部靠近底部(约22mm高度范围)也有几个小孔。"
"主体底部宽度约50mm(比主体40mm主体宽度更宽,说明底部有一段展开的过渡),"
"然后垂直向下折弯90度,形成一个水平的底部安装法兰,法兰从折弯处向外延伸约31mm。"
"折弯处内侧有一个小台阶偏移,偏移量约7mm。"
"底部法兰不是左右对称的,法兰的外边缘是弧形的,法兰上分布若干安装孔。"
"整体是用于设备安装的支架,参考附图中的正视图、侧视图和仰视示意图,"
"按图中标注的尺寸(单位mm)生成。"
)
def main():
image_path = Path(
"/Users/jerry/.claude/image-cache/9c8a5f33-4130-4d51-ab37-38717e51fde6/62.png"
)
image_b64 = base64.b64encode(image_path.read_bytes()).decode() if image_path.exists() else None
print(f"[信息] 参考图: {'已附带' if image_b64 else '未找到,纯文字生成'}")
try:
report = generate_from_description_best(TEXT, BASE_DIR, image_base64=image_b64)
except PipelineError as e:
print(f"[失败] {e}")
sys.exit(1)
print(f"\n[完成] 零件名: {report.get('part_name')}")
print(f"[完成] agentic: {report.get('agentic', False)} degraded_fallback: {report.get('degraded_fallback', False)} is_fallback_placeholder: {report.get('is_fallback_placeholder', False)}")
print(f"[完成] 体积: {report.get('volume_mm3', 0):.2f} mm^3")
print(f"[完成] 报告: {BASE_DIR / 'output' / report['part_name'] / 'report.json'}")
if __name__ == "__main__":
main()