nodebookls/style_templates.py

128 lines
4.6 KiB
Python
Raw Permalink Normal View History

2025-10-29 13:56:24 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
风格模板管理模块
提供多种文案风格模板支持动态参数填充
"""
class StyleTemplateManager:
def __init__(self):
# 定义预设的风格模板
self.templates = {
"通用文案": {
"description": "适用于大多数场景的通用文案风格",
"template": """你是专业文案助手,基于以下资料生成文案。
资料{context}
要求
- 风格通用正式文案
- 字数{min_length}~{max_length}
- 严格基于资料不编造信息资料不足时明确提示"信息不足"
- 使用清晰准确的语言表达
- 保持逻辑连贯结构清晰""",
"temperature": 0.3
},
"小红书种草风": {
"description": "适合小红书平台的种草文案风格",
"template": """你是小红书种草文案专家,基于以下资料生成吸引人的种草文案。
资料{context}
要求
- 风格小红书种草风活泼亲切有感染力
- 字数{min_length}~{max_length}
- 严格基于资料不编造信息资料不足时明确提示"信息不足"
- 使用emoji表情符号增加趣味性
- 加入个人体验感受词汇"我觉得""个人认为"
- 可以使用感叹号增加情绪表达""",
"temperature": 0.5
},
"官方通告": {
"description": "适合官方发布的正式通告风格",
"template": """你是官方通告撰写专家,基于以下资料生成正式的官方通告。
资料{context}
要求
- 风格官方正式通告严谨权威规范
- 字数{min_length}~{max_length}
- 严格基于资料不编造信息资料不足时明确提示"信息不足"
- 使用正式规范的语言表达
- 保持结构清晰条理分明
- 避免口语化表达""",
"temperature": 0.2
},
"知乎科普": {
"description": "适合知乎平台的科普文案风格",
"template": """你是知乎科普文章作者,基于以下资料生成专业的科普内容。
资料{context}
要求
- 风格知乎科普风专业深入有见解
- 字数{min_length}~{max_length}
- 严格基于资料不编造信息资料不足时明确提示"信息不足"
- 使用专业但易懂的语言表达
- 可以加入分析和解读内容
- 保持逻辑严谨论据充分""",
"temperature": 0.3
},
"微博热点": {
"description": "适合微博平台的热点话题文案风格",
"template": """你是微博热点文案专家,基于以下资料生成吸引关注的微博文案。
资料{context}
要求
- 风格微博热点风简洁有力有话题性
- 字数{min_length}~{max_length}
- 严格基于资料不编造信息资料不足时明确提示"信息不足"
- 使用简洁明了的语言表达
- 可以使用网络流行语和热点词汇
- 加入话题标签# #增加曝光
- 保持内容的时效性和话题性""",
"temperature": 0.4
}
}
def get_template(self, style_name: str) -> dict:
"""
获取指定风格的模板
Args:
style_name: 风格名称
Returns:
模板字典包含descriptiontemplate和temperature
"""
return self.templates.get(style_name, self.templates["通用文案"])
def get_all_templates(self) -> dict:
"""
获取所有可用的风格模板
Returns:
所有模板的字典
"""
return self.templates
def add_template(self, name: str, description: str, template: str, temperature: float = 0.3):
"""
添加新的风格模板
Args:
name: 模板名称
description: 模板描述
template: 模板内容
temperature: 温度参数
"""
self.templates[name] = {
"description": description,
"template": template,
"temperature": temperature
}
def remove_template(self, name: str):
"""
删除指定的风格模板
Args:
name: 要删除的模板名称
"""
if name in self.templates and name not in ["通用文案", "小红书种草风", "官方通告", "知乎科普", "微博热点"]:
del self.templates[name]
# 创建全局实例
style_manager = StyleTemplateManager()