优化 岗位编辑agent 性能
This commit is contained in:
@@ -14,7 +14,7 @@ from langchain_core.prompts import ChatPromptTemplate
|
||||
from app.ai.models import LLM
|
||||
from app.ai.skill_gap_analyzer.prompts import (
|
||||
SKILL_GAP_PROMPT, SUMMARY_OPTIMIZE_PROMPT, EXPERIENCE_OPTIMIZE_PROMPT,
|
||||
AGENT_PLAN_PROMPT, AGENT_MODULE_EDIT_PROMPT, MODULE_SCHEMAS,
|
||||
AGENT_PLAN_PROMPT, AGENT_MODULE_EDIT_PROMPT, AGENT_MODULE_ADD_PROMPT, MODULE_SCHEMAS,
|
||||
)
|
||||
from app.core.logger import log
|
||||
|
||||
@@ -100,11 +100,13 @@ _plan_chain = (
|
||||
)
|
||||
|
||||
|
||||
async def plan_edit(job_title: str, resume_json: str, chat_history: str, instruction: str) -> dict | None:
|
||||
"""Agent 规划:分析用户指令,返回修改计划或对话回复"""
|
||||
async def plan_edit(job_title: str, job_description: str, resume_json: str,
|
||||
chat_history: str, instruction: str) -> dict | None:
|
||||
"""Agent 规划:分析用户指令,返回原子操作列表或对话回复"""
|
||||
try:
|
||||
raw = await _plan_chain.ainvoke({
|
||||
"job_title": job_title, "resume_json": resume_json,
|
||||
"job_title": job_title, "job_description": job_description,
|
||||
"resume_json": resume_json,
|
||||
"chat_history": chat_history, "instruction": instruction,
|
||||
})
|
||||
result = _parse_json(raw)
|
||||
@@ -114,24 +116,51 @@ async def plan_edit(job_title: str, resume_json: str, chat_history: str, instruc
|
||||
return None
|
||||
|
||||
|
||||
# ===== Agent - 模块修改 =====
|
||||
# ===== Agent - 单条记录修改 =====
|
||||
|
||||
_module_edit_chain = (
|
||||
_record_edit_chain = (
|
||||
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_EDIT_PROMPT), ("human", "请执行修改。")])
|
||||
| LLM.GPT_4O.create(temperature=0.3)
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
|
||||
async def execute_module_edit(job_title: str, module_instruction: str,
|
||||
module_schema: str, module_data: str) -> dict | list | None:
|
||||
"""Agent 模块修改:根据指令修改指定模块数据"""
|
||||
async def execute_record_edit(job_title: str, job_description: str, instruction: str,
|
||||
chat_history: str, module_schema: str,
|
||||
record_data: str) -> dict | list | None:
|
||||
"""修改单条记录:根据指令修改指定记录数据"""
|
||||
try:
|
||||
raw = await _module_edit_chain.ainvoke({
|
||||
"job_title": job_title, "module_instruction": module_instruction,
|
||||
"module_schema": module_schema, "module_data": module_data,
|
||||
raw = await _record_edit_chain.ainvoke({
|
||||
"job_title": job_title, "job_description": job_description,
|
||||
"instruction": instruction, "chat_history": chat_history,
|
||||
"module_schema": module_schema, "record_data": record_data,
|
||||
})
|
||||
return _parse_json(raw)
|
||||
except Exception as e:
|
||||
log.warning(f"AI模块修改失败: {e}")
|
||||
log.warning(f"AI单条记录修改失败: {e}")
|
||||
return None
|
||||
|
||||
|
||||
# ===== Agent - 新增记录 =====
|
||||
|
||||
_record_add_chain = (
|
||||
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_ADD_PROMPT), ("human", "请生成新记录。")])
|
||||
| LLM.GPT_4O.create(temperature=0.3)
|
||||
| StrOutputParser()
|
||||
)
|
||||
|
||||
|
||||
async def execute_record_add(job_title: str, job_description: str, instruction: str,
|
||||
chat_history: str, module_schema: str) -> dict | None:
|
||||
"""新增一条记录:根据指令生成新记录"""
|
||||
try:
|
||||
raw = await _record_add_chain.ainvoke({
|
||||
"job_title": job_title, "job_description": job_description,
|
||||
"instruction": instruction, "chat_history": chat_history,
|
||||
"module_schema": module_schema,
|
||||
})
|
||||
result = _parse_json(raw)
|
||||
return result if isinstance(result, dict) else None
|
||||
except Exception as e:
|
||||
log.warning(f"AI新增记录失败: {e}")
|
||||
return None
|
||||
|
||||
@@ -52,10 +52,11 @@ EXPERIENCE_OPTIMIZE_PROMPT = """你是一个简历优化助手。根据目标岗
|
||||
4. description 字段是 [{{"id": "xxx", "text": "xxx"}}] 格式:修改时保留原 id 只改 text,新增段落生成随机8位字符串作为 id,删除段落直接移除
|
||||
5. 返回修改后的完整模块数据(JSON 格式,与输入格式一致)"""
|
||||
|
||||
AGENT_PLAN_PROMPT = """你是一个简历编辑助手。分析用户的指令,决定需要修改简历的哪些模块。
|
||||
AGENT_PLAN_PROMPT = """你是一个简历编辑助手。分析用户的指令,将其拆解为原子操作。
|
||||
|
||||
【目标岗位】
|
||||
{job_title}
|
||||
{job_description}
|
||||
|
||||
【当前简历】
|
||||
{resume_json}
|
||||
@@ -66,43 +67,73 @@ AGENT_PLAN_PROMPT = """你是一个简历编辑助手。分析用户的指令,
|
||||
【用户指令】
|
||||
{instruction}
|
||||
|
||||
如果用户指令明确,返回修改计划 JSON:
|
||||
{{"action": "modify", "modules": [{{"module": "模块名", "instruction": "具体修改要求"}}], "updatedModulesLabel": "中文模块名列表"}}
|
||||
|
||||
如果用户指令不明确或需要澄清,返回对话 JSON:
|
||||
如果用户指令不明确或需要澄清,返回:
|
||||
{{"action": "chat", "message": "你的追问内容"}}
|
||||
|
||||
模块名可选:
|
||||
- resume:主表(个人信息,包含 name、email、mobileNumber、city、wechatNumber、portfolioUrl、skills、certificates、summary、avatarUrl)
|
||||
- education:教育经历
|
||||
- work:工作经历
|
||||
- internship:实习经历
|
||||
- project:项目经历
|
||||
- competition:竞赛经历
|
||||
只返回 JSON,不要其他内容。"""
|
||||
如果用户指令明确,将其拆解为原子操作列表,返回:
|
||||
{{"action": "modify", "operations": [...]}}
|
||||
|
||||
AGENT_MODULE_EDIT_PROMPT = """你是一个简历编辑助手。根据修改要求,修改简历的指定模块。
|
||||
操作类型:
|
||||
1. 删除记录:{{"type": "delete", "module": "模块名", "id": "记录id"}}
|
||||
2. 修改记录:{{"type": "update", "module": "模块名", "id": "记录id", "instruction": "修改说明(50字内)"}}
|
||||
3. 修改主表:{{"type": "update", "module": "resume", "instruction": "修改说明(50字内)"}}
|
||||
4. 新增记录:{{"type": "add", "module": "模块名", "instruction": "新增说明(50字内)"}}
|
||||
|
||||
模块名可选:resume(主表,包含 name、email、mobileNumber、city、wechatNumber、portfolioUrl、skills、certificates、summary、avatarUrl)、education(教育)、work(工作)、internship(实习)、project(项目)、competition(竞赛)
|
||||
|
||||
规则:
|
||||
1. 每条操作对应一个最小粒度的修改,一个用户指令可拆出多条操作
|
||||
2. delete 和 update(非resume)必须带 id,从当前简历中匹配
|
||||
3. instruction 不超过50字,简明扼要
|
||||
4. 只返回 JSON,不要其他内容"""
|
||||
|
||||
AGENT_MODULE_EDIT_PROMPT = """你是一个简历编辑助手。根据修改要求,修改简历中的一条记录。
|
||||
|
||||
【目标岗位】
|
||||
{job_title}
|
||||
{job_description}
|
||||
|
||||
【修改要求】
|
||||
{module_instruction}
|
||||
{instruction}
|
||||
|
||||
【最近对话】
|
||||
{chat_history}
|
||||
|
||||
【模块数据结构】
|
||||
{module_schema}
|
||||
|
||||
【当前模块数据】
|
||||
{module_data}
|
||||
【当前记录数据】
|
||||
{record_data}
|
||||
|
||||
规则:
|
||||
1. 严格按照修改要求操作,可以增删改
|
||||
2. 未要求修改的记录保持不变
|
||||
1. 严格按照修改要求操作
|
||||
2. 未要求修改的字段保持不变
|
||||
3. 不要编造用户简历中不存在的内容
|
||||
4. 保持原文格式和结构
|
||||
5. description 字段是 [{{"id": "xxx", "text": "xxx"}}] 格式:修改时保留原 id 只改 text,新增段落生成随机8位字符串作为 id,删除段落直接从数组中移除
|
||||
6. 新增记录时按照模块数据结构生成完整字段,id 使用随机8位字符串
|
||||
7. 返回修改后的完整模块数据(JSON 格式,与输入格式一致)"""
|
||||
5. description 字段是 [{{"id": "xxx", "text": "xxx"}}] 格式:修改时保留原 id 只改 text,新增段落生成随机8位字符串作为 id,删除段落直接移除
|
||||
6. 返回修改后的完整记录数据(JSON 格式,与输入格式一致)"""
|
||||
|
||||
AGENT_MODULE_ADD_PROMPT = """你是一个简历编辑助手。根据要求,生成一条新的简历记录。
|
||||
|
||||
【目标岗位】
|
||||
{job_title}
|
||||
{job_description}
|
||||
|
||||
【新增要求】
|
||||
{instruction}
|
||||
|
||||
【最近对话】
|
||||
{chat_history}
|
||||
|
||||
【模块数据结构】
|
||||
{module_schema}
|
||||
|
||||
规则:
|
||||
1. 按照模块数据结构生成完整字段
|
||||
2. id 使用随机8位字符串
|
||||
3. description 中每个段落的 id 也使用随机8位字符串
|
||||
4. 内容要合理真实,贴合目标岗位方向
|
||||
5. 返回一条完整记录的 JSON,与模块数据结构一致"""
|
||||
|
||||
# 各模块数据结构定义(传入 prompt 的 module_schema)
|
||||
MODULE_SCHEMAS: dict[str, str] = {
|
||||
|
||||
Reference in New Issue
Block a user