添加适配评分
This commit is contained in:
@@ -92,6 +92,15 @@ async def save(user_id: int, job_id: int, cr: CustomizeResume, resume_id: int |
|
||||
session.add(UserJobCustomizeResume(id=next_id(), user_id=user_id, job_id=job_id, resume_id=resume_id, resume_name=resume_name, content=content))
|
||||
|
||||
|
||||
async def get_by_id(user_id: int, customize_resume_id: int) -> CustomizeResume | None:
|
||||
"""按定制简历ID查询,校验归属当前用户,查不到返回 None"""
|
||||
async for session in get_db():
|
||||
result = await session.execute(select(UserJobCustomizeResume).where(UserJobCustomizeResume.id == customize_resume_id, UserJobCustomizeResume.user_id == user_id))
|
||||
record = result.scalar_one_or_none()
|
||||
return CustomizeResume.model_validate(record.content) if record else None
|
||||
return None
|
||||
|
||||
|
||||
async def get(user_id: int, job_id: int) -> dict | None:
|
||||
"""查询定制简历,查不到则加载默认简历构建返回
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""求职助手 Agent 岗位简历优化 Service
|
||||
|
||||
主要功能:针对岗位并发优化简历。
|
||||
依赖:resume_loader(简历统一查询)、customize_resume_store(定制简历存取+构建)、job_agent.resume_optimizer(岗位简历优化)
|
||||
使用表:bg_user_resume + 5张子表(通过 resume_loader 查询)、bg_job(查岗位)
|
||||
主要功能:针对岗位并发优化简历;岗位匹配度评分。
|
||||
依赖:resume_loader(简历统一查询)、customize_resume_store(定制简历存取+构建)、job_agent.resume_optimizer(岗位简历优化)、job_agent.match_scorer(匹配评分)
|
||||
使用表:bg_user_resume + 5张子表(通过 resume_loader 查询)、bg_job(查岗位)、bg_user_job_customize_resume(定制简历)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -13,6 +13,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.ai.job_agent.resume_optimizer import optimize_summary, optimize_experience_record
|
||||
from app.ai.job_agent.match_scorer import score_match as ai_score_match
|
||||
from app.core.logger import log
|
||||
from app.models.job import Job
|
||||
from app.schemas.customize_resume import CustomizeResume, Education, Work, Internship, Project, Competition
|
||||
@@ -25,6 +26,55 @@ class JobAgentChatService:
|
||||
def __init__(self, session: AsyncSession):
|
||||
self.session = session
|
||||
|
||||
async def score_match(self, user_id: int, customize_resume_id: int, job_id: int) -> int:
|
||||
"""岗位匹配评分:查定制简历 + 岗位 → 序列化简历 → 调AI评分,返回 0-100 整数"""
|
||||
cr = await customize_resume_store.get_by_id(user_id, customize_resume_id)
|
||||
if cr is None:
|
||||
raise ValueError("定制简历不存在")
|
||||
job = await self._get_job(job_id)
|
||||
resume_text = self._build_resume_text_from_cr(cr)
|
||||
skill_tags = "、".join(job.skill_tags) if job.skill_tags else ""
|
||||
job_desc = f"{job.description or ''}\n{job.requirement or ''}"
|
||||
return await ai_score_match(job.title or "", skill_tags, job_desc, resume_text)
|
||||
|
||||
@staticmethod
|
||||
def _build_resume_text_from_cr(cr: CustomizeResume) -> str:
|
||||
"""将定制简历序列化为文本供 AI 评估使用"""
|
||||
r = cr.resume
|
||||
parts: list[str] = []
|
||||
if r.name:
|
||||
parts.append(f"姓名:{r.name}")
|
||||
if r.skills:
|
||||
parts.append(f"技能:{'、'.join(r.skills)}")
|
||||
if r.certificates:
|
||||
parts.append(f"证书:{'、'.join(r.certificates)}")
|
||||
if r.summary:
|
||||
parts.append(f"个人概述:{r.summary}")
|
||||
if cr.education:
|
||||
parts.append("教育经历:")
|
||||
for e in cr.education:
|
||||
parts.append(f" - {e.school} {e.major} {e.degree} {e.study_type}".rstrip())
|
||||
if cr.work:
|
||||
parts.append("工作经历:")
|
||||
for w in cr.work:
|
||||
parts.append(f" - {w.company_name} {w.position}".rstrip())
|
||||
parts.extend(f" {p.text}" for p in w.description if p.text)
|
||||
if cr.internship:
|
||||
parts.append("实习经历:")
|
||||
for i in cr.internship:
|
||||
parts.append(f" - {i.company_name} {i.position}".rstrip())
|
||||
parts.extend(f" {p.text}" for p in i.description if p.text)
|
||||
if cr.project:
|
||||
parts.append("项目经历:")
|
||||
for p in cr.project:
|
||||
parts.append(f" - {p.project_name} {p.role}".rstrip())
|
||||
parts.extend(f" {seg.text}" for seg in p.description if seg.text)
|
||||
if cr.competition:
|
||||
parts.append("竞赛经历:")
|
||||
for c in cr.competition:
|
||||
parts.append(f" - {c.competition_name} {c.award}".rstrip())
|
||||
return "\n".join(parts) if parts else "暂无简历信息"
|
||||
|
||||
async def optimize_resume(self, user_id: int, resume_id: int, job_id: int) -> dict:
|
||||
"""针对岗位优化简历:查简历+岗位 → 构建定制简历 → 按单条记录并发AI优化 → 存数据库 → 返回"""
|
||||
# 1. 查简历 + 岗位
|
||||
|
||||
Reference in New Issue
Block a user