重构简历优化

This commit is contained in:
zk
2026-06-23 18:21:30 +08:00
parent 1edc28e332
commit 2f38c80207
11 changed files with 99 additions and 113 deletions
+1 -40
View File
@@ -7,7 +7,7 @@ from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from app.ai.model_config import DiagnoserModel
from app.ai.resume_diagnoser.prompts import DIAGNOSE_MODULE_PROMPT, SUMMARY_PROMPT, POLISH_PROMPT
from app.ai.resume_diagnoser.prompts import DIAGNOSE_MODULE_PROMPT, SUMMARY_PROMPT
from app.core.logger import log
from app.tool.json_helper import parse_llm_json
@@ -54,45 +54,6 @@ async def generate_summary(grade: str, urgent_total: int, important_total: int,
return "简历诊断已完成,请查看各模块的详细诊断结果。"
_polish_chain = (
ChatPromptTemplate.from_messages([("system", POLISH_PROMPT), ("human", "请开始优化。")])
| DiagnoserModel.POLISH
| StrOutputParser()
)
async def polish_content(module_type: str, reference_content: list[dict] | str | None,
user_content: list[str], is_summary: bool) -> list[str]:
"""润色用户编辑后的文本"""
ref_text = ""
if reference_content:
if isinstance(reference_content, list):
ref_text = "\n".join(
item.get("text", "") if isinstance(item, dict) else str(item)
for item in reference_content
)
else:
ref_text = str(reference_content)
if not ref_text:
ref_text = ""
inp = {
"module_type": module_type,
"reference_content": ref_text,
"user_content": "\n".join(user_content),
"summary_constraint": "- 注意:此模块只能输出一个段落,数组只能有一个元素" if is_summary else "",
}
try:
raw = await _polish_chain.ainvoke(inp)
result = parse_llm_json(raw)
if isinstance(result, list):
return [str(item) for item in result]
return [str(result)]
except Exception as e:
log.warning(f"AI润色失败: {e}")
return user_content
async def _safe_invoke(task: dict) -> dict:
"""单条记录诊断,失败返回空结果"""
module_type = task.get("module_type", "unknown")