简历诊断添加日志
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"""简历诊断 AI 引擎:并行诊断 + 汇总评价"""
|
"""简历诊断 AI 引擎:并行诊断 + 汇总评价"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
from langchain_core.output_parsers import StrOutputParser
|
from langchain_core.output_parsers import StrOutputParser
|
||||||
from langchain_core.prompts import ChatPromptTemplate
|
from langchain_core.prompts import ChatPromptTemplate
|
||||||
@@ -94,12 +95,18 @@ async def polish_content(module_type: str, reference_content: list[dict] | str |
|
|||||||
|
|
||||||
async def _safe_invoke(task: dict) -> dict:
|
async def _safe_invoke(task: dict) -> dict:
|
||||||
"""单条记录诊断,失败返回空结果"""
|
"""单条记录诊断,失败返回空结果"""
|
||||||
|
module_type = task.get("module_type", "unknown")
|
||||||
|
log.info(f"AI诊断[{module_type}]开始")
|
||||||
|
start = time.time()
|
||||||
raw = ""
|
raw = ""
|
||||||
try:
|
try:
|
||||||
raw = await _diagnose_chain.ainvoke(task)
|
raw = await _diagnose_chain.ainvoke(task)
|
||||||
|
elapsed = time.time() - start
|
||||||
|
log.info(f"AI诊断[{module_type}]完成, 耗时{elapsed:.2f}s")
|
||||||
return parse_llm_json(raw)
|
return parse_llm_json(raw)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(f"AI诊断[{task.get('module_type', '')}]失败: {e}\n原始输出: {raw[:500]}")
|
elapsed = time.time() - start
|
||||||
|
log.warning(f"AI诊断[{module_type}]失败, 耗时{elapsed:.2f}s: {e}\n原始输出: {raw[:500]}")
|
||||||
return _empty_result()
|
return _empty_result()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
"""简历诊断接口"""
|
"""简历诊断接口"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
@@ -7,6 +9,7 @@ from app.ai.resume_diagnoser.diagnoser import diagnose_all, generate_summary, po
|
|||||||
from app.core.auth import func_permission
|
from app.core.auth import func_permission
|
||||||
from app.core.context import RequestContext
|
from app.core.context import RequestContext
|
||||||
from app.core.database import get_db
|
from app.core.database import get_db
|
||||||
|
from app.core.logger import log
|
||||||
from app.services.resume_diagnose_service import ResumeDiagnoseService, aggregate_results
|
from app.services.resume_diagnose_service import ResumeDiagnoseService, aggregate_results
|
||||||
|
|
||||||
router = APIRouter(prefix="/resume/diagnose", tags=["简历诊断"])
|
router = APIRouter(prefix="/resume/diagnose", tags=["简历诊断"])
|
||||||
@@ -20,6 +23,7 @@ class DiagnoseParam(BaseModel):
|
|||||||
async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permission("resume_diag"))):
|
async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permission("resume_diag"))):
|
||||||
"""触发简历AI诊断,返回报告ID"""
|
"""触发简历AI诊断,返回报告ID"""
|
||||||
user_id = RequestContext.user_id.get()
|
user_id = RequestContext.user_id.get()
|
||||||
|
log.info(f"简历诊断开始, resumeId={param.resume_id}, userId={user_id}")
|
||||||
|
|
||||||
# 1. 短事务:加载简历数据
|
# 1. 短事务:加载简历数据
|
||||||
async for session in get_db():
|
async for session in get_db():
|
||||||
@@ -27,21 +31,29 @@ async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permissio
|
|||||||
resume, tasks = await service.load_resume_data(param.resume_id, user_id)
|
resume, tasks = await service.load_resume_data(param.resume_id, user_id)
|
||||||
|
|
||||||
if not tasks:
|
if not tasks:
|
||||||
|
log.warning(f"简历无可诊断内容, resumeId={param.resume_id}")
|
||||||
raise ValueError("简历没有可诊断的描述内容")
|
raise ValueError("简历没有可诊断的描述内容")
|
||||||
|
|
||||||
|
log.info(f"加载简历数据完成, 待诊断任务数={len(tasks)}")
|
||||||
|
|
||||||
# 2. 并行 AI 诊断(不持有数据库连接)
|
# 2. 并行 AI 诊断(不持有数据库连接)
|
||||||
ai_tasks = [{k: v for k, v in t.items() if not k.startswith("_")} for t in tasks]
|
ai_tasks = [{k: v for k, v in t.items() if not k.startswith("_")} for t in tasks]
|
||||||
|
t0 = time.time()
|
||||||
ai_results = await diagnose_all(ai_tasks)
|
ai_results = await diagnose_all(ai_tasks)
|
||||||
|
log.info(f"AI诊断全部完成, 耗时{time.time() - t0:.2f}s")
|
||||||
|
|
||||||
# 3. 统计 + 评级(纯计算)
|
# 3. 统计 + 评级(纯计算)
|
||||||
stats = aggregate_results(tasks, ai_results)
|
stats = aggregate_results(tasks, ai_results)
|
||||||
|
log.info(f"统计完成, grade={stats['grade']}, urgent={stats['urgent_total']}, important={stats['important_total']}, expression={stats['expression_total']}")
|
||||||
|
|
||||||
# 4. AI 生成整体评价(不持有数据库连接)
|
# 4. AI 生成整体评价(不持有数据库连接)
|
||||||
|
t1 = time.time()
|
||||||
summary = await generate_summary(
|
summary = await generate_summary(
|
||||||
grade=stats["grade"], urgent_total=stats["urgent_total"],
|
grade=stats["grade"], urgent_total=stats["urgent_total"],
|
||||||
important_total=stats["important_total"], expression_total=stats["expression_total"],
|
important_total=stats["important_total"], expression_total=stats["expression_total"],
|
||||||
target_position=resume.target_position or "", all_findings=stats["all_findings"],
|
target_position=resume.target_position or "", all_findings=stats["all_findings"],
|
||||||
)
|
)
|
||||||
|
log.info(f"AI生成整体评价完成, 耗时{time.time() - t1:.2f}s")
|
||||||
|
|
||||||
# 5. 短事务:纯写入
|
# 5. 短事务:纯写入
|
||||||
async for session in get_db():
|
async for session in get_db():
|
||||||
@@ -52,6 +64,7 @@ async def diagnose_resume(param: DiagnoseParam, _: None = Depends(func_permissio
|
|||||||
tasks, ai_results,
|
tasks, ai_results,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log.info(f"简历诊断完成, reportId={report_id}")
|
||||||
return {"reportId": report_id}
|
return {"reportId": report_id}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user