optimize: refine LLM prompts for conciseness and reduce verbosity; reduce max_tokens to 1000
This commit is contained in:
@@ -76,34 +76,34 @@ def expand_content_with_llm(
|
|||||||
context: str = ""
|
context: str = ""
|
||||||
) -> str:
|
) -> str:
|
||||||
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
||||||
prompt = f"""你是一个专业的内容创作者。请将以下大纲扩展为完整的文章章节。
|
prompt = f"""你是一个专业的内容创作者,风格精炼、直接、切中要点。请将以下大纲扩展为完整的文章章节,要求如下:
|
||||||
|
|
||||||
# 选题信息
|
### 选题信息
|
||||||
- 标题:{topic.get('title')}
|
标题:{topic.get('title')}
|
||||||
- 领域:{topic.get('field')}
|
领域:{topic.get('field')}
|
||||||
- 核心观点:{topic.get('core_concept', '')}
|
核心观点:{topic.get('core_concept', '')}
|
||||||
- 受众痛点:{topic.get('audience_pain', '')}
|
受众痛点:{topic.get('audience_pain', '')}
|
||||||
- 独特视角:{topic.get('unique_angle', '')}
|
独特视角:{topic.get('unique_angle', '')}
|
||||||
|
|
||||||
# 当前章节
|
### 当前章节
|
||||||
## {section_title}
|
## {section_title}
|
||||||
{section_content}
|
{section_content}
|
||||||
|
|
||||||
# 要求
|
### 输出要求
|
||||||
- 以 `## {section_title}` 作为章节标题开头
|
- 以 "## {section_title}" 开始
|
||||||
- 字数:300-500 字
|
- 字数:200-300 字(精炼为主)
|
||||||
- 风格:客观、专业、易懂
|
- 语言:直白、有冲击力,避免空洞套话
|
||||||
- 使用 Markdown 格式
|
- 使用 Markdown 格式
|
||||||
- 包含具体数据或案例(如果有)
|
- 每个论点配具体案例或数据支撑
|
||||||
- 保持与整体文章调性一致
|
- 确保与整体文章调性一致
|
||||||
|
|
||||||
直接输出完整的 Markdown 章节(包括 ## 标题和正文段落)。"""
|
直接输出完整 Markdown 章节(包括标题和正文)。"""
|
||||||
|
|
||||||
if context:
|
if context:
|
||||||
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = call_llm(prompt, temperature=0.8, max_tokens=2000)
|
result = call_llm(prompt, temperature=0.8, max_tokens=1000)
|
||||||
return result.strip()
|
return result.strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"## {section_title}\n\n(LLM 调用失败:{e},请手动补充)"
|
return f"## {section_title}\n\n(LLM 调用失败:{e},请手动补充)"
|
||||||
|
|||||||
@@ -102,28 +102,28 @@ def call_llm(
|
|||||||
|
|
||||||
def expand_content_with_llm(topic: dict, section_title: str, section_content: str, context: str = "") -> str:
|
def expand_content_with_llm(topic: dict, section_title: str, section_content: str, context: str = "") -> str:
|
||||||
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
||||||
prompt = f"""你是一个专业的内容创作者。请将以下大纲扩展为完整的文章章节。
|
prompt = f"""你是一个专业的内容创作者,风格精炼、直接、切中要点。请将以下大纲扩展为完整的文章章节,要求如下:
|
||||||
|
|
||||||
# 选题信息
|
### 选题信息
|
||||||
- 标题:{topic.get('title')}
|
标题:{topic.get('title')}
|
||||||
- 领域:{topic.get('field')}
|
领域:{topic.get('field')}
|
||||||
- 核心观点:{topic.get('core_concept', '')}
|
核心观点:{topic.get('core_concept', '')}
|
||||||
- 受众痛点:{topic.get('audience_pain', '')}
|
受众痛点:{topic.get('audience_pain', '')}
|
||||||
- 独特视角:{topic.get('unique_angle', '')}
|
独特视角:{topic.get('unique_angle', '')}
|
||||||
|
|
||||||
# 当前章节
|
### 当前章节
|
||||||
## {section_title}
|
## {section_title}
|
||||||
{section_content}
|
{section_content}
|
||||||
|
|
||||||
# 要求
|
### 输出要求
|
||||||
- 以 `## {section_title}` 作为章节标题开头
|
- 以 "## {section_title}" 开始
|
||||||
- 字数:300-500字
|
- 字数:200-300 字(精炼为主)
|
||||||
- 风格:客观、专业、易懂
|
- 语言:直白、有冲击力,避免空洞套话
|
||||||
- 使用 Markdown 格式
|
- 使用 Markdown 格式
|
||||||
- 包含具体数据或案例(如果有)
|
- 每个论点配具体案例或数据支撑
|
||||||
- 保持与整体文章调性一致
|
- 确保与整体文章调性一致
|
||||||
|
|
||||||
直接输出完整的 Markdown 章节(包括 ## 标题和正文段落)。"""
|
直接输出完整 Markdown 章节(包括标题和正文)。"""
|
||||||
if context:
|
if context:
|
||||||
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ def expand_content_with_llm(topic: dict, section_title: str, section_content: st
|
|||||||
prompt,
|
prompt,
|
||||||
model="google/gemma-3n-e4b-it",
|
model="google/gemma-3n-e4b-it",
|
||||||
temperature=0.20,
|
temperature=0.20,
|
||||||
max_tokens=2000,
|
max_tokens=1000,
|
||||||
top_p=0.70,
|
top_p=0.70,
|
||||||
frequency_penalty=0.00,
|
frequency_penalty=0.00,
|
||||||
presence_penalty=0.00
|
presence_penalty=0.00
|
||||||
|
|||||||
@@ -71,34 +71,33 @@ def call_llm(
|
|||||||
|
|
||||||
def expand_content_with_llm(topic: dict, section_title: str, section_content: str, context: str = "") -> str:
|
def expand_content_with_llm(topic: dict, section_title: str, section_content: str, context: str = "") -> str:
|
||||||
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
"""扩写大纲章节,返回包含 ## 标题的完整 Markdown"""
|
||||||
prompt = f"""你是一个专业的内容创作者。请将以下大纲扩展为完整的文章章节。
|
prompt = f"""你是一个专业的内容创作者,风格精炼、直接、切中要点。请将以下大纲扩展为完整的文章章节,要求如下:
|
||||||
|
|
||||||
# 选题信息
|
### 选题信息
|
||||||
- 标题:{topic.get('title')}
|
标题:{topic.get('title')}
|
||||||
- 领域:{topic.get('field')}
|
领域:{topic.get('field')}
|
||||||
- 核心观点:{topic.get('core_concept', '')}
|
核心观点:{topic.get('core_concept', '')}
|
||||||
- 受众痛点:{topic.get('audience_pain', '')}
|
受众痛点:{topic.get('audience_pain', '')}
|
||||||
- 独特视角:{topic.get('unique_angle', '')}
|
独特视角:{topic.get('unique_angle', '')}
|
||||||
|
|
||||||
# 当前章节
|
### 当前章节
|
||||||
## {section_title}
|
## {section_title}
|
||||||
{section_content}
|
{section_content}
|
||||||
|
|
||||||
# 要求
|
### 输出要求
|
||||||
- 以 `## {section_title}` 作为章节标题开头
|
- 以 "## {section_title}" 开始
|
||||||
- 字数:300-500字
|
- 字数:200-300 字(精炼为主)
|
||||||
- 风格:客观、专业、易懂
|
- 语言:直白、有冲击力,避免空洞套话
|
||||||
- 使用 Markdown 格式
|
- 使用 Markdown 格式
|
||||||
- 包含具体数据或案例(如果有)
|
- 每个论点配具体案例或数据支撑
|
||||||
- 保持与整体文章调性一致
|
- 确保与整体文章调性一致
|
||||||
- 所有数据和时间必须基于2025年及以后,避免引用2024年以前的具体事件或统计数据。如果信息不足,请使用'近期'、'最新'等模糊表述,不要编造旧数据。
|
|
||||||
|
|
||||||
直接输出完整的 Markdown 章节(包括 ## 标题和正文段落)。"""
|
直接输出完整 Markdown 章节(包括标题和正文)。"""
|
||||||
if context:
|
if context:
|
||||||
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
prompt = f"# 参考资料\n{context}\n\n{prompt}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = call_llm(prompt, temperature=0.8, max_tokens=2000)
|
result = call_llm(prompt, temperature=0.8, max_tokens=1000)
|
||||||
return result.strip()
|
return result.strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"## {section_title}\n\n(LLM 调用失败:{e},请手动补充)"
|
return f"## {section_title}\n\n(LLM 调用失败:{e},请手动补充)"
|
||||||
|
|||||||
Reference in New Issue
Block a user