添加引导词和投递模板

This commit is contained in:
2026-08-26 16:19:15 +08:00
parent ab79dd89be
commit 8d57c5dbc3
17 changed files with 644 additions and 13 deletions
+3 -1
View File
@@ -37,7 +37,7 @@ class AIClient:
# ------------------------------------------------------------------
# 职位匹配度评分
# ------------------------------------------------------------------
def score_job(self, jd_text: str, resume_content: str) -> MatchResult:
def score_job(self, jd_text: str, resume_content: str, prompt: str | None = None) -> MatchResult:
"""根据 JD 与主简历内容评估匹配度"""
if not self.available():
return MatchResult(50, "AI 未配置,默认放行")
@@ -49,6 +49,8 @@ class AIClient:
"评分标准:80-100 高度匹配;60-79 基本匹配;40-59 部分匹配;0-39 不匹配。"
)
user_prompt = f"【职位描述】\n{jd_text}\n\n【候选人简历】\n{resume_content}"
if prompt:
user_prompt += f"\n\n【用户额外偏好/引导词】\n{prompt}"
try:
resp = self.client.chat.completions.create(
+4 -2
View File
@@ -177,7 +177,7 @@ class Applicant:
salary_min: int | None, salary_max: int | None,
min_score: int, delay_range: tuple[int, int],
boss_online_only: bool = False, daily_limit: int = 0,
allow_headhunter: bool = False) -> None:
allow_headhunter: bool = False, prompt: str | None = None) -> None:
if self.is_running:
logger.warning("已有投递任务在运行")
return
@@ -185,6 +185,7 @@ class Applicant:
session = self.server.start_session(
keywords=",".join(keywords), city=city,
salary_min=salary_min, salary_max=salary_max,
prompt=prompt,
)
self.session_id = session["id"]
@@ -197,6 +198,7 @@ class Applicant:
self.boss_online_only = boss_online_only
self.daily_limit = daily_limit
self.allow_headhunter = allow_headhunter
self.prompt = prompt
self._daily_base = 0
self._thread = threading.Thread(
@@ -462,7 +464,7 @@ class Applicant:
ai_score, ai_reason = -1, ""
if self.ai and self.ai.available() and self.primary_resume_content:
result = self.ai.score_job(card.jd_text, self.primary_resume_content)
result = self.ai.score_job(card.jd_text, self.primary_resume_content, prompt=self.prompt)
ai_score, ai_reason = result.score, result.reason
logger.info(f"AI 评分 {ai_score}(及格线 {min_score}):"
f"{card.company} - {card.title} | {ai_reason}")
+30 -1
View File
@@ -211,7 +211,8 @@ class ServerAPI:
# 投递会话
# ------------------------------------------------------------------
def start_session(self, keywords: str, city: str,
salary_min: int | None, salary_max: int | None) -> dict:
salary_min: int | None, salary_max: int | None,
prompt: str | None = None) -> dict:
resp = self._req("post",
f"{self.base_url}/api/sessions/start",
json={
@@ -219,6 +220,7 @@ class ServerAPI:
"city": city,
"salary_min": salary_min,
"salary_max": salary_max,
"prompt": prompt,
},
headers=self._headers(), timeout=15,
)
@@ -279,6 +281,33 @@ class ServerAPI:
page += 1
return companies
# ------------------------------------------------------------------
# 投递条件模板
# ------------------------------------------------------------------
def list_templates(self) -> list[dict]:
resp = self._req("get", f"{self.base_url}/api/templates",
headers=self._headers(), timeout=15)
resp.raise_for_status()
return resp.json()
def create_template(self, data: dict) -> dict:
resp = self._req("post", f"{self.base_url}/api/templates",
json=data, headers=self._headers(), timeout=15)
resp.raise_for_status()
return resp.json()
def update_template(self, template_id: int, data: dict) -> dict:
resp = self._req("put", f"{self.base_url}/api/templates/{template_id}",
json=data, headers=self._headers(), timeout=15)
resp.raise_for_status()
return resp.json()
def delete_template(self, template_id: int) -> dict:
resp = self._req("delete", f"{self.base_url}/api/templates/{template_id}",
headers=self._headers(), timeout=15)
resp.raise_for_status()
return resp.json()
def get_stats(self) -> dict:
resp = self._req("get", f"{self.base_url}/api/jobs/stats", headers=self._headers(), timeout=15)
resp.raise_for_status()
+41
View File
@@ -168,6 +168,7 @@ def start_apply_shared(params: dict) -> dict:
boss_online_only=bool(params.get("boss_online_only")),
daily_limit=int(params.get("daily_limit") or 0),
allow_headhunter=bool(params.get("allow_headhunter")),
prompt=params.get("prompt"),
)
return {"ok": True, "msg": "投递任务已启动", "session_id": applicant.session_id}
@@ -216,6 +217,7 @@ class StartApplyReq(BaseModel):
boss_online_only: bool = False
daily_limit: int = 0
allow_headhunter: bool = False
prompt: str | None = None
class ResumeUpdateReq(BaseModel):
@@ -488,6 +490,45 @@ def stop_apply():
return {"ok": True, "msg": "正在停止投递任务..."}
# =======================================================
# 投递条件模板(服务端持久化)
# =======================================================
@app.get("/api/templates")
def list_templates():
_require_auth()
try:
return state.server_api.list_templates()
except requests.HTTPError as e:
raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e))
@app.post("/api/templates")
def create_template(req: dict):
_require_auth()
try:
return state.server_api.create_template(req)
except requests.HTTPError as e:
raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e))
@app.put("/api/templates/{template_id}")
def update_template(template_id: int, req: dict):
_require_auth()
try:
return state.server_api.update_template(template_id, req)
except requests.HTTPError as e:
raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e))
@app.delete("/api/templates/{template_id}")
def delete_template(template_id: int):
_require_auth()
try:
return state.server_api.delete_template(template_id)
except requests.HTTPError as e:
raise HTTPException(status_code=e.response.status_code, detail=_extract_error(e))
@app.get("/api/apply-status")
def apply_status():
applicant = state.applicant
+150
View File
@@ -26,6 +26,7 @@ function goToStep(step) {
}
if (step === 2) detectBossLogin(); // 进入 Boss登录 步骤自动活体检测
if (step === 3) loadResumes();
if (step === 4) loadTemplates();
if (step === 5) loadHistory();
}
document.querySelectorAll('.step').forEach(el => {
@@ -379,6 +380,7 @@ $('btnStartApply').addEventListener('click', async () => {
boss_online_only: $('bossOnlineOnly').checked,
allow_headhunter: $('allowHeadhunter').checked,
daily_limit: parseInt($('dailyLimit').value) || 0,
prompt: $('prompt').value.trim() || null,
}),
});
toast('投递任务已启动');
@@ -397,6 +399,154 @@ $('btnStopApply').addEventListener('click', async () => {
} catch (e) { toast('停止失败:' + e.message); }
});
// ==========================================================
// 投递模板管理
// ==========================================================
let templatesCache = [];
let editingTemplateId = null;
async function loadTemplates() {
try {
templatesCache = await api('/api/templates') || [];
const select = $('templateSelect');
select.innerHTML = '<option value="">-- 不使用模板 --</option>';
templatesCache.forEach(t => {
const opt = document.createElement('option');
opt.value = t.id;
opt.textContent = t.name;
select.appendChild(opt);
});
} catch (e) {
console.error('加载模板失败', e);
}
}
function fillApplyForm(t) {
$('keywords').value = (t.keywords || '').replace(/,/g, ', ');
$('city').value = t.city || '北京';
$('salaryMin').value = t.salary_min || '';
$('salaryMax').value = t.salary_max || '';
$('minScore').value = t.min_score || 65;
$('dailyLimit').value = t.daily_limit || 30;
$('bossOnlineOnly').checked = !!t.boss_online_only;
$('allowHeadhunter').checked = !!t.allow_headhunter;
$('prompt').value = t.prompt || '';
}
function collectTemplateFromForm() {
return {
keywords: $('keywords').value.split(',').map(k => k.trim()).filter(Boolean).join(','),
city: $('city').value,
salary_min: parseInt($('salaryMin').value) || null,
salary_max: parseInt($('salaryMax').value) || null,
min_score: parseInt($('minScore').value) || 65,
daily_limit: parseInt($('dailyLimit').value) || 0,
boss_online_only: $('bossOnlineOnly').checked,
allow_headhunter: $('allowHeadhunter').checked,
prompt: $('prompt').value.trim() || null,
};
}
$('templateSelect').addEventListener('change', () => {
const id = $('templateSelect').value;
if (!id) return;
const t = templatesCache.find(x => String(x.id) === id);
if (t) fillApplyForm(t);
});
$('btnSaveTemplate').addEventListener('click', () => {
editingTemplateId = null;
$('templateName').value = '';
$('saveTemplateModal').classList.remove('hidden');
});
$('btnCancelSaveTemplate').addEventListener('click', () => {
$('saveTemplateModal').classList.add('hidden');
});
$('btnConfirmSaveTemplate').addEventListener('click', async () => {
const name = $('templateName').value.trim();
if (!name) { toast('请输入模板名称'); return; }
const data = { name, ...collectTemplateFromForm() };
try {
if (editingTemplateId) {
await api(`/api/templates/${editingTemplateId}`, { method: 'PUT', body: JSON.stringify(data) });
toast('模板已更新');
} else {
await api('/api/templates', { method: 'POST', body: JSON.stringify(data) });
toast('模板已保存');
}
$('saveTemplateModal').classList.add('hidden');
await loadTemplates();
} catch (e) {
toast('保存失败:' + e.message, 5000);
}
});
$('btnManageTemplates').addEventListener('click', async () => {
await renderTemplatesList();
$('manageTemplatesModal').classList.remove('hidden');
});
$('btnCloseManageTemplates').addEventListener('click', () => {
$('manageTemplatesModal').classList.add('hidden');
});
async function renderTemplatesList() {
await loadTemplates();
const tbody = $('templatesBody');
if (!templatesCache.length) {
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;color:#999">暂无模板</td></tr>';
return;
}
tbody.innerHTML = templatesCache.map(t => `
<tr>
<td>${escapeHtml(t.name)}</td>
<td>${escapeHtml(t.keywords || '-')}</td>
<td>${escapeHtml(t.city || '-')}</td>
<td>
<button class="btn btn-sm" data-tid="${t.id}" data-action="apply">套用</button>
<button class="btn btn-sm" data-tid="${t.id}" data-action="edit">编辑</button>
<button class="btn btn-sm btn-danger" data-tid="${t.id}" data-action="delete">删除</button>
</td>
</tr>
`).join('');
tbody.querySelectorAll('button').forEach(b => {
b.addEventListener('click', handleTemplateAction);
});
}
async function handleTemplateAction(e) {
const tid = parseInt(e.target.dataset.tid);
const action = e.target.dataset.action;
if (action === 'apply') {
const t = templatesCache.find(x => x.id === tid);
if (t) {
fillApplyForm(t);
$('templateSelect').value = tid;
$('manageTemplatesModal').classList.add('hidden');
toast('已套用模板:' + t.name);
}
} else if (action === 'edit') {
const t = templatesCache.find(x => x.id === tid);
if (!t) return;
editingTemplateId = tid;
$('templateName').value = t.name;
fillApplyForm(t);
$('manageTemplatesModal').classList.add('hidden');
$('saveTemplateModal').classList.remove('hidden');
} else if (action === 'delete') {
if (!confirm('确定删除该模板吗?')) return;
try {
await api(`/api/templates/${tid}`, { method: 'DELETE' });
toast('模板已删除');
await renderTemplatesList();
} catch (e) {
toast('删除失败:' + e.message, 5000);
}
}
}
function toggleApplyUI(running) {
$('btnStartApply').classList.toggle('hidden', running);
$('btnStopApply').classList.toggle('hidden', !running);
+1
View File
@@ -180,6 +180,7 @@ body {
.action-buttons { display: flex; gap: 12px; margin-top: 10px; }
.btn-outline { background: #fff; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline:hover { filter: brightness(.96); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
/* 登录/注册模式切换引导链接 */
.switch-link {
+47
View File
@@ -81,6 +81,18 @@
<!-- Step 4: 配置投递 -->
<section class="panel hidden" id="panel-4">
<h2>配置并开始投递</h2>
<div class="form-row">
<div class="form-group" style="flex:3;">
<label>选择模板</label>
<select id="templateSelect">
<option value="">-- 不使用模板 --</option>
</select>
</div>
<div class="form-group" style="display:flex;align-items:flex-end;gap:8px;padding-bottom:6px;">
<button class="btn btn-outline" id="btnManageTemplates" type="button">管理模板</button>
<button class="btn btn-outline" id="btnSaveTemplate" type="button">保存为模板</button>
</div>
</div>
<div class="form-group">
<label>搜索关键词(多个用逗号分隔)</label>
<input type="text" id="keywords" placeholder="如:Python开发,后端工程师" value="Python开发">
@@ -128,6 +140,10 @@
</label>
</div>
</div>
<div class="form-group">
<label>AI 引导词(可选,会作为 AI 评分时的额外偏好)</label>
<textarea id="prompt" rows="4" placeholder="例如:优先投递 Java 后端岗位,接受 10-15K,有 AI 项目经验优先"></textarea>
</div>
<div class="action-buttons">
<button class="btn btn-success" id="btnStartApply">▶ 开始投递</button>
<button class="btn btn-danger hidden" id="btnStopApply">■ 结束投递</button>
@@ -209,6 +225,37 @@
</div>
</div>
<!-- 保存模板弹窗 -->
<div class="modal-mask hidden" id="saveTemplateModal">
<div class="modal-box">
<h3>保存为模板</h3>
<div class="form-group">
<label>模板名称</label>
<input type="text" id="templateName" placeholder="如:Java 北京 10-15K">
</div>
<div class="action-buttons">
<button class="btn btn-primary" id="btnConfirmSaveTemplate">保 存</button>
<button class="btn btn-outline" id="btnCancelSaveTemplate">取 消</button>
</div>
</div>
</div>
<!-- 模板管理弹窗 -->
<div class="modal-mask hidden" id="manageTemplatesModal">
<div class="modal-box" style="min-width: 680px; max-width: 90vw;">
<h3>管理投递模板</h3>
<table class="history-table">
<thead>
<tr><th>名称</th><th>关键词</th><th>城市</th><th>操作</th></tr>
</thead>
<tbody id="templatesBody"></tbody>
</table>
<div class="action-buttons">
<button class="btn btn-outline" id="btnCloseManageTemplates">关 闭</button>
</div>
</div>
</div>
<!-- Toast 提示 -->
<div class="toast" id="toast"></div>