重构简历优化
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""简历段落润色 AI 引擎:仅做格式/错字/表达层面的优化"""
|
||||
|
||||
import json
|
||||
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
|
||||
from app.ai.model_config import ResumePolisherModel
|
||||
from app.ai.resume_polisher.prompts import POLISH_PROMPT
|
||||
from app.core.logger import log
|
||||
from app.tool.json_helper import parse_llm_json
|
||||
|
||||
# 润色链(StrOutputParser 拿原始文本,再手动解析 JSON,避免 markdown 代码块导致解析失败)
|
||||
_polish_chain = (
|
||||
ChatPromptTemplate.from_messages([("system", POLISH_PROMPT), ("human", "请开始润色。")])
|
||||
| ResumePolisherModel.POLISH
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
|
||||
async def polish_paragraphs(content: list[str]) -> list[str]:
|
||||
"""对段落数组做表达层面的润色,返回与输入等长的数组;失败兜底原样返回"""
|
||||
if not content:
|
||||
return []
|
||||
|
||||
inp = {"content": json.dumps(content, ensure_ascii=False)}
|
||||
try:
|
||||
raw = await _polish_chain.ainvoke(inp)
|
||||
result = parse_llm_json(raw)
|
||||
if isinstance(result, list) and len(result) == len(content):
|
||||
return [str(item) for item in result]
|
||||
log.warning(f"AI润色返回结果不符合预期, 原样返回: {result}")
|
||||
return content
|
||||
except Exception as e:
|
||||
log.warning(f"AI润色失败: {e}")
|
||||
return content
|
||||
@@ -0,0 +1,21 @@
|
||||
"""简历段落润色 Prompt 模板"""
|
||||
|
||||
POLISH_PROMPT = """你是一位严谨的简历文字校对助手。请对用户提交的简历段落进行"表面润色",只做表达层面的优化。
|
||||
|
||||
## 优化范围(只允许做这些)
|
||||
- 修正错别字、标点、语法错误
|
||||
- 优化文本格式与排版(如多余空格、断句、全半角混用)
|
||||
- 让表达更通顺、专业,去除明显口语化和冗余措辞
|
||||
|
||||
## 严格禁止(绝对不能做)
|
||||
- 不得改变原意,不得增加或删除任何信息点
|
||||
- 不得编造、补充任何内容(尤其禁止凭空添加数字、量化成果、技能、成就)
|
||||
- 不得改变段落的数量和顺序
|
||||
|
||||
## 输入
|
||||
用户提交的段落数组(每个元素是一个段落):
|
||||
{content}
|
||||
|
||||
## 输出格式
|
||||
严格输出 JSON 数组,元素个数和顺序必须与输入完全一致,不要输出其他任何内容:
|
||||
["润色后的段落1", "润色后的段落2"]"""
|
||||
Reference in New Issue
Block a user