补充日志

This commit is contained in:
zk
2026-05-13 15:41:56 +08:00
parent ed8663cc42
commit d47f9e214a
2 changed files with 16 additions and 3 deletions
+3 -3
View File
@@ -94,7 +94,7 @@ async def optimize_module(job_title: str, job_description: str, module_data: str
_plan_chain = ( _plan_chain = (
ChatPromptTemplate.from_messages([("system", AGENT_PLAN_PROMPT), ("human", "请分析用户指令。")]) ChatPromptTemplate.from_messages([("system", AGENT_PLAN_PROMPT), ("human", "请分析用户指令。")])
| LLM.DOUBAO_PRO_32K.create(temperature=0) | LLM.ZM_GPT_5_4_MINI.create(temperature=0)
| StrOutputParser() | StrOutputParser()
) )
@@ -119,7 +119,7 @@ async def plan_edit(job_title: str, job_description: str, resume_json: str,
_record_edit_chain = ( _record_edit_chain = (
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_EDIT_PROMPT), ("human", "请执行修改。")]) ChatPromptTemplate.from_messages([("system", AGENT_MODULE_EDIT_PROMPT), ("human", "请执行修改。")])
| LLM.ZM_GPT_5_4_MINI.create(temperature=0.3) | LLM.DOUBAO_PRO_32K.create(temperature=0.3)
| StrOutputParser() | StrOutputParser()
) )
@@ -144,7 +144,7 @@ async def execute_record_edit(job_title: str, job_description: str, instruction:
_record_add_chain = ( _record_add_chain = (
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_ADD_PROMPT), ("human", "请生成新记录。")]) ChatPromptTemplate.from_messages([("system", AGENT_MODULE_ADD_PROMPT), ("human", "请生成新记录。")])
| LLM.ZM_GPT_5_4_MINI.create(temperature=0.3) | LLM.DOUBAO_PRO_32K.create(temperature=0.3)
| StrOutputParser() | StrOutputParser()
) )
+13
View File
@@ -177,6 +177,8 @@ class SkillGapService:
async def ai_edit_customize_resume(self, user_id: int, job_id: int, async def ai_edit_customize_resume(self, user_id: int, job_id: int,
instruction: str, chat_history: list) -> dict: instruction: str, chat_history: list) -> dict:
"""AI 对话式编辑定制简历(原子化操作版)""" """AI 对话式编辑定制简历(原子化操作版)"""
log.info(f"AI编辑定制简历开始 [user={user_id}, job={job_id}, instruction={instruction[:50]}]")
t_start = time.monotonic()
# 1. 取当前定制简历 # 1. 取当前定制简历
cr_data = await customize_resume_store.get(user_id, job_id) cr_data = await customize_resume_store.get(user_id, job_id)
if not cr_data: if not cr_data:
@@ -188,7 +190,9 @@ class SkillGapService:
job_desc = f"{job.description or ''}\n{job.requirement or ''}" job_desc = f"{job.description or ''}\n{job.requirement or ''}"
# 3. 规划 AI(意图识别 + 操作原子化) # 3. 规划 AI(意图识别 + 操作原子化)
history_str = json.dumps(chat_history, ensure_ascii=False) if chat_history else "" history_str = json.dumps(chat_history, ensure_ascii=False) if chat_history else ""
t0 = time.monotonic()
plan = await plan_edit(job.title or "", job_desc, resume_json, history_str, instruction) plan = await plan_edit(job.title or "", job_desc, resume_json, history_str, instruction)
log.info(f"AI编辑规划完成 ({round(time.monotonic() - t0, 2)}s), plan_action={plan.get('action') if plan else None} , 详情计划:{plan}")
if not plan: if not plan:
return {"type": "message", "message": "抱歉,我没有理解你的意思,请再描述一下。"} return {"type": "message", "message": "抱歉,我没有理解你的意思,请再描述一下。"}
if plan.get("action") == "chat": if plan.get("action") == "chat":
@@ -197,14 +201,19 @@ class SkillGapService:
operations = plan.get("operations", []) operations = plan.get("operations", [])
if not operations: if not operations:
return {"type": "message", "message": plan.get("message", "请再描述一下你的需求。")} return {"type": "message", "message": plan.get("message", "请再描述一下你的需求。")}
log.info(f"AI编辑操作列表: {len(operations)}个操作 {[op.get('type') + '/' + op.get('module', '') for op in operations]}")
# 截取最近10条对话历史 # 截取最近10条对话历史
recent_history = chat_history[-10:] if len(chat_history) > 10 else chat_history recent_history = chat_history[-10:] if len(chat_history) > 10 else chat_history
recent_history_str = json.dumps(recent_history, ensure_ascii=False) if recent_history else "" recent_history_str = json.dumps(recent_history, ensure_ascii=False) if recent_history else ""
# 5. 按操作类型分发执行 # 5. 按操作类型分发执行
# 先处理 delete(零 AI 开销) # 先处理 delete(零 AI 开销)
delete_count = 0
for op in operations: for op in operations:
if op.get("type") == "delete": if op.get("type") == "delete":
self._apply_delete(cr, op.get("module", ""), op.get("id", "")) self._apply_delete(cr, op.get("module", ""), op.get("id", ""))
delete_count += 1
if delete_count:
log.info(f"AI编辑删除操作完成: {delete_count}条记录")
# 并发执行 update 和 add # 并发执行 update 和 add
ai_tasks = [] ai_tasks = []
for op in operations: for op in operations:
@@ -232,8 +241,11 @@ class SkillGapService:
)) ))
# 并发执行 # 并发执行
if ai_tasks: if ai_tasks:
log.info(f"AI编辑执行开始: {len(ai_tasks)}个并发任务")
t0 = time.monotonic()
coros = [t[3] for t in ai_tasks] coros = [t[3] for t in ai_tasks]
results = await asyncio.gather(*coros, return_exceptions=True) results = await asyncio.gather(*coros, return_exceptions=True)
log.info(f"AI编辑执行完成, 耗时={round(time.monotonic() - t0, 2)}s")
for (op_type, mod_name, record_id, _), result in zip(ai_tasks, results): for (op_type, mod_name, record_id, _), result in zip(ai_tasks, results):
if isinstance(result, Exception): if isinstance(result, Exception):
log.warning(f"AI编辑[{op_type}/{mod_name}/{record_id}]失败: {result}") log.warning(f"AI编辑[{op_type}/{mod_name}/{record_id}]失败: {result}")
@@ -249,6 +261,7 @@ class SkillGapService:
# 拼接更新模块标签 # 拼接更新模块标签
updated_modules = list(dict.fromkeys(op.get("module", "") for op in operations)) updated_modules = list(dict.fromkeys(op.get("module", "") for op in operations))
label = "".join(_MODULE_LABELS.get(m, m) for m in updated_modules if m) label = "".join(_MODULE_LABELS.get(m, m) for m in updated_modules if m)
log.info(f"AI编辑定制简历完成 [user={user_id}, job={job_id}], 总耗时={round(time.monotonic() - t_start, 2)}s, 更新模块={label}")
return {"type": "updated", "message": f"完成!已更新:{label or '简历内容'}"} return {"type": "updated", "message": f"完成!已更新:{label or '简历内容'}"}
@staticmethod @staticmethod