| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- """测试修复后的预览API"""
- import requests
- import json
- API_BASE = "http://localhost:8000/api"
- # 获取x11 wash common模板
- response = requests.get(f"{API_BASE}/templates")
- templates = response.json()
- tpl = None
- for t in templates:
- if t['machine_model'] == 'x11' and t['template_type'] == 'common' and t['device_type'] == 'wash':
- tpl = t
- break
- if not tpl:
- print("❌ 未找到模板")
- exit(1)
- print(f"✅ 模板: {tpl['machine_model']}/{tpl['template_type']}")
- print(f" Body长度: {len(tpl['template_body'])}")
- print()
- # 测试1: 默认参数预览
- print("=" * 60)
- print("📝 测试1: 默认参数(rerank_reason=PIN_CONSECUTIVE)")
- print("=" * 60)
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": tpl['template_body'],
- "parameters": {"rerank_reason": "PIN_CONSECUTIVE", "program_id": "1"}
- })
- result = resp.json()
- print(f"Success: {result['success']}")
- print(f"Condition vars: {[v['name'] for v in result.get('condition_vars', [])]}")
- print(f"Data vars: {[v['name'] for v in result.get('data_vars', [])]}")
- print(f"Result:\n{result['result'][:300]}...")
- print()
- # 测试2: POPULAR分支
- print("=" * 60)
- print("📝 测试2: POPULAR分支")
- print("=" * 60)
- resp = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": tpl['template_body'],
- "parameters": {"rerank_reason": "", "recommend_type": "POPULAR", "program_id": "15"}
- })
- result = resp.json()
- print(f"Success: {result['success']}")
- if result['success']:
- print(f"Result:\n{result['result'][:300]}...")
- else:
- print(f"Error: {result['error']}")
- print()
- # 测试3: 重新生成(应该随机不同)
- print("=" * 60)
- print("📝 测试3: 两次重新生成(检查随机性)")
- print("=" * 60)
- resp1 = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": tpl['template_body'],
- "parameters": {"rerank_reason": "PIN_CONSECUTIVE", "program_id": "1"}
- })
- resp2 = requests.post(f"{API_BASE}/templates/preview", json={
- "template_body": tpl['template_body'],
- "parameters": {"rerank_reason": "PIN_CONSECUTIVE", "program_id": "1"}
- })
- r1 = resp1.json()
- r2 = resp2.json()
- print(f"第一次: {r1['result'][:100]}...")
- print(f"第二次: {r2['result'][:100]}...")
- print(f"是否不同: {r1['result'] != r2['result']}")
|