Let the model report a verdict per must-have and cap career at 39 in code when one is broken
The judge numbers an agent's must-haves (one per line) and answers met, broken or unclear for each; career is stored as the model gave it and counts as at most BROKEN_CAP when a role is served, in cv_score, Store.judgement and the SQL of Best CV match. Migration 29 adds role_judgements.musts and broken; the judge's input_key carries a format version so earlier judgements are made again. The reader lists the must-haves with their verdicts and the cap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
64fecf57ad
commit
001fc9002b
19 files changed
+336
-61
No files matched your search
+29
-16
@@ -11,7 +11,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import sqlite3
|
||||
from collections import Counter
|
||||
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
|
||||
from contextlib import closing, contextmanager
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
@@ -26,7 +26,7 @@ from app.models import (
|
||||
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
|
||||
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
|
||||
RoleCopy, RolePlace, RoleRow, ScoredRole, cv_languages as normal_languages, cv_score,
|
||||
language_flag, role_languages,
|
||||
BROKEN_CAP, capped_career, language_flag, role_languages,
|
||||
Subscription, Weights, check_prompts, company_fold, company_key, country_of, excerpt, place_key,
|
||||
fetch_terms as normal_terms, host_word, iso_day, posted_at, posted_host, remote_of, title_key,
|
||||
)
|
||||
@@ -120,7 +120,7 @@ _VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
|
||||
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
|
||||
|
||||
#: The agent's `judge` readings beside every role, the same way: `j.skills`,
|
||||
#: `j.experience` and `j.career` are NULL for a role not judged and with no
|
||||
#: `j.experience`, `j.career` and `j.broken` are NULL for a role not judged and with no
|
||||
#: agent.
|
||||
_WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agent_id = ? "
|
||||
"AND j.judged_at IS NOT NULL")
|
||||
@@ -129,15 +129,19 @@ _WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agen
|
||||
|
||||
def _cv_sql(weights: Weights | None) -> str:
|
||||
"""`cv_score` as SQL for one agent's weights, unrounded (`app.models.cv_score`
|
||||
rounds it): NULL for a role not judged, and for all three weights 0. The
|
||||
rounds it): NULL for a role not judged, and for all three weights 0. Career
|
||||
counts as at most `BROKEN_CAP` when the judgement holds a broken
|
||||
must-have (`j.broken`), as `app.models.capped_career` has it. The
|
||||
numbers are the model's validated, finite floats, so they are written in
|
||||
rather than bound, the select's placeholders being then no concern."""
|
||||
w = weights or Weights()
|
||||
total = w.cv_skills + w.cv_experience + w.cv_career
|
||||
if not total:
|
||||
return "NULL"
|
||||
career = (f"(CASE WHEN j.broken > 0 AND j.career > {BROKEN_CAP} THEN {BROKEN_CAP} "
|
||||
"ELSE j.career END)")
|
||||
return (f"(({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
|
||||
f"+ {w.cv_career!r} * j.career) / {total!r})")
|
||||
f"+ {w.cv_career!r} * {career}) / {total!r})")
|
||||
|
||||
|
||||
def _by_cv(expression: str) -> str:
|
||||
@@ -1888,27 +1892,34 @@ class Store:
|
||||
|
||||
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
|
||||
experience: int, career: int, strengths: Sequence[str],
|
||||
gaps: Sequence[str]) -> bool:
|
||||
gaps: Sequence[str], musts: Sequence[Mapping[str, str]] = ()) -> bool:
|
||||
"""Store `judge`'s reading of one role for one agent, replacing the
|
||||
one before, with `cv_score` (`app.models.cv_score`, at the default weights: the
|
||||
table's column is not read, see `judgement`) and its tries
|
||||
back at 0. False for an unknown role or agent."""
|
||||
one before: the three numbers as the model gave them, the verdict on
|
||||
each of the agent's must-haves (`musts`, `{id, text, verdict}`) and how
|
||||
many are broken, `cv_score` (`app.models.cv_score`, at the default
|
||||
weights and with the cap: the table's column is not read, see
|
||||
`judgement`) and its tries back at 0. False for an unknown role or
|
||||
agent."""
|
||||
broken = sum(1 for m in musts if m.get("verdict") == "broken")
|
||||
try:
|
||||
with self.transaction() as conn:
|
||||
conn.execute(
|
||||
"""INSERT INTO role_judgements (uid, agent_id, skills, experience, career,
|
||||
cv_score, strengths, gaps, input_key, tries,
|
||||
judged_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,0,?)
|
||||
cv_score, strengths, gaps, musts, broken,
|
||||
input_key, tries, judged_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,0,?)
|
||||
ON CONFLICT(uid, agent_id) DO UPDATE SET
|
||||
skills=excluded.skills, experience=excluded.experience,
|
||||
career=excluded.career, cv_score=excluded.cv_score,
|
||||
strengths=excluded.strengths, gaps=excluded.gaps,
|
||||
musts=excluded.musts, broken=excluded.broken,
|
||||
input_key=excluded.input_key, tries=0, judged_at=excluded.judged_at""",
|
||||
(uid, agent_id, skills, experience, career,
|
||||
cv_score(skills, experience, career),
|
||||
cv_score(skills, experience, career, broken=broken),
|
||||
json.dumps(list(strengths), ensure_ascii=False),
|
||||
json.dumps(list(gaps), ensure_ascii=False), input_key, self.now()))
|
||||
json.dumps(list(gaps), ensure_ascii=False),
|
||||
json.dumps([dict(m) for m in musts], ensure_ascii=False), broken,
|
||||
input_key, self.now()))
|
||||
except sqlite3.IntegrityError:
|
||||
return False
|
||||
return True
|
||||
@@ -1935,7 +1946,8 @@ class Store:
|
||||
def judgement(self, agent_id: int | None, uid: str) -> Judgement | None:
|
||||
"""The agent's judgement of one role, None when it has none, its
|
||||
`cv_score` the three numbers under the agent's weights as they are
|
||||
now, not as stored."""
|
||||
now, not as stored, and `career_capped` the model's career as the
|
||||
broken must-haves leave it (`BROKEN_CAP`)."""
|
||||
if agent_id is None:
|
||||
return None
|
||||
row = self._row("SELECT * FROM role_judgements WHERE agent_id = ? AND uid = ? "
|
||||
@@ -1944,8 +1956,9 @@ class Store:
|
||||
return None
|
||||
found = Judgement.from_row(row)
|
||||
agent = self.agent(agent_id)
|
||||
found.career_capped = capped_career(found.career, found.broken)
|
||||
found.cv_score = cv_score(found.skills, found.experience, found.career,
|
||||
agent.weights if agent else None)
|
||||
agent.weights if agent else None, found.broken)
|
||||
return found
|
||||
|
||||
def set_article_text(self, uid: str, text: str) -> Role | None:
|
||||
|
||||
Reference in new issue
Block a user