feat: 步骤5填充字段改用智能体执行
- 新增步骤5任务模板(config/agent_fill_fields_template.txt) - 步骤5调用智能体hz4th_editor执行: 1. 获取API文档了解对应类别字段定义 2. 从内容库获取相关内容数据 3. 整理产品参数 4. 通过API提交到ParamHub审核系统 - /process页面新增步骤5模板编辑面板 - 步骤6改为确认提交结果(备用本地提交) - 新增API: GET/POST /api/process/fill-fields-template
This commit is contained in:
@@ -258,3 +258,83 @@ def preview_agent_template():
|
||||
except Exception as e:
|
||||
logger.error(f"预览模板失败: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
# ===== 步骤5填充字段模板 API =====
|
||||
|
||||
FILL_FIELDS_TEMPLATE_FILE = os.path.join(TEMPLATE_DIR, 'agent_fill_fields_template.txt')
|
||||
|
||||
|
||||
@bp.route('/fill-fields-template', methods=['GET'])
|
||||
def get_fill_fields_template():
|
||||
"""获取步骤5填充字段任务文本模板"""
|
||||
try:
|
||||
if os.path.exists(FILL_FIELDS_TEMPLATE_FILE):
|
||||
with open(FILL_FIELDS_TEMPLATE_FILE, 'r', encoding='utf-8') as f:
|
||||
template = f.read()
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'template': template
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': '模板文件不存在'
|
||||
}), 404
|
||||
except Exception as e:
|
||||
logger.error(f"获取填充字段模板失败: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@bp.route('/fill-fields-template', methods=['POST'])
|
||||
def save_fill_fields_template():
|
||||
"""保存步骤5填充字段任务文本模板"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
template = data.get('template', '')
|
||||
|
||||
if not template:
|
||||
return jsonify({'success': False, 'error': '模板内容不能为空'}), 400
|
||||
|
||||
os.makedirs(TEMPLATE_DIR, exist_ok=True)
|
||||
with open(FILL_FIELDS_TEMPLATE_FILE, 'w', encoding='utf-8') as f:
|
||||
f.write(template)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': '模板已保存'
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"保存填充字段模板失败: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@bp.route('/fill-fields-template/preview', methods=['POST'])
|
||||
def preview_fill_fields_template():
|
||||
"""预览填充后的步骤5任务文本"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
product_name = data.get('product_name', '示例产品')
|
||||
category = data.get('category', '示例类别')
|
||||
subcategory = data.get('subcategory', '示例子类别')
|
||||
|
||||
# 读取模板
|
||||
if os.path.exists(FILL_FIELDS_TEMPLATE_FILE):
|
||||
with open(FILL_FIELDS_TEMPLATE_FILE, 'r', encoding='utf-8') as f:
|
||||
template = f.read()
|
||||
else:
|
||||
return jsonify({'success': False, 'error': '模板文件不存在'}), 404
|
||||
|
||||
# 填充示例数据
|
||||
filled = template.replace('{{product_name}}', product_name)
|
||||
filled = filled.replace('{{category}}', category)
|
||||
filled = filled.replace('{{subcategory}}', subcategory or '无')
|
||||
filled = filled.replace('{{relevant_content_ids}}', 'ID 101: 示例相关文章A\nID 102: 示例相关文章B\nID 103: 示例相关文章C')
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'preview': filled
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"预览填充字段模板失败: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
Reference in New Issue
Block a user