更新润写传入
This commit is contained in:
parent
a196c6d4ed
commit
aa4406036e
30
app.py
30
app.py
@ -220,6 +220,34 @@ def build_rewrite_prompt(request: RewriteRequest) -> str:
|
||||
if not beautify_type:
|
||||
raise HTTPException(status_code=400, detail=f"不支持的 rewrite_type: {request.rewrite_type}")
|
||||
|
||||
target_text = (request.sentence or request.content or "").strip()
|
||||
if not target_text:
|
||||
raise HTTPException(status_code=400, detail="缺少需要改写的内容")
|
||||
|
||||
# 润色区的四种能力都是编辑器选区级操作。这里不传入全文上下文,避免模型
|
||||
# 把 content 误判为改写对象,从而在只选择一句话时仍输出整篇公文。
|
||||
selection_style_instructions = {
|
||||
"金句润色": "在保持原意的基础上提炼语言,使表达精练、有力、有文采",
|
||||
"书面化": "改写为严谨、规范、庄重的公文书面表达",
|
||||
"讲稿化": "改写为适合正式场合表达、自然连贯的讲稿语言",
|
||||
"规整": "改写为格式规范、内容严谨、语言得体的公文表达",
|
||||
}
|
||||
if beautify_type in selection_style_instructions:
|
||||
style_instruction = selection_style_instructions[beautify_type]
|
||||
return f"""你是专业的公文局部改写助手。
|
||||
下面“待改写内容”是本次唯一允许处理和输出的内容。
|
||||
请{style_instruction},保持原意和事实信息,不增加新的时间、地点、人物、数据或事项。
|
||||
不得扩写为完整公文、完整讲稿或完整段落,不得补充标题、称谓、开场白、结尾或上下文。
|
||||
输出长度应与待改写内容大致相当。
|
||||
禁止使用Markdown,禁止解释修改过程,禁止复述未被选中的任何内容。
|
||||
只输出改写结果。
|
||||
|
||||
其他要求:{request.require or "无"}
|
||||
待改写内容:
|
||||
<selection>
|
||||
{target_text}
|
||||
</selection>"""
|
||||
|
||||
prompt_template = BEAUTIFY_TYPE_DICT.get(beautify_type)
|
||||
if not prompt_template:
|
||||
raise HTTPException(status_code=400, detail=f"未找到提示词模板: {beautify_type}")
|
||||
@ -227,7 +255,7 @@ def build_rewrite_prompt(request: RewriteRequest) -> str:
|
||||
return prompt_template.format(
|
||||
require=request.require or "",
|
||||
content=request.content or "",
|
||||
sentence=request.sentence or request.content or "",
|
||||
sentence=target_text,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user