Rank by the cut: fetch gate overrides in scoring, the cut per agent, stages read the cut, fetch text renamed from enrich, the feed kept to the fetch gate, and migration 32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
060ccf66e6
commit
617356e60c
35 files changed
+1052
-749
No files matched your search
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
app companies seed|add|edit|checked|remove|by-hand|set-board|detach|discover|check|size
|
app companies seed|add|edit|checked|remove|by-hand|set-board|detach|discover|check|size
|
||||||
app searches add|list|remove
|
app searches add|list|remove
|
||||||
app agents list|prompt
|
app agents list|prompt
|
||||||
app stages [extract|summarise|judge|enrich on|off]
|
app stages [extract|summarise|judge|fetch_text on|off]
|
||||||
app dupes
|
app dupes
|
||||||
app prep [unmapped|unlinked] [--remap]
|
app prep [unmapped|unlinked] [--remap]
|
||||||
app db init
|
app db init
|
||||||
@@ -177,8 +177,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
prompt.add_argument("--remove", action="store_true", help="remove the prompt instead")
|
prompt.add_argument("--remove", action="store_true", help="remove the prompt instead")
|
||||||
|
|
||||||
stages = sub.add_parser(
|
stages = sub.add_parser(
|
||||||
"stages", help="show whether extract, summarise, judge and enrich run, or switch one")
|
"stages", help="show whether extract, summarise, judge and fetch_text run, or switch one")
|
||||||
stages.add_argument("name", nargs="?", choices=["extract", "summarise", "judge", "enrich"])
|
stages.add_argument("name", nargs="?", choices=["extract", "summarise", "judge", "fetch_text"])
|
||||||
stages.add_argument("state", nargs="?", choices=["on", "off"])
|
stages.add_argument("state", nargs="?", choices=["on", "off"])
|
||||||
|
|
||||||
sub.add_parser("seniority", help="per host, how often the stated level equals the model's")
|
sub.add_parser("seniority", help="per host, how often the stated level equals the model's")
|
||||||
|
|||||||
+14
-21
@@ -44,9 +44,8 @@ class ExtractConfig(ModelTaskConfig):
|
|||||||
"""Turning a posting's title and text into the gate columns. See
|
"""Turning a posting's title and text into the gate columns. See
|
||||||
app/jobs/extract.py. Off by default, so nobody is billed by surprise:
|
app/jobs/extract.py. Off by default, so nobody is billed by surprise:
|
||||||
on the API backend every batch is a paid call. On, it reads only the
|
on the API backend every batch is a paid call. On, it reads only the
|
||||||
best roles of each enabled agent, as deep and as low as that agent's
|
roles in the cut of an enabled agent (`app.jobs.score`), so the cost
|
||||||
own `limits` say, so the cost follows the ranking rather than the
|
follows the agents rather than the boards."""
|
||||||
boards."""
|
|
||||||
|
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
model: str = "claude-haiku-4-5-20251001"
|
model: str = "claude-haiku-4-5-20251001"
|
||||||
@@ -56,9 +55,9 @@ class ExtractConfig(ModelTaskConfig):
|
|||||||
class SummariseConfig(ModelTaskConfig):
|
class SummariseConfig(ModelTaskConfig):
|
||||||
"""About 60 words on a role, for the list and the read page. See
|
"""About 60 words on a role, for the list and the read page. See
|
||||||
app/jobs/summarise.py. Off by default like extract; on, a pull summarises
|
app/jobs/summarise.py. Off by default like extract; on, a pull summarises
|
||||||
the best of each enabled agent, as deep and as low as that agent's
|
the best `summarise_top` final scores of each enabled agent (its
|
||||||
own `limits` say, so the cost is bounded whatever the backlog, and every
|
`limits`), so the cost is bounded whatever the backlog, and every role
|
||||||
role that is saved or liked, whatever its rank. The read page's Summarise button asks for one
|
that is saved or liked, whatever its rank. The read page's Summarise button asks for one
|
||||||
role whether this is on or not."""
|
role whether this is on or not."""
|
||||||
|
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
@@ -69,12 +68,10 @@ class SummariseConfig(ModelTaskConfig):
|
|||||||
|
|
||||||
|
|
||||||
class JudgeConfig(ModelTaskConfig):
|
class JudgeConfig(ModelTaskConfig):
|
||||||
"""Each search agent's best roles read against its CV, as three numbers
|
"""Each search agent's cut read against its CV, as three numbers and a
|
||||||
and a total. See app/jobs/judge.py. Off by default like extract; on, a
|
total. See app/jobs/judge.py. Off by default like extract; on, a pull
|
||||||
pull judges the best of each enabled agent with a CV, as deep and as low
|
judges the cut of each enabled agent with a CV and a prompt, and only
|
||||||
as that agent's own `limits` say (`judge_top`, `judge_min`), and the
|
the roles whose judgement is missing or was read from another CV or
|
||||||
`judge_cv_top` ungated ones closest to its CV that those leave out, and
|
|
||||||
only the roles whose judgement is missing or was read from another CV or
|
|
||||||
text."""
|
text."""
|
||||||
|
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
@@ -84,17 +81,13 @@ class JudgeConfig(ModelTaskConfig):
|
|||||||
batch_size: int = Field(5, ge=1)
|
batch_size: int = Field(5, ge=1)
|
||||||
|
|
||||||
|
|
||||||
class EnrichConfig(Section):
|
class FetchTextConfig(Section):
|
||||||
"""Reading roles on their own pages after scoring, for the hosts whose
|
"""Reading roles on their own pages after scoring, for the hosts whose
|
||||||
list carries no text. See app/jobs/enrich.py. A role is read when it has
|
list carries no text. See app/jobs/fetch_text.py. A role is read when it
|
||||||
no text and an enabled agent with a prompt ranks it ungated among its
|
has no text and is in the cut of an enabled agent (`app.jobs.score`), so
|
||||||
best `top` and at `min_score` or above: the extract bar (`Limits`,
|
every role the model reads has its text first."""
|
||||||
500 and 0.55) with the score a notch lower, since a role ranked on its
|
|
||||||
title alone is the one whose score its text moves most."""
|
|
||||||
|
|
||||||
enabled: bool = True
|
enabled: bool = True
|
||||||
top: int = Field(500, ge=0)
|
|
||||||
min_score: float = Field(0.5, ge=0, le=1)
|
|
||||||
#: Reads per board and per run. Per board is the cap the pull had; the
|
#: Reads per board and per run. Per board is the cap the pull had; the
|
||||||
#: boards are read in parallel on the `http` pool.
|
#: boards are read in parallel on the `http` pool.
|
||||||
per_board: int = Field(200, ge=0)
|
per_board: int = Field(200, ge=0)
|
||||||
@@ -253,7 +246,7 @@ class Config(Section):
|
|||||||
summarise: SummariseConfig = Field(default_factory=SummariseConfig)
|
summarise: SummariseConfig = Field(default_factory=SummariseConfig)
|
||||||
judge: JudgeConfig = Field(default_factory=JudgeConfig)
|
judge: JudgeConfig = Field(default_factory=JudgeConfig)
|
||||||
embed: EmbedConfig = Field(default_factory=EmbedConfig)
|
embed: EmbedConfig = Field(default_factory=EmbedConfig)
|
||||||
enrich: EnrichConfig = Field(default_factory=EnrichConfig)
|
fetch_text: FetchTextConfig = Field(default_factory=FetchTextConfig)
|
||||||
#: Starter agents, imported once into an empty table.
|
#: Starter agents, imported once into an empty table.
|
||||||
agents: list[AgentSeed] = Field(default_factory=list)
|
agents: list[AgentSeed] = Field(default_factory=list)
|
||||||
#: Starter searches, imported once into an empty set of `search`
|
#: Starter searches, imported once into an empty set of `search`
|
||||||
|
|||||||
+51
-47
@@ -1,32 +1,29 @@
|
|||||||
"""The tasks roledesk offers, and the order a pull runs them in.
|
"""The tasks roledesk offers, and the order a pull runs them in.
|
||||||
|
|
||||||
pull → prep → embed → score → enrich → prep → embed → score → extract → score
|
pull → prep → embed → score → fetch_text → prep → embed → score → extract
|
||||||
→ summarise → judge
|
→ score → judge → summarise
|
||||||
|
|
||||||
newsdesk's cascade convention: a cascade is a tuple of task names, and the
|
newsdesk's cascade convention: a cascade is a tuple of task names, and the
|
||||||
final job of one task starts the next (`step` is the callback it carries).
|
final job of one task starts the next (`step` is the callback it carries).
|
||||||
Nothing is alive between two tasks. `prep` (`app/jobs/prep.py`) maps what
|
Nothing is alive between two tasks. `prep` (`app/jobs/prep.py`) maps what
|
||||||
the pull stored and folds the copies before anything reads the roles; after
|
the pull stored and folds the copies before anything reads the roles; after
|
||||||
`enrich` it maps the roles their own pages filled. A stage is addressed by its position in
|
`fetch_text` it maps the roles their own pages filled. A stage is addressed
|
||||||
the tuple, not its name, since `score` runs twice.
|
by its position in the tuple, not its name, since `score` runs three times.
|
||||||
|
|
||||||
Every stage is always in the chain, and a stage that is switched off finds
|
Every stage is always in the chain, and a stage that is switched off finds
|
||||||
nothing: a stage switched off (`stages.stage_on`), or an `on_ingest` this pull does not
|
nothing: a stage switched off (`stages.stage_on`), or an `on_ingest` this
|
||||||
satisfy, is an extract stage with no batches whose final job moves straight
|
pull does not satisfy, is a stage with no batches whose final job moves
|
||||||
on. The free stages go first: embed and score cost no tokens, and the score
|
straight on. The free stages go first: embed and score cost no tokens, and
|
||||||
they produce is what bounds the rest. Enrich reads the best roles without
|
score writes each agent's cut (`app.jobs.score`), which bounds the rest.
|
||||||
text on their own pages (`app/jobs/enrich.py`), and prep, embed and score
|
Fetch text reads the role's own page for the roles in the cut that came
|
||||||
follow for the roles it filled; when it filled none, `step` passes over all
|
without text (`app/jobs/fetch_text.py`), and prep, embed and score follow
|
||||||
three. Extract
|
for the roles it filled, so their levels and the cut are recomputed; when
|
||||||
reads only the best
|
it filled none, `step` passes over all three. Extract reads the cut; the
|
||||||
roles of each enabled agent, as deep and as low as that agent's own `limits`
|
score after it applies the fetch gate and the cut again with the columns
|
||||||
say; the second score then applies the gates to the columns it filled.
|
extract filled, so a role can drop out or enter (one that enters is
|
||||||
Summarise follows, on the best roles by the same agent's summarise limits,
|
extracted on the next pull). Judge reads each agent's cut as recomputed,
|
||||||
and judge runs last, reading each agent's best roles against its CV by its
|
against its CV. Summarise runs last, on the top of each agent's feed by
|
||||||
judge limits. The `enrich` cascade, which follows the rescore after an agent
|
final score and the roles liked or saved: it is no part of any score.
|
||||||
is saved, ends with judge too, so a changed CV, prompt or like text is read
|
|
||||||
again at once rather than at the next pull; a pair whose `input_key` did not
|
|
||||||
change costs nothing.
|
|
||||||
|
|
||||||
A batch that failed, or a stage somebody killed, does not stop the chain: the
|
A batch that failed, or a stage somebody killed, does not stop the chain: the
|
||||||
work comes round on the next pull, and a rescore of what did arrive is worth
|
work comes round on the next pull, and a rescore of what did arrive is worth
|
||||||
@@ -36,10 +33,13 @@ having either way.
|
|||||||
and a cascade is started by one: the `pull` job's only work is to ask for the
|
and a cascade is started by one: the `pull` job's only work is to ask for the
|
||||||
chain. Its default schedule, `every 6h`, is declared here beside it.
|
chain. Its default schedule, `every 6h`, is declared here beside it.
|
||||||
|
|
||||||
`enrich` is a job and a cascade the same way, `enrich → prep → embed → score`, queued
|
`fetch_text` is a job and a cascade the same way, the pull's chain from
|
||||||
behind the `score` that follows a change to the ranking other than a pull's
|
fetch text on, queued behind the `score` that follows a change to the
|
||||||
(`enrich_after`): an agent saved, a company's affinity changed. A vote moves
|
ranking other than a pull's (`fetch_text_after`): an agent saved, a
|
||||||
one agent's taste a little and queues neither.
|
company's affinity or overrides changed. The cut may have changed, so its
|
||||||
|
new roles get their text, extract and judge at once rather than at the next
|
||||||
|
pull; a judgement whose `input_key` did not change costs nothing. A vote
|
||||||
|
moves one agent's taste a little and queues neither.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -49,19 +49,22 @@ from dataclasses import replace
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app.jobs import embed, enrich, extract, judge, prep, pull, score, summarise # noqa: F401 -- registers the jobs
|
from app.jobs import ( # noqa: F401 -- registers the jobs
|
||||||
|
embed, extract, fetch_text, judge, prep, pull, score, summarise,
|
||||||
|
)
|
||||||
from desk.tools import agent
|
from desk.tools import agent
|
||||||
from pipeline import NULL, TASKS, Notice, RunContext, Tally, Task, declare, job
|
from pipeline import NULL, TASKS, Notice, RunContext, Tally, Task, declare, job
|
||||||
|
|
||||||
STEP = "app.jobs.cascade:step"
|
STEP = "app.jobs.cascade:step"
|
||||||
|
|
||||||
CASCADES: dict[str, tuple[str, ...]] = {
|
CASCADES: dict[str, tuple[str, ...]] = {
|
||||||
"pull": ("pull", "prep", "embed", "score", "enrich", "prep", "embed", "score", "extract",
|
"pull": ("pull", "prep", "embed", "score", "fetch_text", "prep", "embed", "score",
|
||||||
"score", "summarise", "judge"),
|
"extract", "score", "judge", "summarise"),
|
||||||
"enrich": ("enrich", "prep", "embed", "score", "judge"),
|
"fetch_text": ("fetch_text", "prep", "embed", "score", "extract", "score", "judge",
|
||||||
|
"summarise"),
|
||||||
}
|
}
|
||||||
|
|
||||||
#: What follows `enrich` for the roles it filled, passed over when it filled none.
|
#: What follows `fetch_text` for the roles it filled, passed over when it filled none.
|
||||||
REFILL = ("prep", "embed", "score")
|
REFILL = ("prep", "embed", "score")
|
||||||
|
|
||||||
|
|
||||||
@@ -131,7 +134,7 @@ STAGES: dict[str, Callable[[str], Task]] = {
|
|||||||
label="Mapping the roles' host words"),
|
label="Mapping the roles' host words"),
|
||||||
"summarise": _summarise,
|
"summarise": _summarise,
|
||||||
"judge": _judge,
|
"judge": _judge,
|
||||||
"enrich": lambda cascade: enrich.enrich_task(),
|
"fetch_text": lambda cascade: fetch_text.fetch_text_task(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +160,7 @@ def step(config: Any, store: Any, tally: Tally, payload: dict[str, Any], *,
|
|||||||
name, done = payload.get("cascade", ""), payload.get("task", "")
|
name, done = payload.get("cascade", ""), payload.get("task", "")
|
||||||
at = int(payload.get("at", -1))
|
at = int(payload.get("at", -1))
|
||||||
tasks = CASCADES.get(name, ())
|
tasks = CASCADES.get(name, ())
|
||||||
if done == "enrich" and not enrich.filled(tally) \
|
if done == "fetch_text" and not fetch_text.filled(tally) \
|
||||||
and tasks[at + 1:at + 1 + len(REFILL)] == REFILL:
|
and tasks[at + 1:at + 1 + len(REFILL)] == REFILL:
|
||||||
at += len(REFILL)
|
at += len(REFILL)
|
||||||
following = follows(name, at)
|
following = follows(name, at)
|
||||||
@@ -222,24 +225,25 @@ def run_pull(config: Any, store: Any, *, context: RunContext = NULL) -> dict[str
|
|||||||
return {"started": " > ".join(CASCADES["pull"]), "run": run}
|
return {"started": " > ".join(CASCADES["pull"]), "run": run}
|
||||||
|
|
||||||
|
|
||||||
@job("enrich", "Reading the best roles on their own pages", solo=True, resource="http")
|
@job("fetch_text", fetch_text.LABEL, solo=True, resource="http")
|
||||||
def run_enrich(config: Any, store: Any, *, context: RunContext = NULL) -> dict[str, Any]:
|
def run_fetch_text(config: Any, store: Any, *, context: RunContext = NULL) -> dict[str, Any]:
|
||||||
"""Ask for the enrich cascade, `enrich → prep → embed → score`. Its own work is
|
"""Ask for the fetch text cascade, the pull's chain from fetch text on.
|
||||||
nil, as the `pull` job's. Under `NULL` there is no queue to take it."""
|
Its own work is nil, as the `pull` job's. Under `NULL` there is no queue
|
||||||
if not context.task(chain("enrich")):
|
to take it."""
|
||||||
raise RuntimeError("no queue to start the enrich cascade on")
|
if not context.task(chain("fetch_text")):
|
||||||
return {"started": " > ".join(CASCADES["enrich"])}
|
raise RuntimeError("no queue to start the fetch text cascade on")
|
||||||
|
return {"started": " > ".join(CASCADES["fetch_text"])}
|
||||||
|
|
||||||
|
|
||||||
def enrich_after(queue: Any, score_job: Any) -> Any:
|
def fetch_text_after(queue: Any, score_job: Any) -> Any:
|
||||||
"""Queue the `enrich` job behind `score_job`, the rescore that follows a
|
"""Queue the `fetch_text` job behind `score_job`, the rescore that
|
||||||
change to the ranking, however that score ends. One per score job
|
follows a change to the ranking, however that score ends. One per score
|
||||||
(`enrich:after:<id>`), so ten changes answered by one score are one
|
job (`fetch_text:after:<id>`), so ten changes answered by one score are
|
||||||
enrich. None without a score job, or when the queue refuses."""
|
one cascade. None without a score job, or when the queue refuses."""
|
||||||
if score_job is None:
|
if score_job is None:
|
||||||
return None
|
return None
|
||||||
return queue.enqueue("enrich", depends_on=[score_job.id], after="done",
|
return queue.enqueue("fetch_text", depends_on=[score_job.id], after="done",
|
||||||
dedup_key=f"enrich:after:{score_job.id}")
|
dedup_key=f"fetch_text:after:{score_job.id}")
|
||||||
|
|
||||||
|
|
||||||
#: What `app job <name>` and `/api/jobs` start besides `pull`: one stage
|
#: What `app job <name>` and `/api/jobs` start besides `pull`: one stage
|
||||||
@@ -255,5 +259,5 @@ for _name in ("extract", "embed", "score", "summarise", "judge", "prep"):
|
|||||||
# setting: a cadence edited or switched off under Runs survives
|
# setting: a cadence edited or switched off under Runs survives
|
||||||
# every restart (see pipeline/schedule.py).
|
# every restart (see pipeline/schedule.py).
|
||||||
declare("pull", "pull", "every 6h",
|
declare("pull", "pull", "every 6h",
|
||||||
label="Pull every board, then map, embed, score, read the best roles' pages, "
|
label="Pull every board, then map, embed, score, fetch the text of the roles in the "
|
||||||
"extract, rescore, summarise and judge against the CVs")
|
"cut, extract, rescore, judge against the CVs and summarise")
|
||||||
+6
-7
@@ -12,13 +12,12 @@ is waiting while it is open, has not been given up on, has never been
|
|||||||
answered (`extracted_at IS NULL`), has no model level (`seniority_model`
|
answered (`extracted_at IS NULL`), has no model level (`seniority_model`
|
||||||
empty), was never asked where a remote hire may live (`remote_where_model`
|
empty), was never asked where a remote hire may live (`remote_where_model`
|
||||||
NULL) or for its languages and deadline (`languages_required` NULL), and is
|
NULL) or for its languages and deadline (`languages_required` NULL), and is
|
||||||
in the best of an enabled agent's
|
in the cut of an enabled agent (`scores.cut`, see `app.jobs.score`). That
|
||||||
ungated scores as deep and as low as that agent's own `limits` say
|
bound is what keeps the cost proportional to the agents rather than to the
|
||||||
(`extract_top`, `extract_min`). That bound is what keeps the cost
|
boards: the pull scores every role for free first, then reads the cut, and
|
||||||
proportional to the rankings rather than to the boards:
|
scores again so the fetch gate and the cut see what was filled; a role that
|
||||||
the pull scores every role for free first, then reads the few hundred that
|
enters the cut then is read on the next pull. A batch built for named uids
|
||||||
rank, and scores again so the gates see what was filled. A batch built for
|
finishes what it was dealt whatever their rank. The answer only
|
||||||
named uids finishes what it was dealt whatever their rank. The answer only
|
|
||||||
fills columns that are still empty: a board's structured field wins over what
|
fills columns that are still empty: a board's structured field wins over what
|
||||||
a model read out of the prose. The exception is the level, which the model
|
a model read out of the prose. The exception is the level, which the model
|
||||||
always gives (the board's word and the title's go in as hints) and which
|
always gives (the board's word and the title's go in as hints) and which
|
||||||
|
|||||||
@@ -1,32 +1,34 @@
|
|||||||
"""`enrich`: the best roles without text, read on their own pages.
|
"""`fetch_text`: the roles in the cut without text, read on their own pages.
|
||||||
|
|
||||||
Some hosts list a role without its text and state it on the role's own page
|
Some hosts list a role without its text and state it on the role's own page
|
||||||
only (`text="detail"`: Workday, SuccessFactors, Oracle, Phenom and the rest
|
only (`text="detail"`: Workday, SuccessFactors, Oracle, Phenom and the rest
|
||||||
with a `detail`, and a search provider such as Jobbank). The pull reads
|
with a `detail`, and a search provider such as Jobbank). The pull reads
|
||||||
listings only; this stage reads those pages after scoring, so the calls go
|
listings only; this stage reads those pages after scoring, for the roles the
|
||||||
where the ranking is. A saved search whose reader has `detail` is treated as
|
model pass will read, so each has its text first. A saved search whose
|
||||||
a board under its target `provider:name`: the same bar, budgets and state
|
reader has `detail` is treated as a board under its target `provider:name`:
|
||||||
keys, and its failing record is `search:failing:<target>`.
|
the same budgets and state keys, and its failing record is
|
||||||
|
`search:failing:<target>`. No model is asked.
|
||||||
|
|
||||||
1. `enrich_waiting` hands over the open roles without text that an enabled
|
1. `Store.fetch_text_waiting` hands over the open roles without text in the
|
||||||
agent with a prompt ranks ungated among its best `enrich.top` and at
|
cut of an enabled agent (`scores.cut`, see `app.jobs.score`), best first
|
||||||
`enrich.min_score` or above, best first by the highest such score. A role
|
by the highest final score. A role in no cut gets no call.
|
||||||
below that bar for every agent gets no call.
|
|
||||||
2. They are taken in that order, those whose read failed last, on boards and
|
2. They are taken in that order, those whose read failed last, on boards and
|
||||||
searches whose reader has `detail`, at most `enrich.per_board` from one
|
searches whose reader has `detail`, at most `fetch_text.per_board` from
|
||||||
board and `enrich.per_run` in all, leaving out the roles already read,
|
one board and `fetch_text.per_run` in all, leaving out the roles already
|
||||||
unless their read failed or gave no text `enrich.retry_days` ago
|
read, unless their read failed or gave no text `fetch_text.retry_days`
|
||||||
(`plugins.ats.detail_due`).
|
ago (`plugins.ats.detail_due`).
|
||||||
3. One batch per board or search, on the `http` pool, reads them
|
3. One batch per board or search, on the `http` pool, reads them
|
||||||
(`plugins.ats.read_board_details`, which keeps `ats:detailed:<target>`,
|
(`plugins.ats.read_board_details`, which keeps `ats:detailed:<target>`,
|
||||||
`ats:detailfailed:<target>` and `ats:detailempty:<target>`) and stores
|
`ats:detailfailed:<target>` and `ats:detailempty:<target>`) and stores
|
||||||
what each page filled. `Store.upsert_role` drops the vector of a role
|
what each page filled. `Store.upsert_role` drops the vector of a role
|
||||||
whose text improved, so the next `embed` encodes those roles only.
|
whose text improved, so the next `embed` encodes those roles only.
|
||||||
|
|
||||||
In the pull cascade `embed` and `score` follow; `cascade.step` passes over
|
In the pull cascade `prep`, `embed` and `score` follow, so the filled roles
|
||||||
both when no role was filled. The same stage follows a rescore after an agent
|
are embedded again and their levels and the cut recomputed; `cascade.step`
|
||||||
is saved or a company's affinity changes (`cascade.enrich_after`), never after
|
passes over the three when no role was filled. The same stage starts the
|
||||||
a vote. Whether it runs is `stages.stage_on(config, store, "enrich")`.
|
cascade that follows a rescore after an agent is saved or a company's
|
||||||
|
affinity or overrides change (`cascade.fetch_text_after`), never after a
|
||||||
|
vote. Whether it runs is `stages.stage_on(config, store, "fetch_text")`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -47,8 +49,8 @@ from pipeline import NULL, Batch, RunContext, Tally, Task, job
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
KIND = "enrich_batch"
|
KIND = "fetch_text_batch"
|
||||||
SETTLE = "app.jobs.enrich:settle"
|
SETTLE = "app.jobs.fetch_text:settle"
|
||||||
|
|
||||||
|
|
||||||
def _ats() -> Any:
|
def _ats() -> Any:
|
||||||
@@ -93,13 +95,14 @@ def _readable(store: Store) -> dict[int, Subscription]:
|
|||||||
|
|
||||||
def plan(config: Config, store: Store) -> list[tuple[str, list[str]]]:
|
def plan(config: Config, store: Store) -> list[tuple[str, list[str]]]:
|
||||||
"""`(target, uids)` per board or search, best first, within the budgets:
|
"""`(target, uids)` per board or search, best first, within the budgets:
|
||||||
the roles `enrich_waiting` ranks, on fetchable boards and searches whose
|
the roles `fetch_text_waiting` hands over, on fetchable boards and
|
||||||
reader has `detail` and that are not failing, and due for a read."""
|
searches whose reader has `detail` and that are not failing, and due for
|
||||||
settings = config.enrich
|
a read."""
|
||||||
|
settings = config.fetch_text
|
||||||
ats = _ats()
|
ats = _ats()
|
||||||
subs = _readable(store)
|
subs = _readable(store)
|
||||||
by_board: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
by_board: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
||||||
for found in store.enrich_waiting(settings.top, settings.min_score):
|
for found in store.fetch_text_waiting():
|
||||||
sub = subs.get(found["subscription_id"])
|
sub = subs.get(found["subscription_id"])
|
||||||
if sub is None or f"{sub.source}:failing:{sub.target}" in store.state:
|
if sub is None or f"{sub.source}:failing:{sub.target}" in store.state:
|
||||||
continue
|
continue
|
||||||
@@ -135,7 +138,7 @@ def plan(config: Config, store: Store) -> list[tuple[str, list[str]]]:
|
|||||||
def batches(config: Config, store: Store) -> list[Batch]:
|
def batches(config: Config, store: Store) -> list[Batch]:
|
||||||
"""The finder: one batch per board or search, nothing while the stage is
|
"""The finder: one batch per board or search, nothing while the stage is
|
||||||
off."""
|
off."""
|
||||||
if not stages.stage_on(config, store, "enrich"):
|
if not stages.stage_on(config, store, "fetch_text"):
|
||||||
return []
|
return []
|
||||||
return [Batch({"target": target, "uids": uids},
|
return [Batch({"target": target, "uids": uids},
|
||||||
label=f"Reading {len(uids)} roles on {target}")
|
label=f"Reading {len(uids)} roles on {target}")
|
||||||
@@ -153,12 +156,12 @@ def run_batch(config: Config, store: Store, *, target: str, uids: list[str],
|
|||||||
if not subs or not uids:
|
if not subs or not uids:
|
||||||
return {"target": target, "filled": 0, "texts": 0}
|
return {"target": target, "filled": 0, "texts": 0}
|
||||||
sub = subs[0]
|
sub = subs[0]
|
||||||
found = {f["uid"]: f for f in store.enrich_waiting(0, 0.0, uids)}
|
found = {f["uid"]: f for f in store.fetch_text_waiting(uids)}
|
||||||
rows = [_row(found[uid], sub) for uid in uids if uid in found]
|
rows = [_row(found[uid], sub) for uid in uids if uid in found]
|
||||||
context.check()
|
context.check()
|
||||||
with httpx.Client() as client:
|
with httpx.Client() as client:
|
||||||
filled = ats.read_board_details(store.state, target, rows, client=client,
|
filled = ats.read_board_details(store.state, target, rows, client=client,
|
||||||
cap=len(rows), retry_days=config.enrich.retry_days)
|
cap=len(rows), retry_days=config.fetch_text.retry_days)
|
||||||
label = sub.company or sub.label
|
label = sub.company or sub.label
|
||||||
texts = 0
|
texts = 0
|
||||||
for row in filled:
|
for row in filled:
|
||||||
@@ -166,7 +169,7 @@ def run_batch(config: Config, store: Store, *, target: str, uids: list[str],
|
|||||||
item.source = sub.source
|
item.source = sub.source
|
||||||
store.upsert_role(item, sub)
|
store.upsert_role(item, sub)
|
||||||
texts += bool(row.get("description"))
|
texts += bool(row.get("description"))
|
||||||
log.info("enrich: %s: %d read, %d filled, %d with text", target, len(rows), len(filled),
|
log.info("fetch_text: %s: %d read, %d filled, %d with text", target, len(rows), len(filled),
|
||||||
texts)
|
texts)
|
||||||
return {"target": target, "read": len(rows), "filled": len(filled), "texts": texts}
|
return {"target": target, "read": len(rows), "filled": len(filled), "texts": texts}
|
||||||
|
|
||||||
@@ -183,6 +186,9 @@ def settle(config: Config, store: Store, tally: Tally, *,
|
|||||||
"texts": sum(int(result.get("texts") or 0) for result in tally.results)}
|
"texts": sum(int(result.get("texts") or 0) for result in tally.results)}
|
||||||
|
|
||||||
|
|
||||||
def enrich_task() -> Task:
|
#: What the task and the cascade's job are called on the Runs page.
|
||||||
return Task(kind=KIND, finder=batches, name="enrich", settle=SETTLE,
|
LABEL = "Fetching the text of the roles in the cut"
|
||||||
label="Reading the best roles on their own pages")
|
|
||||||
|
|
||||||
|
def fetch_text_task() -> Task:
|
||||||
|
return Task(kind=KIND, finder=batches, name="fetch_text", settle=SETTLE, label=LABEL)
|
||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
"""`judge`: each of an agent's best roles read against its CV, as three numbers.
|
"""`judge`: each role in an agent's cut read against its CV, as three numbers.
|
||||||
|
|
||||||
A `ModelTask` beside `summarise`, after the `/rank` of
|
A `ModelTask` beside `summarise`, after the `/rank` of
|
||||||
github.com/MadsLorentzen/ai-job-search: the model reads a posting against a
|
github.com/MadsLorentzen/ai-job-search: the model reads a posting against a
|
||||||
@@ -10,14 +10,15 @@ CV match sorts by. The model also reports a verdict on each of the
|
|||||||
agent's must-haves (one per line of its must text, numbered M1..Mn in the
|
agent's must-haves (one per line of its must text, numbered M1..Mn in the
|
||||||
prompt); it does not apply them. The rule is code's: a "broken" one makes
|
prompt); it does not apply them. The rule is code's: a "broken" one makes
|
||||||
career count as at most `app.models.BROKEN_CAP`, when the role is served. Culture and location are left out: the first
|
career count as at most `app.models.BROKEN_CAP`, when the role is served. Culture and location are left out: the first
|
||||||
is guessed from ad text, the second is what the gates do.
|
is guessed from ad text, the second is what the fetch gate does.
|
||||||
|
|
||||||
The work is pairs, `(agent, role)`: an enabled agent with a CV, and a role
|
The work is pairs, `(agent, role)`: an enabled agent with a CV and a prompt,
|
||||||
among its best ungated scores as deep and as low as its own `limits` say
|
and an open role in its cut (`scores.cut`, see `app.jobs.score`: the best by
|
||||||
(`judge_top`, `judge_min`), or among the `judge_cv_top` ungated roles closest
|
fit, the best by CV closeness that those leave out, and the liked and saved)
|
||||||
to its CV (`scores.cv_fit`) that those leave out, with some text, that has
|
with some text, that has no judgement yet, or one read from another CV,
|
||||||
no judgement yet, or one read from another CV, prompts, like, avoid or must
|
prompts, like, avoid or must text or role text than today's (`input_key`).
|
||||||
text or role text than today's (`input_key`). A pair is named by the composite key `"<agent_id>:<uid>"`,
|
The cut is the only selection: the pull judges it after extract and the
|
||||||
|
rescore that follows, so it reads the cut as recomputed. A pair is named by the composite key `"<agent_id>:<uid>"`,
|
||||||
which is what `desk.modeltask` hands round as a uid, so `desk/` is untouched.
|
which is what `desk.modeltask` hands round as a uid, so `desk/` is untouched.
|
||||||
A batch holds one agent's pairs, since the profile is in the system prompt;
|
A batch holds one agent's pairs, since the profile is in the system prompt;
|
||||||
the finder cuts per agent (`_finder`) and the job runs one call per agent it
|
the finder cuts per agent (`_finder`) and the job runs one call per agent it
|
||||||
@@ -186,8 +187,7 @@ def input_key(agent: Agent, text: str) -> str:
|
|||||||
|
|
||||||
def _judged(agent: Agent) -> bool:
|
def _judged(agent: Agent) -> bool:
|
||||||
"""Whether `judge` reads for this agent at all: enabled, with a CV and a
|
"""Whether `judge` reads for this agent at all: enabled, with a CV and a
|
||||||
prompt with text (without one its scores have no fit, so its best roles
|
prompt with text (without one nothing of its cut is in by fit)."""
|
||||||
are its newest)."""
|
|
||||||
return agent.enabled and bool(agent.cv_text.strip()) \
|
return agent.enabled and bool(agent.cv_text.strip()) \
|
||||||
and any(p.text.strip() for p in agent.prompts)
|
and any(p.text.strip() for p in agent.prompts)
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ def _judged(agent: Agent) -> bool:
|
|||||||
def waiting(store: Store, keys: Sequence[str] | None = None,
|
def waiting(store: Store, keys: Sequence[str] | None = None,
|
||||||
limit: int | None = None) -> list[tuple[Agent, Any, str, str]]:
|
limit: int | None = None) -> list[tuple[Agent, Any, str, str]]:
|
||||||
"""The pairs `judge` has yet to read, as `(agent, row, text, input_key)`,
|
"""The pairs `judge` has yet to read, as `(agent, row, text, input_key)`,
|
||||||
each agent's best first (`Store.judge_rows`). Given `keys`, only those
|
each agent's cut in its order (`Store.judge_rows`). Given `keys`, only those
|
||||||
of them still waiting, whatever their rank."""
|
of them still waiting, whatever their rank."""
|
||||||
wanted: dict[int, list[str]] | None = None
|
wanted: dict[int, list[str]] | None = None
|
||||||
if keys is not None:
|
if keys is not None:
|
||||||
|
|||||||
+1
-1
@@ -135,7 +135,7 @@ def _detail_target(role: Role) -> str:
|
|||||||
|
|
||||||
def _detail_text(role: Role, target: str) -> str:
|
def _detail_text(role: Role, target: str) -> str:
|
||||||
"""The text of a search role, read by its reader's `detail` on the ad's
|
"""The text of a search role, read by its reader's `detail` on the ad's
|
||||||
own page as the pull's enrich stage reads it. Raises `Unreadable` when
|
own page as the pull's fetch text stage reads it. Raises `Unreadable` when
|
||||||
the read fails or the page states no text."""
|
the read fails or the page states no text."""
|
||||||
from plugins import ats
|
from plugins import ats
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
In the pull cascade it follows the pull, whose settle has closed what is
|
In the pull cascade it follows the pull, whose settle has closed what is
|
||||||
gone, and maps every role the pull changed, then folds the copies across
|
gone, and maps every role the pull changed, then folds the copies across
|
||||||
the whole database (`Store.rebuild_dupes`, which the pull's settle used to
|
the whole database (`Store.rebuild_dupes`, which the pull's settle used to
|
||||||
run). After `enrich` it maps the roles their own pages filled, since only
|
run). After `fetch_text` it maps the roles their own pages filled, since only
|
||||||
those are due. `solo`, so two cascades never write the same rows at once.
|
those are due. `solo`, so two cascades never write the same rows at once.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
+132
-67
@@ -1,21 +1,29 @@
|
|||||||
"""`score`: every open role, scored for every enabled search agent.
|
"""`score`: every open role, scored for every enabled search agent, and each
|
||||||
|
agent's cut.
|
||||||
|
|
||||||
A role is scored per agent, `(uid, agent) -> score`, because a role is only
|
A role is scored per agent, `(uid, agent) -> score`, because a role is only
|
||||||
good for a given search. For each agent:
|
good for a given search. Each agent first applies its fetch gate:
|
||||||
|
|
||||||
require gates a role that fails one keeps its row, with score 0 and the
|
require gates a role that fails one keeps its row, with score 0 and the
|
||||||
reason ("remote not remote")
|
reason ("remote not remote"); the region, which nothing
|
||||||
any gates one group: a role that matches none of them, and has the
|
lifts
|
||||||
column filled for at least one, is gated ("none of
|
any gates one group, the place part: a role that matches none of
|
||||||
country DK / remote remote")
|
them, and has the column filled for at least one, is
|
||||||
prefer gates `weight` when the role matches, 0 when it does not
|
gated ("none of country DK / remote remote"); skipped for
|
||||||
|
a company set to All countries
|
||||||
exclude gates a role that matches one of the values keeps its row, with
|
exclude gates a role that matches one of the values keeps its row, with
|
||||||
score 0 and the value ("title account executive")
|
score 0 and the value ("title account executive"); those
|
||||||
|
on `title` are skipped for a company set to All roles
|
||||||
|
|
||||||
A gate rejects on evidence, never on absence: a role whose column is empty
|
A gate rejects on evidence, never on absence: a role whose column is empty
|
||||||
is not gated by it. `extract` is what fills an empty column, and it reads
|
is not gated by it. `extract` is what fills an empty column, and it reads
|
||||||
only the roles that rank, so gating on an empty column would keep those
|
only the roles in the cut, so gating on an empty column would keep those
|
||||||
roles out of extract's reach for good.
|
roles out of extract's reach for good. A hidden company (`affinity = -1`)
|
||||||
|
is not scored at all; a favourite passes the gate like any other company.
|
||||||
|
|
||||||
|
The final score, the feed's order, is the weighted sum of four terms over
|
||||||
|
the sum of the weights, so it stays 0..1:
|
||||||
|
|
||||||
fit cos(role vector, prompt vector) as a level: the embedding
|
fit cos(role vector, prompt vector) as a level: the embedding
|
||||||
model's calibrated `lo` is 0 and `hi` 1, clipped outside
|
model's calibrated `lo` is 0 and `hi` 1, clipped outside
|
||||||
(see `scale`), so a role's fit does not depend on what
|
(see `scale`), so a role's fit does not depend on what
|
||||||
@@ -29,25 +37,29 @@ roles out of extract's reach for good.
|
|||||||
over this agent's votes; with only likes it is the liked mean,
|
over this agent's votes; with only likes it is the liked mean,
|
||||||
with only passes the negated passed mean; no votes, no term
|
with only passes the negated passed mean; no votes, no term
|
||||||
|
|
||||||
Beside the score, for an agent with a CV, `cv_fit`: how close the role is to
|
A role with no vector is scored without `fit` and `taste`, unless `fit` is
|
||||||
the CV, the best cosine between the role and the CV's chunks
|
all there is, when it is gated as "no vector". An agent with no votes scores
|
||||||
(`embed.cv_chunks`, embedded as the prompts are), scaled like fit. It is no
|
every role without `taste`; the direction is newsdesk's
|
||||||
term of the score; the judge reads the closest roles the score leaves out
|
`centroid(liked) - centroid(disliked)`. An agent with no prompt that has
|
||||||
(`Store.judge_rows`) and CV match orders the roles not judged yet by it.
|
text has no `fit` either, so nothing of it enters the cut by fit and its
|
||||||
|
scores do not decide what summarise reads (`Store._summarise_top`); a run
|
||||||
|
names such agents in one notice.
|
||||||
|
|
||||||
Every term is 0..1. The score is the weighted sum over the sum of the weights
|
Beside the score, `fit` is stored as it is, and for an agent with a CV,
|
||||||
(the agent's four and its prefer gates'), so it stays 0..1. A favourite
|
`cv_fit`: how close the role is to the CV, the best cosine between the role
|
||||||
company (`affinity = 2`) skips the `any` group but not the `require` or
|
and the CV's chunks (`embed.cv_chunks`, embedded as the prompts are), scaled
|
||||||
`exclude` gates, and
|
like fit. Neither carries the affinity term.
|
||||||
is scored like any other company with its affinity term at 1: nothing puts
|
|
||||||
its roles above a better fit. A hidden one (`-1`) is not scored at all. A
|
The cut is the roles that get fetch text, extract and judge (`cut_of`). It
|
||||||
role with no vector is scored without `fit` and `taste`, unless `fit` is all
|
is computed from two levels, each with the company's affinity as a bonus of
|
||||||
there is, when it is gated as "no vector".
|
`w.affinity * affinity / 3` over the sum of the weights, the same size as in
|
||||||
An agent with no votes scores every role without `taste`; the direction is
|
the final score (a liked company about 0.05 above neutral, a favourite about
|
||||||
newsdesk's `centroid(liked) - centroid(disliked)`. An agent with no prompt
|
0.1): the fit level `fit + bonus` and the CV level `cv_fit + bonus`. Over
|
||||||
that has text has no `fit` either: its scores are not a match, so it is left
|
the roles that pass the fetch gate, the best `cut_fit_top` by fit level at
|
||||||
out of what extract and summarise read (`Store._top_scope`), and a run names
|
or above `cut_fit_min` are `fit`; the best `cut_cv_top` by CV level at or
|
||||||
such agents in one notice.
|
above `cut_cv_min` that are not in yet are `cv`; every role this agent
|
||||||
|
liked or anybody saved that is not in yet is `kept`. Newness and taste are
|
||||||
|
no part of it, and the two lists are not merged into one number.
|
||||||
|
|
||||||
Recomputed in full on every run, and each agent's rows are replaced in one
|
Recomputed in full on every run, and each agent's rows are replaced in one
|
||||||
transaction: nothing is incremental, so nothing can drift.
|
transaction: nothing is incremental, so nothing can drift.
|
||||||
@@ -67,7 +79,7 @@ import numpy as np
|
|||||||
from pipeline import NULL, Notice, RunContext, job
|
from pipeline import NULL, Notice, RunContext, job
|
||||||
from app.config import Calibration, Config
|
from app.config import Calibration, Config
|
||||||
from app.jobs import embed
|
from app.jobs import embed
|
||||||
from app.models import Agent, Candidate, Gate, Weights
|
from app.models import Agent, Candidate, Gate, Limits, Weights
|
||||||
from app.storage import Store
|
from app.storage import Store
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -130,10 +142,10 @@ def scale(cosines: dict[str, float],
|
|||||||
embedding model's calibrated `band` (`app.config.CALIBRATION`).
|
embedding model's calibrated `band` (`app.config.CALIBRATION`).
|
||||||
|
|
||||||
Raw cosines on multilingual-e5-small sit between about 0.75 and 0.87 for
|
Raw cosines on multilingual-e5-small sit between about 0.75 and 0.87 for
|
||||||
real postings against a real intent, so unscaled a prefer gate weighted
|
real postings against a real intent, so unscaled the whole spread of fit
|
||||||
0.2 moved a score more than the whole spread of fit. The band stretches
|
was smaller than a recency step. The band stretches that spread to 0..1
|
||||||
that spread to 0..1 with fixed constants, so a role's level is the same
|
with fixed constants, so a role's level is the same in every run and a
|
||||||
in every run and a `limits` bar is an absolute threshold.
|
minimum of the cut is an absolute threshold.
|
||||||
|
|
||||||
Without a band, for a model nobody calibrated, it falls back to min-max
|
Without a band, for a model nobody calibrated, it falls back to min-max
|
||||||
across the run: the closest role is 1 and the farthest 0, which ranks
|
across the run: the closest role is 1 and the farthest 0, which ranks
|
||||||
@@ -165,19 +177,20 @@ def _reason(gate: Gate) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
|
def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
|
||||||
"""Why this role is gated, as reasons: every require gate it fails, every
|
"""Why the fetch gate rejects this role, as reasons: every require gate
|
||||||
exclude gate it matches, and the `any` group when it matches none of them.
|
it fails, every exclude gate it matches, and the `any` group when it
|
||||||
A gate with an empty column (state -1) neither passes nor fails, so the
|
matches none of them. A gate with an empty column (state -1) neither
|
||||||
group fails only when some member had evidence. A favourite company's
|
passes nor fails, so the group fails only when some member had evidence.
|
||||||
roles skip the `any` group but not the require and exclude gates, so a
|
A company set to All countries skips the `any` group, the place part,
|
||||||
star widens a search to a company's roles within e.g. Europe, not to the
|
and one set to All roles the exclude gates on `title`, the titles to
|
||||||
whole world, and not to the titles the agent leaves out."""
|
leave out; the require gates, the region, apply to every company."""
|
||||||
states = list(zip(gates, candidate.gates, strict=True))
|
states = list(zip(gates, candidate.gates, strict=True))
|
||||||
reasons = [_reason(g) for g, state in states if g.mode == "require" and state == 0]
|
reasons = [_reason(g) for g, state in states if g.mode == "require" and state == 0]
|
||||||
reasons += [f"{g.field} {g.values[state - 1]}" for g, state in states
|
reasons += [f"{g.field} {g.values[state - 1]}" for g, state in states
|
||||||
if g.mode == "exclude" and state > 0]
|
if g.mode == "exclude" and state > 0
|
||||||
|
and not (candidate.all_roles and g.field == "title")]
|
||||||
group = [(g, state) for g, state in states if g.mode == "any"]
|
group = [(g, state) for g, state in states if g.mode == "any"]
|
||||||
if candidate.affinity != 2 and group and not any(state == 1 for _, state in group) \
|
if not candidate.all_countries and group and not any(state == 1 for _, state in group) \
|
||||||
and any(state == 0 for _, state in group):
|
and any(state == 0 for _, state in group):
|
||||||
reasons.append("none of " + ", ".join(_wanted(g) for g, _ in group))
|
reasons.append("none of " + ", ".join(_wanted(g) for g, _ in group))
|
||||||
return reasons
|
return reasons
|
||||||
@@ -186,17 +199,15 @@ def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
|
|||||||
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
||||||
fit: float | None, now: datetime, *, taste: float | None = None,
|
fit: float | None, now: datetime, *, taste: float | None = None,
|
||||||
missing: str = "no vector") -> tuple[float, str]:
|
missing: str = "no vector") -> tuple[float, str]:
|
||||||
"""One role for one agent: `(score, gated_reason)`. `fit` and `taste` are
|
"""One role for one agent: `(final score, gated_reason)`. `fit` and
|
||||||
already scaled to 0..1 (see `scale`), or None when there is nothing to
|
`taste` are already scaled to 0..1 (see `scale`), or None when there is
|
||||||
measure: no role vector, no prompt vector, no votes. A None term leaves
|
nothing to measure: no role vector, no prompt vector, no votes. A None
|
||||||
the denominator; `missing` says why fit is out."""
|
term leaves the denominator; `missing` says why fit is out."""
|
||||||
if failed := failed_gates(candidate, gates):
|
if failed := failed_gates(candidate, gates):
|
||||||
return 0.0, ", ".join(failed)
|
return 0.0, ", ".join(failed)
|
||||||
|
|
||||||
terms = [(weights.recency, recency(candidate.posted_at, now)),
|
terms = [(weights.recency, recency(candidate.posted_at, now)),
|
||||||
(weights.affinity, affinity_term(candidate.affinity))]
|
(weights.affinity, affinity_term(candidate.affinity))]
|
||||||
terms += [(g.weight, 1.0 if state == 1 else 0.0)
|
|
||||||
for g, state in zip(gates, candidate.gates, strict=True) if g.mode == "prefer"]
|
|
||||||
if fit is not None:
|
if fit is not None:
|
||||||
terms.append((weights.fit, fit))
|
terms.append((weights.fit, fit))
|
||||||
if taste is not None:
|
if taste is not None:
|
||||||
@@ -208,6 +219,44 @@ def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
|||||||
return sum(w * t for w, t in terms) / total, ""
|
return sum(w * t for w, t in terms) / total, ""
|
||||||
|
|
||||||
|
|
||||||
|
def bonus(affinity: int, weights: Weights) -> float:
|
||||||
|
"""What a company's affinity adds to both levels of the cut: the share
|
||||||
|
the affinity term gives it in the final score above a company at -1, so
|
||||||
|
a liked company sits about 0.05 above a neutral one and a favourite
|
||||||
|
about 0.1 on the default weights. 0 when every weight is 0."""
|
||||||
|
total = weights.fit + weights.recency + weights.affinity + weights.taste
|
||||||
|
return weights.affinity * affinity / 3 / total if total else 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def cut_of(candidates: Sequence[Candidate], passed: set[str], fits: dict[str, float],
|
||||||
|
near: dict[str, float], kept: set[str], weights: Weights,
|
||||||
|
limits: Limits) -> dict[str, str]:
|
||||||
|
"""`uid -> why` for the roles in the cut, among `candidates` whose uid
|
||||||
|
is in `passed` (the fetch gate let them through): `fit` for the best
|
||||||
|
`limits.cut_fit_top` by fit level at or above `cut_fit_min`, `cv` for
|
||||||
|
the best `cut_cv_top` by CV level at or above `cut_cv_min` not in yet,
|
||||||
|
and `kept` for those in `kept` (liked or saved) not in yet. A level is
|
||||||
|
`fits` or `near` plus the company's `bonus`; a role without one is in
|
||||||
|
no list by it. Ties go to the newer role, then the lower uid."""
|
||||||
|
by_uid = {c.uid: c for c in candidates if c.uid in passed}
|
||||||
|
# Newest first, then uid, as the sort below keeps equal levels in order.
|
||||||
|
ordered = sorted(sorted(by_uid.values(), key=lambda c: c.uid),
|
||||||
|
key=lambda c: c.posted_at, reverse=True)
|
||||||
|
cut: dict[str, str] = {}
|
||||||
|
for why, levels, top, floor in (("fit", fits, limits.cut_fit_top, limits.cut_fit_min),
|
||||||
|
("cv", near, limits.cut_cv_top, limits.cut_cv_min)):
|
||||||
|
scored = [(levels[c.uid] + bonus(c.affinity, weights), c.uid) for c in ordered
|
||||||
|
if c.uid in levels and c.uid not in cut]
|
||||||
|
scored = [(level, uid) for level, uid in scored if level >= floor]
|
||||||
|
scored.sort(key=lambda pair: pair[0], reverse=True)
|
||||||
|
for _, uid in scored[:top]:
|
||||||
|
cut[uid] = why
|
||||||
|
for c in ordered:
|
||||||
|
if c.uid in kept and c.uid not in cut:
|
||||||
|
cut[c.uid] = "kept"
|
||||||
|
return cut
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------ vectors
|
# ------------------------------------------------------------------ vectors
|
||||||
|
|
||||||
def intent_key(model: str, intent: str) -> str:
|
def intent_key(model: str, intent: str) -> str:
|
||||||
@@ -301,12 +350,13 @@ def _cv(store: Store, agent: Agent, model: str, encoder: _Encoder) -> np.ndarray
|
|||||||
|
|
||||||
def no_intent(names: Sequence[str]) -> Notice:
|
def no_intent(names: Sequence[str]) -> Notice:
|
||||||
"""The notice for enabled agents without a prompt that has text: their
|
"""The notice for enabled agents without a prompt that has text: their
|
||||||
scores have no fit, so `Store._top_scope` keeps them from feeding extract
|
scores have no fit, so nothing of theirs enters the cut by fit and
|
||||||
and summarise. The code keeps its name from when an agent had one intent."""
|
their final scores do not choose what summarise reads. The code keeps
|
||||||
|
its name from when an agent had one intent."""
|
||||||
return Notice(
|
return Notice(
|
||||||
code="score.no_intent", level="warning", kind="expected", key="score",
|
code="score.no_intent", level="warning", kind="expected", key="score",
|
||||||
text=f"No prompt with text, so ranked without fit and not read by extract "
|
text=f"No prompt with text, so ranked without fit and nothing in the cut by fit: "
|
||||||
f"or summarise: {', '.join(names)}.",
|
f"{', '.join(names)}.",
|
||||||
fix="Give the agent a prompt under Settings, Search agents.",
|
fix="Give the agent a prompt under Settings, Search agents.",
|
||||||
where="app.jobs.score")
|
where="app.jobs.score")
|
||||||
|
|
||||||
@@ -314,7 +364,8 @@ def no_intent(names: Sequence[str]) -> Notice:
|
|||||||
def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||||
prompts: Sequence[tuple[str, np.ndarray]], now: datetime,
|
prompts: Sequence[tuple[str, np.ndarray]], now: datetime,
|
||||||
calibration: Calibration | None = None,
|
calibration: Calibration | None = None,
|
||||||
cv: np.ndarray | None = None) -> dict[str, int]:
|
cv: np.ndarray | None = None,
|
||||||
|
saved: set[str] | None = None) -> dict[str, int]:
|
||||||
"""Two passes: the cosines of the roles this agent scores, to each of its
|
"""Two passes: the cosines of the roles this agent scores, to each of its
|
||||||
`prompts` and to its taste direction, then every score with both scaled
|
`prompts` and to its taste direction, then every score with both scaled
|
||||||
by the model's `calibration`, or across the run without one. A role's fit
|
by the model's `calibration`, or across the run without one. A role's fit
|
||||||
@@ -327,9 +378,12 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
|||||||
share. The voted roles are scored like any other; a liked one sits near
|
share. The voted roles are scored like any other; a liked one sits near
|
||||||
the direction it helped make, which is what a like should do. With `cv`
|
the direction it helped make, which is what a like should do. With `cv`
|
||||||
(`_cv`), each of those roles also gets its `cv_fit`, its `closeness` to
|
(`_cv`), each of those roles also gets its `cv_fit`, its `closeness` to
|
||||||
the CV scaled like fit, beside the score and not in it."""
|
the CV scaled like fit. Then the cut (`cut_of`), with this agent's likes
|
||||||
|
and the `saved` roles (`Store.saved_uids`, read here when not given)
|
||||||
|
kept."""
|
||||||
candidates = store.score_candidates(agent.id, agent.gates)
|
candidates = store.score_candidates(agent.id, agent.gates)
|
||||||
direction = taste_direction(vectors, store.votes(agent.id))
|
votes = store.votes(agent.id)
|
||||||
|
direction = taste_direction(vectors, votes)
|
||||||
cosines: dict[str, dict[str, float]] = {name: {} for name, _ in prompts}
|
cosines: dict[str, dict[str, float]] = {name: {} for name, _ in prompts}
|
||||||
tastes: dict[str, float] = {}
|
tastes: dict[str, float] = {}
|
||||||
near: dict[str, float] = {}
|
near: dict[str, float] = {}
|
||||||
@@ -351,22 +405,29 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
|||||||
fits[uid], best[uid] = value, name
|
fits[uid], best[uid] = value, name
|
||||||
tastes = scale(tastes, calibration.taste if calibration else None)
|
tastes = scale(tastes, calibration.taste if calibration else None)
|
||||||
near = scale(near, calibration.cv_band if calibration else None)
|
near = scale(near, calibration.cv_band if calibration else None)
|
||||||
rows: list[tuple[str, float, str, str, float | None]] = []
|
scored: list[tuple[str, float, str, float | None]] = []
|
||||||
gated = 0
|
passed: set[str] = set()
|
||||||
for candidate in candidates:
|
for candidate in candidates:
|
||||||
fit = fits.get(candidate.uid)
|
fit = fits.get(candidate.uid)
|
||||||
value, reason = score_one(
|
value, reason = score_one(
|
||||||
candidate, agent.gates, agent.weights, fit, now,
|
candidate, agent.gates, agent.weights, fit, now,
|
||||||
taste=tastes.get(candidate.uid),
|
taste=tastes.get(candidate.uid),
|
||||||
missing="no vector" if prompts else "no prompt vector")
|
missing="no vector" if prompts else "no prompt vector")
|
||||||
gated += bool(reason)
|
if not reason:
|
||||||
|
passed.add(candidate.uid)
|
||||||
|
scored.append((candidate.uid, value, reason, fit))
|
||||||
|
kept = {uid for uid, vote in votes.items() if vote == 1}
|
||||||
|
kept |= store.saved_uids() if saved is None else saved
|
||||||
|
cut = cut_of(candidates, passed, fits, near, kept, agent.weights, agent.limits)
|
||||||
|
rows = []
|
||||||
|
for uid, value, reason, fit in scored:
|
||||||
counted = fit is not None and agent.weights.fit and not reason
|
counted = fit is not None and agent.weights.fit and not reason
|
||||||
cv_fit = near.get(candidate.uid)
|
cv_fit = near.get(uid)
|
||||||
rows.append((candidate.uid, round(value, 6), reason,
|
rows.append((uid, round(value, 6), reason, best[uid] if counted else "",
|
||||||
best[candidate.uid] if counted else "",
|
None if cv_fit is None else round(cv_fit, 6),
|
||||||
None if cv_fit is None else round(cv_fit, 6)))
|
None if fit is None else round(fit, 6), cut.get(uid, "")))
|
||||||
store.replace_scores(agent.id, rows)
|
store.replace_scores(agent.id, rows)
|
||||||
return {"scored": len(rows), "gated": gated}
|
return {"scored": len(rows), "gated": len(rows) - len(passed), "cut": len(cut)}
|
||||||
|
|
||||||
|
|
||||||
@job("score", "Scoring roles for every agent", solo=True, resource="cpu")
|
@job("score", "Scoring roles for every agent", solo=True, resource="cpu")
|
||||||
@@ -386,17 +447,21 @@ def run_score(config: Config, store: Store, *,
|
|||||||
if blind := [agent.name for agent in agents
|
if blind := [agent.name for agent in agents
|
||||||
if not any(p.text.strip() for p in agent.prompts)]:
|
if not any(p.text.strip() for p in agent.prompts)]:
|
||||||
context.notice(no_intent(blind))
|
context.notice(no_intent(blind))
|
||||||
scored = gated = 0
|
scored = gated = cut = 0
|
||||||
|
saved = store.saved_uids()
|
||||||
for n, agent in enumerate(agents):
|
for n, agent in enumerate(agents):
|
||||||
context.check()
|
context.check()
|
||||||
context.progress(n, len(agents), f"scoring for {agent.name}, {n + 1} of {len(agents)}")
|
context.progress(n, len(agents), f"scoring for {agent.name}, {n + 1} of {len(agents)}")
|
||||||
counts = score_agent(store, agent, vectors, _prompts(store, agent, model, encoder),
|
counts = score_agent(store, agent, vectors, _prompts(store, agent, model, encoder),
|
||||||
now, calibration, cv=_cv(store, agent, model, encoder))
|
now, calibration, cv=_cv(store, agent, model, encoder),
|
||||||
|
saved=saved)
|
||||||
scored += counts["scored"]
|
scored += counts["scored"]
|
||||||
gated += counts["gated"]
|
gated += counts["gated"]
|
||||||
log.info("%-20s %6d scored, %6d gated", agent.name, counts["scored"], counts["gated"])
|
cut += counts["cut"]
|
||||||
|
log.info("%-20s %6d scored, %6d gated, %5d in the cut", agent.name, counts["scored"],
|
||||||
|
counts["gated"], counts["cut"])
|
||||||
context.progress(len(agents), len(agents), "")
|
context.progress(len(agents), len(agents), "")
|
||||||
return {"agents": len(agents), "scored": scored, "gated": gated,
|
return {"agents": len(agents), "scored": scored, "gated": gated, "cut": cut,
|
||||||
"vectors": len(vectors)}
|
"vectors": len(vectors)}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -1,5 +1,5 @@
|
|||||||
"""Whether the three model stages of a pull, `extract`, `summarise` and
|
"""Whether the three model stages of a pull, `extract`, `summarise` and
|
||||||
`judge`, and the `enrich` stage run.
|
`judge`, and the `fetch_text` stage run.
|
||||||
|
|
||||||
`extract.enabled`, `summarise.enabled` and `judge.enabled` in config.yaml are
|
`extract.enabled`, `summarise.enabled` and `judge.enabled` in config.yaml are
|
||||||
read at startup and say nothing on the page, so the switch lives in the
|
read at startup and say nothing on the page, so the switch lives in the
|
||||||
@@ -10,16 +10,17 @@ deployment that never uses the switch behaves as it did. `stage_on` is the
|
|||||||
one place that decides, and the tasks' finders ask it
|
one place that decides, and the tasks' finders ask it
|
||||||
(`extract.extract_task`, `summarise.summarise_task`, `judge.judge_task`).
|
(`extract.extract_task`, `summarise.summarise_task`, `judge.judge_task`).
|
||||||
|
|
||||||
`enrich` (reading the best roles on their own pages, `app/jobs/enrich.py`)
|
`fetch_text` (reading the role's own page for the roles in the cut,
|
||||||
asks no model and is on by default (`enrich.enabled`); its switch is
|
`app/jobs/fetch_text.py`) asks no model and is on by default
|
||||||
`stage:enrich`, set the same way as the others: by the Runs page
|
(`fetch_text.enabled`); its switch is `stage:fetch_text`, set the same way
|
||||||
(`PUT /api/stages/enrich`) and by `app stages enrich on|off`.
|
as the others: by the Runs page (`PUT /api/stages/fetch_text`) and by
|
||||||
|
`app stages fetch_text on|off`.
|
||||||
|
|
||||||
`describe` is what `GET /api/stages` and `app stages` show: for each stage
|
`describe` is what `GET /api/stages` and `app stages` show: for each stage
|
||||||
with a switch, the model stages and `enrich`, whether it is on, where that comes from, the model it uses, and who
|
with a switch, the model stages and `fetch_text`, whether it is on, where
|
||||||
would answer. The model is the one a call is made with: `agent.model` when
|
that comes from, the model it uses, and who would answer. The model is the
|
||||||
set, since it overrides the per-task model everywhere (`desk/modeltask.py`),
|
one a call is made with: `agent.model` when set, since it overrides the
|
||||||
else the stage's own.
|
per-task model everywhere (`desk/modeltask.py`), else the stage's own.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -34,8 +35,8 @@ from desk.tools import agent
|
|||||||
|
|
||||||
NAMES = ("extract", "summarise", "judge")
|
NAMES = ("extract", "summarise", "judge")
|
||||||
|
|
||||||
#: Every stage with a switch: the model stages and `enrich`.
|
#: Every stage with a switch: the model stages and `fetch_text`.
|
||||||
SWITCHES = (*NAMES, "enrich")
|
SWITCHES = (*NAMES, "fetch_text")
|
||||||
|
|
||||||
#: What `describe_one` says of a stage that asks no model.
|
#: What `describe_one` says of a stage that asks no model.
|
||||||
NO_ASK = "reads role pages, asks no model"
|
NO_ASK = "reads role pages, asks no model"
|
||||||
@@ -53,7 +54,7 @@ class Stage(BaseModel):
|
|||||||
`backend` is `agent.backend`'s answer, "" for nobody, and `answer` says
|
`backend` is `agent.backend`'s answer, "" for nobody, and `answer` says
|
||||||
it in words."""
|
it in words."""
|
||||||
|
|
||||||
name: Literal["extract", "summarise", "judge", "enrich"]
|
name: Literal["extract", "summarise", "judge", "fetch_text"]
|
||||||
on: bool
|
on: bool
|
||||||
source: Literal["stored", "config"]
|
source: Literal["stored", "config"]
|
||||||
model: str
|
model: str
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ what the model is told, the schema it answers in, what to do with the
|
|||||||
answer), and running it is `desk.modeltask`'s.
|
answer), and running it is `desk.modeltask`'s.
|
||||||
|
|
||||||
A role is waiting while it has no summary, has some text, is open and no copy,
|
A role is waiting while it has no summary, has some text, is open and no copy,
|
||||||
and is either in the top of an enabled agent's ungated scores as deep and as
|
and is either in the top of an enabled agent's feed, the best `summarise_top`
|
||||||
low as that agent's own `limits` say (`summarise_top`, `summarise_min`), or
|
final scores among the roles its fetch gate passes (its `limits`), or one the
|
||||||
one the owner cares about whatever its rank: saved (it has an application, the
|
owner cares about whatever its rank: saved (it has an application, the star)
|
||||||
star) or voted up by an enabled agent. The limits keep the cost flat: a pull
|
or voted up by an enabled agent. Summarise is no part of any score and runs
|
||||||
summarises the roles somebody will look at, not the 30k that are open, and the
|
last in the pull, once the final scores are set. The limit keeps the cost
|
||||||
saved and liked roles are a handful the owner picked. Each is summarised
|
flat: a pull summarises the roles somebody will look at, not the 30k that are
|
||||||
|
open, and the saved and liked roles are a handful the owner picked. Each is summarised
|
||||||
once, with the same give-up rule (`GIVE_UP_AFTER` replies that left it
|
once, with the same give-up rule (`GIVE_UP_AFTER` replies that left it
|
||||||
without). Saving or liking a role queues a batch for that one uid at once,
|
without). Saving or liking a role queues a batch for that one uid at once,
|
||||||
while the stage is on (`web.api`), rather than waiting for the next pull. A
|
while the stage is on (`web.api`), rather than waiting for the next pull. A
|
||||||
|
|||||||
+48
-40
@@ -1450,28 +1450,29 @@ GateField = Literal["place", "country", "remote", "remote_from", "seniority", "f
|
|||||||
"salary_min", "currency", "permit", "languages", "company", "title"]
|
"salary_min", "currency", "permit", "languages", "company", "title"]
|
||||||
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
|
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
|
||||||
|
|
||||||
GateMode = Literal["require", "any", "prefer", "exclude"]
|
GateMode = Literal["require", "any", "exclude"]
|
||||||
|
|
||||||
|
|
||||||
class Gate(Model):
|
class Gate(Model):
|
||||||
"""One condition of an agent. `require` gates a role that fails it (the
|
"""One condition of an agent's fetch gate. `require` gates a role that
|
||||||
row is kept with the reason); the `any` gates together are one group a
|
fails it (the row is kept with the reason); the `any` gates together are
|
||||||
role must match at least one of ("in Denmark, or remote"); `prefer` adds
|
one group a role must match at least one of ("in Denmark, or remote");
|
||||||
`weight` to its score when it matches; `exclude` gates a role that matches
|
`exclude` gates a role that matches any of its values ("title account
|
||||||
any of its values ("title account executive"), a favourite's too. A gate
|
executive"). A company set to All countries skips the `any` group and one
|
||||||
rejects on evidence only: a
|
set to All roles skips the `exclude` gates on `title` (`score.failed_gates`).
|
||||||
role whose column is empty is not rejected, since `extract` fills the
|
A gate rejects on evidence only: a role whose column is empty is not
|
||||||
column later for the roles that rank, and only for those."""
|
rejected, since `extract` fills the column later for the roles in the
|
||||||
|
cut, and only for those."""
|
||||||
|
|
||||||
field: GateField
|
field: GateField
|
||||||
values: list[str | int | float] = Field(min_length=1)
|
values: list[str | int | float] = Field(min_length=1)
|
||||||
mode: GateMode = "require"
|
mode: GateMode = "require"
|
||||||
weight: float = Field(1.0, ge=0)
|
|
||||||
|
|
||||||
|
|
||||||
class Weights(Model):
|
class Weights(Model):
|
||||||
"""How much each score term counts. Summed with the prefer gates' weights
|
"""How much each term of the final score counts. The score is the
|
||||||
into the denominator, so a score stays in 0..1 whatever the numbers."""
|
weighted sum over the sum of the weights, so it stays in 0..1 whatever
|
||||||
|
the numbers."""
|
||||||
|
|
||||||
fit: float = Field(0.6, ge=0)
|
fit: float = Field(0.6, ge=0)
|
||||||
recency: float = Field(0.2, ge=0)
|
recency: float = Field(0.2, ge=0)
|
||||||
@@ -1488,31 +1489,21 @@ class Weights(Model):
|
|||||||
|
|
||||||
|
|
||||||
class Limits(Model):
|
class Limits(Model):
|
||||||
"""How far down an agent's ranking the two model stages read. Each pair
|
"""The agent's cut and the depth of summarise. The cut is the roles that
|
||||||
is a top N, the backstop, and a minimum score, the real stop: a role
|
get fetch text, extract and judge (`app.jobs.score`): the best
|
||||||
is read when it is among the agent's best `extract_top` ungated scores
|
`cut_fit_top` by fit level at or above `cut_fit_min`, then the best
|
||||||
and not below `extract_min`, and summarised likewise. Fit is a
|
`cut_cv_top` by CV level at or above `cut_cv_min` that the first list
|
||||||
calibrated level (`score.scale`), so a bar means the same in every run.
|
leaves out, then every role liked or saved. Both levels are calibrated
|
||||||
A fresh role with the worst fit scores about 0.27 on the default
|
(`score.scale`) with the company's affinity as a small bonus, so a
|
||||||
weights, a perfect one about 0.87. Measured on 16,841 open roles for the
|
minimum means the same in every run. For a broad agent the count stops a
|
||||||
"Copenhagen engineering" starter agent (4,156 ungated, no votes), 0.55
|
list, for a narrow one the minimum. Summarise reads the best
|
||||||
admits about 300 roles to extract and 0.65 about 35 to summarise, the
|
`summarise_top` by final score, and every role liked or saved."""
|
||||||
long answer; the top N catches an agent whose bar admits far more. An
|
|
||||||
agent keeps the limits stored with it; only a key its JSON lacks
|
|
||||||
follows these defaults."""
|
|
||||||
|
|
||||||
extract_top: int = Field(500, ge=0)
|
cut_fit_top: int = Field(500, ge=0)
|
||||||
extract_min: float = Field(0.55, ge=0, le=1)
|
cut_fit_min: float = Field(0.6, ge=0, le=1)
|
||||||
summarise_top: int = Field(30, ge=0)
|
cut_cv_top: int = Field(150, ge=0)
|
||||||
summarise_min: float = Field(0.65, ge=0, le=1)
|
cut_cv_min: float = Field(0.6, ge=0, le=1)
|
||||||
#: How deep `judge` reads an agent with a CV: a long answer per role,
|
summarise_top: int = Field(50, ge=0)
|
||||||
#: so between summarise's 30 and extract's 500.
|
|
||||||
judge_top: int = Field(150, ge=0)
|
|
||||||
judge_min: float = Field(0.55, ge=0, le=1)
|
|
||||||
#: And the agent's ungated roles closest to its CV (`scores.cv_fit`, see
|
|
||||||
#: `app.jobs.score`) that the pair above leaves out, as many as this:
|
|
||||||
#: a role the prompts rank low can still be one the CV fits.
|
|
||||||
judge_cv_top: int = Field(50, ge=0)
|
|
||||||
|
|
||||||
|
|
||||||
class Prompt(Model):
|
class Prompt(Model):
|
||||||
@@ -1601,16 +1592,33 @@ class Agent(Model):
|
|||||||
created_at: str
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
|
class SavedFilter(Model):
|
||||||
|
"""A row of `saved_filters`: the feed's filter settings saved under a
|
||||||
|
name for one agent. `query` is the feed's query string as `roles.js`
|
||||||
|
writes it, without the agent. There is no editing: a change is a new
|
||||||
|
one."""
|
||||||
|
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
query: str
|
||||||
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
class Candidate(Model):
|
class Candidate(Model):
|
||||||
"""What scoring reads about one open role for one agent: its posted
|
"""What scoring reads about one open role for one agent: its posted
|
||||||
date (for `recency`), its company's affinity for that agent, and per
|
date (for `recency`), its company's affinity for that agent and the
|
||||||
gate `1` match, `0` no match, `-1` the column is empty. An `exclude`
|
company's two overrides of the fetch gate, and per gate `1` match, `0`
|
||||||
gate's match is the position of the first value it matched, from 1, so
|
no match, `-1` the column is empty. An `exclude` gate's match is the
|
||||||
the reason can name it."""
|
position of the first value it matched, from 1, so the reason can name
|
||||||
|
it."""
|
||||||
|
|
||||||
uid: str
|
uid: str
|
||||||
posted_at: str
|
posted_at: str
|
||||||
affinity: int = 0
|
affinity: int = 0
|
||||||
|
#: `companies.all_countries`: the `any` group (the place part) is skipped.
|
||||||
|
all_countries: bool = False
|
||||||
|
#: `companies.all_roles`: the `exclude` gates on `title` are skipped.
|
||||||
|
all_roles: bool = False
|
||||||
gates: list[int] = []
|
gates: list[int] = []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+101
-4
@@ -385,10 +385,14 @@ CREATE TABLE IF NOT EXISTS role_votes (
|
|||||||
PRIMARY KEY (agent_id, uid)
|
PRIMARY KEY (agent_id, uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- A role is scored per agent. A gated role keeps its row, with the reason.
|
-- A role is scored per agent. A role the fetch gate rejects keeps its row,
|
||||||
-- prompt names the agent's prompt that gave the fit, '' when fit did not count.
|
-- with the reason. score is the final score, the feed's order. prompt names
|
||||||
-- cv_fit is how close the role is to the agent's CV, 0..1, NULL without a CV
|
-- the agent's prompt that gave the fit, '' when fit did not count. fit is the
|
||||||
-- or a vector and for a gated role; it is no term of score.
|
-- prompt fit level and cv_fit how close the role is to the agent's CV, both
|
||||||
|
-- 0..1 before the affinity bonus, NULL without a prompt, a CV or a vector and
|
||||||
|
-- for a gated role. cut says why the role is in the agent's cut, the roles
|
||||||
|
-- that get fetch text, extract and judge: 'fit', 'cv', 'kept' (liked or
|
||||||
|
-- saved), or '' when it is not.
|
||||||
CREATE TABLE IF NOT EXISTS scores (
|
CREATE TABLE IF NOT EXISTS scores (
|
||||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||||
@@ -397,9 +401,23 @@ CREATE TABLE IF NOT EXISTS scores (
|
|||||||
scored_at TEXT NOT NULL,
|
scored_at TEXT NOT NULL,
|
||||||
prompt TEXT NOT NULL DEFAULT '',
|
prompt TEXT NOT NULL DEFAULT '',
|
||||||
cv_fit REAL,
|
cv_fit REAL,
|
||||||
|
fit REAL,
|
||||||
|
cut TEXT NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (uid, agent_id)
|
PRIMARY KEY (uid, agent_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- The feed's filter settings saved under a name, per agent. query is the
|
||||||
|
-- feed's query string without the agent. Names are unique per agent
|
||||||
|
-- regardless of case; a change is a new row.
|
||||||
|
CREATE TABLE IF NOT EXISTS saved_filters (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
query TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE (agent_id, name COLLATE NOCASE)
|
||||||
|
);
|
||||||
|
|
||||||
-- The vectors of an agent's CV, one per chunk in order, for scores.cv_fit.
|
-- The vectors of an agent's CV, one per chunk in order, for scores.cv_fit.
|
||||||
-- vec_key is sha1 of the embedding model, the chunking and the CV text, the
|
-- vec_key is sha1 of the embedding model, the chunking and the CV text, the
|
||||||
-- same on every row of an agent, so an unchanged CV is not embedded again.
|
-- same on every row of an agent, so an unchanged CV is not embedded again.
|
||||||
@@ -487,6 +505,9 @@ CREATE INDEX IF NOT EXISTS idx_roles_board ON roles(source, subscription_id
|
|||||||
CREATE INDEX IF NOT EXISTS idx_application_events
|
CREATE INDEX IF NOT EXISTS idx_application_events
|
||||||
ON application_events(application_id, at);
|
ON application_events(application_id, at);
|
||||||
CREATE INDEX IF NOT EXISTS idx_scores_agent ON scores(agent_id, score DESC);
|
CREATE INDEX IF NOT EXISTS idx_scores_agent ON scores(agent_id, score DESC);
|
||||||
|
-- The roles in an agent's cut, which fetch text, extract and judge read.
|
||||||
|
-- Partial: most roles are in no cut.
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_scores_cut ON scores(agent_id, uid) WHERE cut <> '';
|
||||||
CREATE INDEX IF NOT EXISTS idx_role_votes_agent ON role_votes(agent_id, vote);
|
CREATE INDEX IF NOT EXISTS idx_role_votes_agent ON role_votes(agent_id, vote);
|
||||||
CREATE INDEX IF NOT EXISTS idx_vectors_model ON vectors(model);
|
CREATE INDEX IF NOT EXISTS idx_vectors_model ON vectors(model);
|
||||||
CREATE INDEX IF NOT EXISTS idx_role_tags_tag ON role_tags(tag);
|
CREATE INDEX IF NOT EXISTS idx_role_tags_tag ON role_tags(tag);
|
||||||
@@ -731,6 +752,12 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
|
|||||||
# missing. The next score fills them.
|
# missing. The next score fills them.
|
||||||
(31, "scores.cv_fit and agent_cv_vectors: how close each role is to the agent's CV",
|
(31, "scores.cv_fit and agent_cv_vectors: how close each role is to the agent's CV",
|
||||||
lambda conn: _add_cv_fit(conn)),
|
lambda conn: _add_cv_fit(conn)),
|
||||||
|
# A Python step: gates and limits are JSON. The old limits were bars on
|
||||||
|
# the blended score and mean nothing on plain fit, so every agent takes
|
||||||
|
# the new defaults.
|
||||||
|
(32, "the cut: scores.fit and scores.cut, agents' limits reset to the cut's defaults, "
|
||||||
|
"prefer gates gone, saved_filters, and enrich renamed fetch text",
|
||||||
|
lambda conn: _add_cut(conn)),
|
||||||
)
|
)
|
||||||
|
|
||||||
#: What a file created from `SCHEMA` today is already at.
|
#: What a file created from `SCHEMA` today is already at.
|
||||||
@@ -1094,6 +1121,76 @@ def _add_cv_fit(conn: sqlite3.Connection) -> None:
|
|||||||
PRIMARY KEY (agent_id, position))""")
|
PRIMARY KEY (agent_id, position))""")
|
||||||
|
|
||||||
|
|
||||||
|
#: What migration 32 writes into every agent's `limits`: `models.Limits` as
|
||||||
|
#: it stood then, spelled out so a later change of the defaults does not
|
||||||
|
#: change what this migration did.
|
||||||
|
_V32_LIMITS = {"cut_fit_top": 500, "cut_fit_min": 0.6, "cut_cv_top": 150, "cut_cv_min": 0.6,
|
||||||
|
"summarise_top": 50}
|
||||||
|
|
||||||
|
_V32 = """
|
||||||
|
CREATE TABLE IF NOT EXISTS saved_filters (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
query TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE (agent_id, name COLLATE NOCASE)
|
||||||
|
);
|
||||||
|
INSERT OR IGNORE INTO state (key, value)
|
||||||
|
SELECT 'stage:fetch_text', value FROM state WHERE key = 'stage:enrich';
|
||||||
|
DELETE FROM state WHERE key = 'stage:enrich';
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def _add_cut(conn: sqlite3.Connection) -> None:
|
||||||
|
"""Migration 32's step. `scores.fit` and `scores.cut`, NULL and empty
|
||||||
|
until the next score; every agent's `limits` reset to `_V32_LIMITS`;
|
||||||
|
the `prefer` gates dropped from every agent's `gates` and `weight` from
|
||||||
|
the others; `saved_filters`; the switch `stage:enrich` renamed
|
||||||
|
`stage:fetch_text`; and the queued `enrich` and `enrich_batch` jobs
|
||||||
|
deleted, with a schedule of `enrich` firing `fetch_text`. Runs twice
|
||||||
|
without harm: limits are reset when the columns are added, and after
|
||||||
|
that only where they still hold a key the cut does not know."""
|
||||||
|
columns = {r[1] for r in conn.execute("PRAGMA table_info(scores)")}
|
||||||
|
fresh = "cut" not in columns
|
||||||
|
if "fit" not in columns:
|
||||||
|
conn.execute("ALTER TABLE scores ADD COLUMN fit REAL")
|
||||||
|
if fresh:
|
||||||
|
conn.execute("ALTER TABLE scores ADD COLUMN cut TEXT NOT NULL DEFAULT ''")
|
||||||
|
reset = dropped = 0
|
||||||
|
for agent_id, raw_limits, raw_gates in conn.execute(
|
||||||
|
"SELECT id, limits, gates FROM agents").fetchall():
|
||||||
|
try:
|
||||||
|
limits = json.loads(raw_limits or "{}")
|
||||||
|
except ValueError:
|
||||||
|
limits = None
|
||||||
|
if fresh or not isinstance(limits, dict) or set(limits) - set(_V32_LIMITS):
|
||||||
|
conn.execute("UPDATE agents SET limits=? WHERE id=?",
|
||||||
|
(json.dumps(_V32_LIMITS), agent_id))
|
||||||
|
reset += 1
|
||||||
|
try:
|
||||||
|
gates = json.loads(raw_gates or "[]")
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if not isinstance(gates, list):
|
||||||
|
continue
|
||||||
|
kept = [{k: v for k, v in g.items() if k != "weight"} for g in gates
|
||||||
|
if isinstance(g, dict) and g.get("mode") != "prefer"]
|
||||||
|
if kept != gates:
|
||||||
|
dropped += sum(1 for g in gates if isinstance(g, dict) and g.get("mode") == "prefer")
|
||||||
|
conn.execute("UPDATE agents SET gates=? WHERE id=?", (json.dumps(kept), agent_id))
|
||||||
|
for statement in _statements(_V32):
|
||||||
|
conn.execute(statement)
|
||||||
|
tables = {r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||||
|
if "jobs" in tables:
|
||||||
|
conn.execute("DELETE FROM jobs WHERE state = 'queued' "
|
||||||
|
"AND kind IN ('enrich', 'enrich_batch')")
|
||||||
|
if "schedules" in tables:
|
||||||
|
conn.execute("UPDATE schedules SET kind = 'fetch_text' WHERE kind = 'enrich'")
|
||||||
|
log.info("migration 32: %d agents' limits reset to the cut's defaults, %d prefer gates "
|
||||||
|
"dropped", reset, dropped)
|
||||||
|
|
||||||
|
|
||||||
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
||||||
"""Migration 21's step. The column; the tag for every company that is a
|
"""Migration 21's step. The column; the tag for every company that is a
|
||||||
favourite of any agent, since favourite no longer widens what a pull
|
favourite of any agent, since favourite no longer widens what a pull
|
||||||
|
|||||||
+166
-124
@@ -25,7 +25,7 @@ from app import dupes, places
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
|
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
|
||||||
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
|
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
|
||||||
RoleCopy, RolePlace, RoleRow, ScoredRole, cv_languages as normal_languages, cv_score,
|
RoleCopy, RolePlace, RoleRow, SavedFilter, ScoredRole, cv_languages as normal_languages, cv_score,
|
||||||
BROKEN_CAP, capped_career, 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,
|
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,
|
fetch_terms as normal_terms, host_word, iso_day, posted_at, posted_host, remote_of, title_key,
|
||||||
@@ -42,7 +42,7 @@ _RAW_TEXT = ("place", "currency")
|
|||||||
#: The host's own words a reader hands on in `Item.raw`, stored as
|
#: The host's own words a reader hands on in `Item.raw`, stored as
|
||||||
#: `<name>_host` (`host_word`) for `app.prep` to map. `seniority_host` is
|
#: `<name>_host` (`host_word`) for `app.prep` to map. `seniority_host` is
|
||||||
#: rewritten every pull, as the host's level always was; the others are kept
|
#: rewritten every pull, as the host's level always was; the others are kept
|
||||||
#: filled, since a role's own page (`enrich`) may state what its listing
|
#: filled, since a role's own page (`fetch_text`) may state what its listing
|
||||||
#: does not.
|
#: does not.
|
||||||
_HOST_WORDS = ("seniority", "employment", "remote", "country")
|
_HOST_WORDS = ("seniority", "employment", "remote", "country")
|
||||||
_KEPT_HOST_WORDS = ("employment_host", "remote_host", "country_host")
|
_KEPT_HOST_WORDS = ("employment_host", "remote_host", "country_host")
|
||||||
@@ -78,6 +78,16 @@ _EXTRACT_WAITING = ("(extracted_at IS NULL OR seniority_model = '' OR remote_whe
|
|||||||
"OR languages_required IS NULL) "
|
"OR languages_required IS NULL) "
|
||||||
f"AND closed_at IS NULL AND dup_of IS NULL AND extract_tries < {GIVE_UP_AFTER}")
|
f"AND closed_at IS NULL AND dup_of IS NULL AND extract_tries < {GIVE_UP_AFTER}")
|
||||||
|
|
||||||
|
#: A role in the cut of an enabled agent (`scores.cut`, see `app.jobs.score`),
|
||||||
|
#: as a `WHERE` on `r`: what fetch text and extract read.
|
||||||
|
_IN_CUT = ("r.uid IN (SELECT s.uid FROM scores s JOIN agents a ON a.id = s.agent_id "
|
||||||
|
"AND a.enabled = 1 WHERE s.cut <> '')")
|
||||||
|
|
||||||
|
#: The order within one agent's cut, over its scores as `s`: in by fit, best
|
||||||
|
#: fit first, then in by CV closeness, closest first, then kept.
|
||||||
|
_CUT_ORDER = ("CASE s.cut WHEN 'fit' THEN 0 WHEN 'cv' THEN 1 ELSE 2 END, "
|
||||||
|
"CASE s.cut WHEN 'fit' THEN s.fit WHEN 'cv' THEN s.cv_fit END DESC")
|
||||||
|
|
||||||
#: What a vote may be: 1 like, 0 neither way, -1 pass, None unjudged.
|
#: What a vote may be: 1 like, 0 neither way, -1 pass, None unjudged.
|
||||||
VOTES = (-1, 0, 1, None)
|
VOTES = (-1, 0, 1, None)
|
||||||
|
|
||||||
@@ -1127,7 +1137,7 @@ class Store:
|
|||||||
hide_muted: bool = False, include_read: bool = True,
|
hide_muted: bool = False, include_read: bool = True,
|
||||||
tags: Sequence[str] = (), tag_mode: str = "any",
|
tags: Sequence[str] = (), tag_mode: str = "any",
|
||||||
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
||||||
judged: str | None = None, pay: str | None = None,
|
fetch_gate: bool = False, judged: str | None = None, pay: str | None = None,
|
||||||
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
||||||
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
||||||
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
||||||
@@ -1172,7 +1182,9 @@ class Store:
|
|||||||
set. The score is the stored one moved by the agent's vote
|
set. The score is the stored one moved by the agent's vote
|
||||||
(`_VOTED_SCORE`), so a vote shows in the order at once and needs no
|
(`_VOTED_SCORE`), so a vote shows in the order at once and needs no
|
||||||
rescore. With `by_score` off the order is newest, with the votes and
|
rescore. With `by_score` off the order is newest, with the votes and
|
||||||
no score.
|
no score; with `fetch_gate` as well, the newest order keeps to the
|
||||||
|
agent's fetch gate the same way, carrying `gated_reason`, so no order
|
||||||
|
shows a role the agent's gate rejects unless `gated`.
|
||||||
|
|
||||||
With `by_cv` as well, the roles the agent's `judge` read come first
|
With `by_cv` as well, the roles the agent's `judge` read come first
|
||||||
by `cv_score`, then the others by how close they are to the CV
|
by `cv_score`, then the others by how close they are to the CV
|
||||||
@@ -1191,6 +1203,7 @@ class Store:
|
|||||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||||
|
fetch_gate=fetch_gate,
|
||||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||||
closing=closing)
|
closing=closing)
|
||||||
@@ -1202,7 +1215,9 @@ class Store:
|
|||||||
if scored:
|
if scored:
|
||||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
||||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||||
elif open_only:
|
elif agent is not None and fetch_gate:
|
||||||
|
select += ", s.gated_reason"
|
||||||
|
if not scored and open_only:
|
||||||
# Newest first, open only: idx_roles_posted covers this exactly
|
# Newest first, open only: idx_roles_posted covers this exactly
|
||||||
# (posted_at DESC, uid, WHERE closed_at IS NULL), so it earns the
|
# (posted_at DESC, uid, WHERE closed_at IS NULL), so it earns the
|
||||||
# LIMIT rather than sorting every open role first. Left to the
|
# LIMIT rather than sorting every open role first. Left to the
|
||||||
@@ -1241,7 +1256,7 @@ class Store:
|
|||||||
hide_muted: bool = False, include_read: bool = True,
|
hide_muted: bool = False, include_read: bool = True,
|
||||||
tags: Sequence[str] = (), tag_mode: str = "any",
|
tags: Sequence[str] = (), tag_mode: str = "any",
|
||||||
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
||||||
judged: str | None = None, pay: str | None = None,
|
fetch_gate: bool = False, judged: str | None = None, pay: str | None = None,
|
||||||
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
||||||
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
||||||
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
||||||
@@ -1264,6 +1279,7 @@ class Store:
|
|||||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||||
|
fetch_gate=fetch_gate,
|
||||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||||
closing=closing)
|
closing=closing)
|
||||||
@@ -1280,7 +1296,9 @@ class Store:
|
|||||||
if scored:
|
if scored:
|
||||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
||||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||||
elif open_only:
|
elif agent is not None and fetch_gate:
|
||||||
|
select += ", s.gated_reason"
|
||||||
|
if not scored and open_only:
|
||||||
# Same reasoning as `roles`: the planner otherwise sorts every
|
# Same reasoning as `roles`: the planner otherwise sorts every
|
||||||
# open role before applying LIMIT.
|
# open role before applying LIMIT.
|
||||||
sql = sql.replace("FROM roles ", "FROM roles INDEXED BY idx_roles_posted ", 1)
|
sql = sql.replace("FROM roles ", "FROM roles INDEXED BY idx_roles_posted ", 1)
|
||||||
@@ -1318,7 +1336,8 @@ class Store:
|
|||||||
days: int | None = None, hide_muted: bool = False,
|
days: int | None = None, hide_muted: bool = False,
|
||||||
include_read: bool = True, tags: Sequence[str] = (),
|
include_read: bool = True, tags: Sequence[str] = (),
|
||||||
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
||||||
gated: bool = False, judged: str | None = None,
|
gated: bool = False, fetch_gate: bool = False,
|
||||||
|
judged: str | None = None,
|
||||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||||
seniority_unknown: bool = True, pay_unknown: bool = False,
|
seniority_unknown: bool = True, pay_unknown: bool = False,
|
||||||
@@ -1328,6 +1347,7 @@ class Store:
|
|||||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||||
|
fetch_gate=fetch_gate,
|
||||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||||
closing=closing)
|
closing=closing)
|
||||||
@@ -1340,7 +1360,8 @@ class Store:
|
|||||||
days: int | None = None, hide_muted: bool = False,
|
days: int | None = None, hide_muted: bool = False,
|
||||||
include_read: bool = True, tags: Sequence[str] = (),
|
include_read: bool = True, tags: Sequence[str] = (),
|
||||||
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
||||||
gated: bool = False, judged: str | None = None,
|
gated: bool = False, fetch_gate: bool = False,
|
||||||
|
judged: str | None = None,
|
||||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||||
seniority_unknown: bool = True,
|
seniority_unknown: bool = True,
|
||||||
@@ -1356,7 +1377,7 @@ class Store:
|
|||||||
"company": company, "place": place, "open_only": open_only, "q": q,
|
"company": company, "place": place, "open_only": open_only, "q": q,
|
||||||
"function": function, "remote": remote, "days": days, "hide_muted": hide_muted,
|
"function": function, "remote": remote, "days": days, "hide_muted": hide_muted,
|
||||||
"include_read": include_read, "tags": tags, "tag_mode": tag_mode, "agent": agent,
|
"include_read": include_read, "tags": tags, "tag_mode": tag_mode, "agent": agent,
|
||||||
"by_score": by_score, "gated": gated, "judged": judged,
|
"by_score": by_score, "gated": gated, "fetch_gate": fetch_gate, "judged": judged,
|
||||||
"company_keys": company_keys, "places": places, "closing": closing}
|
"company_keys": company_keys, "places": places, "closing": closing}
|
||||||
by_level, level_params = self._roles_from(
|
by_level, level_params = self._roles_from(
|
||||||
**shared, pay=pay, pay_unknown=pay_unknown)
|
**shared, pay=pay, pay_unknown=pay_unknown)
|
||||||
@@ -1376,6 +1397,7 @@ class Store:
|
|||||||
days: int | None, hide_muted: bool, include_read: bool,
|
days: int | None, hide_muted: bool, include_read: bool,
|
||||||
tags: Sequence[str], tag_mode: str, agent: int | None,
|
tags: Sequence[str], tag_mode: str, agent: int | None,
|
||||||
by_score: bool, gated: bool, judged: str | None,
|
by_score: bool, gated: bool, judged: str | None,
|
||||||
|
fetch_gate: bool = False,
|
||||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||||
seniority_unknown: bool = True,
|
seniority_unknown: bool = True,
|
||||||
@@ -1384,7 +1406,9 @@ class Store:
|
|||||||
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
|
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
|
||||||
its parameters in order. The agent's votes are always joined as `v`
|
its parameters in order. The agent's votes are always joined as `v`
|
||||||
(see `_WITH_VOTES`) and its judgements as `j` (`_WITH_JUDGEMENTS`);
|
(see `_WITH_VOTES`) and its judgements as `j` (`_WITH_JUDGEMENTS`);
|
||||||
its scores as `s` only when ordering by them. A copy of another role
|
its scores as `s` when ordering by them or with `fetch_gate`, and
|
||||||
|
then a role the agent's fetch gate rejects is left out unless
|
||||||
|
`gated`. A copy of another role
|
||||||
(`rebuild_dupes`) is never listed: its kept role stands for it and
|
(`rebuild_dupes`) is never listed: its kept role stands for it and
|
||||||
counts its copies. `closing` keeps the roles whose deadline is
|
counts its copies. `closing` keeps the roles whose deadline is
|
||||||
today or within `CLOSING_DAYS` after it."""
|
today or within `CLOSING_DAYS` after it."""
|
||||||
@@ -1458,7 +1482,7 @@ class Store:
|
|||||||
params += values
|
params += values
|
||||||
sql = f"FROM roles {_WITH_VOTES} {_WITH_JUDGEMENTS}"
|
sql = f"FROM roles {_WITH_VOTES} {_WITH_JUDGEMENTS}"
|
||||||
joins: list[Any] = [agent, agent]
|
joins: list[Any] = [agent, agent]
|
||||||
if agent is not None and by_score:
|
if agent is not None and (by_score or fetch_gate):
|
||||||
sql += " JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
sql += " JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
||||||
joins.append(agent)
|
joins.append(agent)
|
||||||
if not gated:
|
if not gated:
|
||||||
@@ -1639,21 +1663,18 @@ class Store:
|
|||||||
|
|
||||||
# -------------------------------------------------------------- extract
|
# -------------------------------------------------------------- extract
|
||||||
|
|
||||||
def _top_scope(self, stage: Literal["extract", "summarise"]) -> tuple[str, list[Any]]:
|
def _summarise_top(self) -> tuple[str, list[Any]]:
|
||||||
"""The `WHERE` fragment for a role among the best ungated scores of
|
"""The `WHERE` fragment for a role among the best `summarise_top`
|
||||||
an enabled agent, as deep and as low as that agent's own `limits`
|
final scores of an enabled agent with a prompt, open, no copy and
|
||||||
say for `stage`: what the two model stages, extract and summarise,
|
passing that agent's fetch gate: the top of its feed. The rank is
|
||||||
are bounded to. The rank is numbered per agent and the agent's
|
numbered per agent and the agent's limits ride out of the window
|
||||||
limits ride out of the window subquery beside it, so each row is
|
subquery beside it, so each row is held to the limit of the agent
|
||||||
held to the limits of the agent that ranked it; a key the JSON lacks
|
that ranked it; a key the JSON lacks is the `Limits` default. The
|
||||||
is the `Limits` default. The role is `r`. A company an agent hid
|
role is `r`. An agent without a prompt with text counts for nothing
|
||||||
needs no clause: `score` writes no rows for it under that agent. An
|
here: its scores have no fit, so they say how fresh a role is, not
|
||||||
agent without a prompt with text counts for nothing here: its scores
|
whether it is wanted."""
|
||||||
have no fit, so they say how fresh a role is, not whether it is
|
return ("""r.uid IN (SELECT uid FROM (
|
||||||
wanted."""
|
SELECT s.uid, a.limits, ROW_NUMBER() OVER (
|
||||||
defaults = Limits()
|
|
||||||
return (f"""r.uid IN (SELECT uid FROM (
|
|
||||||
SELECT s.uid, s.score, a.limits, ROW_NUMBER() OVER (
|
|
||||||
PARTITION BY s.agent_id
|
PARTITION BY s.agent_id
|
||||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid) AS n
|
ORDER BY s.score DESC, top.posted_at DESC, s.uid) AS n
|
||||||
FROM scores s
|
FROM scores s
|
||||||
@@ -1664,15 +1685,14 @@ class Store:
|
|||||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
||||||
AND top.dup_of IS NULL
|
AND top.dup_of IS NULL
|
||||||
WHERE s.gated_reason = '')
|
WHERE s.gated_reason = '')
|
||||||
WHERE n <= COALESCE(json_extract(limits, '$.{stage}_top'), ?)
|
WHERE n <= COALESCE(json_extract(limits, '$.summarise_top'), ?))""",
|
||||||
AND score >= COALESCE(json_extract(limits, '$.{stage}_min'), ?))""",
|
[Limits().summarise_top])
|
||||||
[getattr(defaults, f"{stage}_top"), getattr(defaults, f"{stage}_min")])
|
|
||||||
|
|
||||||
def _extract_scope(self, uids: Sequence[str] | None) -> tuple[str, list[Any]]:
|
def _extract_scope(self, uids: Sequence[str] | None) -> tuple[str, list[Any]]:
|
||||||
"""The `WHERE` for a role `extract` may read: open, never answered,
|
"""The `WHERE` for a role `extract` may read: open, never answered,
|
||||||
not given up. Given `uids`, those of them and nothing else, since a
|
not given up. Given `uids`, those of them and nothing else, since a
|
||||||
batch asks again when it runs and must finish what it was dealt;
|
batch asks again when it runs and must finish what it was dealt;
|
||||||
otherwise only the roles in `_top_scope`."""
|
otherwise only the roles in the cut of an enabled agent (`_IN_CUT`)."""
|
||||||
where = [_EXTRACT_WAITING.replace("extracted_at", "r.extracted_at")
|
where = [_EXTRACT_WAITING.replace("extracted_at", "r.extracted_at")
|
||||||
.replace("closed_at", "r.closed_at").replace("extract_tries", "r.extract_tries")
|
.replace("closed_at", "r.closed_at").replace("extract_tries", "r.extract_tries")
|
||||||
.replace("dup_of", "r.dup_of")
|
.replace("dup_of", "r.dup_of")
|
||||||
@@ -1682,8 +1702,7 @@ class Store:
|
|||||||
if uids is not None:
|
if uids is not None:
|
||||||
where.append("r.uid IN (SELECT value FROM json_each(?))")
|
where.append("r.uid IN (SELECT value FROM json_each(?))")
|
||||||
return " AND ".join(where), [json.dumps(list(uids))]
|
return " AND ".join(where), [json.dumps(list(uids))]
|
||||||
top, params = self._top_scope("extract")
|
return " AND ".join([*where, _IN_CUT]), []
|
||||||
return " AND ".join([*where, top]), params
|
|
||||||
|
|
||||||
def extract_pending(self) -> int:
|
def extract_pending(self) -> int:
|
||||||
where, params = self._extract_scope(None)
|
where, params = self._extract_scope(None)
|
||||||
@@ -1691,14 +1710,13 @@ class Store:
|
|||||||
return int(row["n"]) if row else 0
|
return int(row["n"]) if row else 0
|
||||||
|
|
||||||
def extract_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
def extract_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
||||||
"""Roles `extract` has yet to read: the best of every enabled agent's
|
"""Roles `extract` has yet to read: those in the cut of an enabled
|
||||||
scores, as deep and as low as that agent's own `limits` say, so the
|
agent, so the backlog follows the cut rather than the boards.
|
||||||
backlog follows the rankings rather than the boards. Ordered by the
|
Ordered by the best rank any agent gives the role by final score
|
||||||
best rank any agent gives the role (each agent's first, then each
|
(each agent's first, then each agent's second ...), then by that
|
||||||
agent's second ...), then by its score, so every agent's top comes
|
score, so every agent's top comes before anyone's tail whatever
|
||||||
before anyone's tail whatever limits cut the batch. Given `uids`,
|
limit cuts the batch. Given `uids`, only those of them still waiting,
|
||||||
only those of them still waiting, whatever their rank; a role no agent
|
whatever their rank; a role no agent ranks comes last."""
|
||||||
ranks comes last."""
|
|
||||||
where, params = self._extract_scope(uids)
|
where, params = self._extract_scope(uids)
|
||||||
return [Role.from_row(r) for r in self._rows(
|
return [Role.from_row(r) for r in self._rows(
|
||||||
"SELECT r.* FROM roles r LEFT JOIN ("
|
"SELECT r.* FROM roles r LEFT JOIN ("
|
||||||
@@ -1826,15 +1844,16 @@ class Store:
|
|||||||
"""The `WHERE` for a role `summarise` may be sent: no summary yet and
|
"""The `WHERE` for a role `summarise` may be sent: no summary yet and
|
||||||
some text to summarise. Given `uids`, those of them and nothing else,
|
some text to summarise. Given `uids`, those of them and nothing else,
|
||||||
open or not and given up or not, because somebody asked for them.
|
open or not and given up or not, because somebody asked for them.
|
||||||
Otherwise open, not given up, and in `_top_scope` or one the owner
|
Otherwise open, not given up, and in the top of an enabled agent's
|
||||||
cares about whatever its rank: saved (it has an application) or voted
|
feed (`_summarise_top`) or one the owner cares about whatever its
|
||||||
up by an enabled agent."""
|
rank: saved (it has an application) or voted up by an enabled
|
||||||
|
agent."""
|
||||||
where = ["r.summary = ''",
|
where = ["r.summary = ''",
|
||||||
"(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"]
|
"(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"]
|
||||||
if uids is not None:
|
if uids is not None:
|
||||||
where.append("r.uid IN (SELECT value FROM json_each(?))")
|
where.append("r.uid IN (SELECT value FROM json_each(?))")
|
||||||
return " AND ".join(where), [json.dumps(list(uids))]
|
return " AND ".join(where), [json.dumps(list(uids))]
|
||||||
top, params = self._top_scope("summarise")
|
top, params = self._summarise_top()
|
||||||
where += [
|
where += [
|
||||||
"r.closed_at IS NULL",
|
"r.closed_at IS NULL",
|
||||||
"r.dup_of IS NULL",
|
"r.dup_of IS NULL",
|
||||||
@@ -1856,12 +1875,12 @@ class Store:
|
|||||||
return int(row["n"]) if row else 0
|
return int(row["n"]) if row else 0
|
||||||
|
|
||||||
def summarise_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
def summarise_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
||||||
"""Roles `summarise` has yet to write, newest first: the top of every
|
"""Roles `summarise` has yet to write, newest first: the best
|
||||||
enabled agent's scores, as deep and as low as that agent's own
|
`summarise_top` final scores of every enabled agent, so the backlog
|
||||||
`limits` say, so the backlog is bounded by the agents rather than by
|
is bounded by the agents rather than by the number of open roles,
|
||||||
the number of open roles, and every open role that is saved or voted
|
and every open role that is saved or voted up by an enabled agent,
|
||||||
up by an enabled agent, whatever its rank; given `uids`, those still without a
|
whatever its rank; given `uids`, those still without a summary,
|
||||||
summary, whatever their rank. A batch asks again when it runs."""
|
whatever their rank. A batch asks again when it runs."""
|
||||||
where, params = self._summary_scope(uids)
|
where, params = self._summary_scope(uids)
|
||||||
return [Role.from_row(r) for r in self._rows(
|
return [Role.from_row(r) for r in self._rows(
|
||||||
f"SELECT r.* FROM roles r WHERE {where} "
|
f"SELECT r.* FROM roles r WHERE {where} "
|
||||||
@@ -1908,17 +1927,15 @@ class Store:
|
|||||||
# ---------------------------------------------------------------- judge
|
# ---------------------------------------------------------------- judge
|
||||||
|
|
||||||
def judge_rows(self, agent: Agent, uids: Sequence[str] | None = None) -> list[sqlite3.Row]:
|
def judge_rows(self, agent: Agent, uids: Sequence[str] | None = None) -> list[sqlite3.Row]:
|
||||||
"""What `judge` may read for one agent: its best ungated scores of
|
"""What `judge` may read for one agent: the open roles in its cut
|
||||||
open roles that are no copy, as deep and as low as its `limits` say
|
that are no copy and have some text (`article_text` or
|
||||||
(`judge_top`, `judge_min`), best first, then the `judge_cv_top`
|
`description`), those in by fit first, best fit first, then those in
|
||||||
ungated ones closest to its CV (`scores.cv_fit`) that the first set
|
by CV closeness, closest first, then those kept because they are
|
||||||
leaves out, closest first, each with some text (`article_text` or
|
liked or saved. Given `uids`, those of them with text, whatever
|
||||||
`description`). Given `uids`, those of them with
|
their rank or state. Each row carries `uid`, `title`, `company`,
|
||||||
text, whatever their rank or state. Each row carries `uid`,
|
`place`, `article_text`, `description`, and the stored judgement's
|
||||||
`title`, `company`, `place`, `article_text`, `description`, and the
|
`input_key`, `judged_at` and `tries` (NULL, NULL and 0 without one),
|
||||||
stored judgement's `input_key`, `judged_at` and `tries` (NULL, NULL
|
and `given_up` once `tries` reached `GIVE_UP_AFTER`."""
|
||||||
and 0 without one), and `given_up` once `tries` reached
|
|
||||||
`GIVE_UP_AFTER`."""
|
|
||||||
text = "(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"
|
text = "(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"
|
||||||
select = ("SELECT r.uid, r.title, r.company, r.place, r.article_text, r.description, "
|
select = ("SELECT r.uid, r.title, r.company, r.place, r.article_text, r.description, "
|
||||||
"j.input_key, j.judged_at, COALESCE(j.tries, 0) AS tries, "
|
"j.input_key, j.judged_at, COALESCE(j.tries, 0) AS tries, "
|
||||||
@@ -1928,23 +1945,13 @@ class Store:
|
|||||||
return self._rows(
|
return self._rows(
|
||||||
f"{select} roles r {joined} WHERE r.uid IN (SELECT value FROM json_each(?)) "
|
f"{select} roles r {joined} WHERE r.uid IN (SELECT value FROM json_each(?)) "
|
||||||
f"AND {text} ORDER BY r.uid", (agent.id, json.dumps(list(uids))))
|
f"AND {text} ORDER BY r.uid", (agent.id, json.dumps(list(uids))))
|
||||||
ranked = ("FROM scores s JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL "
|
|
||||||
"AND top.dup_of IS NULL WHERE s.agent_id = ? AND s.gated_reason = ''")
|
|
||||||
return self._rows(
|
return self._rows(
|
||||||
f"""WITH best AS (SELECT s.uid, s.score {ranked}
|
f"""{select} scores s JOIN roles r ON r.uid = s.uid AND r.closed_at IS NULL
|
||||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid LIMIT ?),
|
AND r.dup_of IS NULL
|
||||||
by_score AS (SELECT uid, 0 AS part, score AS rank FROM best
|
{joined}
|
||||||
WHERE score >= ?),
|
WHERE s.agent_id = ? AND s.cut <> '' AND {text}
|
||||||
by_cv AS (SELECT s.uid, 1 AS part, s.cv_fit AS rank {ranked}
|
ORDER BY {_CUT_ORDER}, r.posted_at DESC, r.uid""",
|
||||||
AND s.cv_fit IS NOT NULL
|
(agent.id, agent.id))
|
||||||
AND s.uid NOT IN (SELECT uid FROM by_score)
|
|
||||||
ORDER BY s.cv_fit DESC, top.posted_at DESC, s.uid LIMIT ?)
|
|
||||||
{select} (SELECT * FROM by_score UNION ALL SELECT * FROM by_cv) w
|
|
||||||
JOIN roles r ON r.uid = w.uid {joined}
|
|
||||||
WHERE {text}
|
|
||||||
ORDER BY w.part, w.rank DESC, r.posted_at DESC, r.uid""",
|
|
||||||
(agent.id, agent.limits.judge_top, agent.limits.judge_min, agent.id,
|
|
||||||
agent.limits.judge_cv_top, agent.id))
|
|
||||||
|
|
||||||
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
|
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
|
||||||
experience: int, career: int, strengths: Sequence[str],
|
experience: int, career: int, strengths: Sequence[str],
|
||||||
@@ -2031,18 +2038,15 @@ class Store:
|
|||||||
keeps it."""
|
keeps it."""
|
||||||
return bool(self._write("UPDATE roles SET posting_url = ? WHERE uid = ?", (url, uid)))
|
return bool(self._write("UPDATE roles SET posting_url = ? WHERE uid = ?", (url, uid)))
|
||||||
|
|
||||||
# --------------------------------------------------------------- enrich
|
# ----------------------------------------------------------- fetch text
|
||||||
|
|
||||||
def enrich_waiting(self, top: int, floor: float,
|
def fetch_text_waiting(self, uids: Sequence[str] | None = None) -> list[dict[str, Any]]:
|
||||||
uids: Sequence[str] | None = None) -> list[dict[str, Any]]:
|
"""Open board and search roles without text in the cut of an enabled
|
||||||
"""Open board and search roles without text that an enabled agent with a prompt
|
agent, best first by the highest final score any such agent gives
|
||||||
ranks ungated among its best `top` and at `floor` or above, best
|
them, as `{uid, source_id, subscription_id, title, url, published_at,
|
||||||
first by the highest such score, as `{uid, source_id,
|
raw, score}`. Given `uids`, those of them still without text, cut or
|
||||||
subscription_id, title, url, published_at, raw, score}`. The ranking
|
not, in no order (`score` is None), since a batch finishes what it
|
||||||
is `_top_scope`'s, with the bar given rather than the agent's own.
|
was dealt."""
|
||||||
Given `uids`, those of them still without text, whatever their rank,
|
|
||||||
in no order (`score` is None), since a batch finishes what it was
|
|
||||||
dealt."""
|
|
||||||
fields = ("r.uid, r.source_id, r.subscription_id, r.title, r.original_url AS url, "
|
fields = ("r.uid, r.source_id, r.subscription_id, r.title, r.original_url AS url, "
|
||||||
"r.published_at, r.raw")
|
"r.published_at, r.raw")
|
||||||
waiting = ("r.closed_at IS NULL AND r.dup_of IS NULL AND r.source IN ('ats', 'search') "
|
waiting = ("r.closed_at IS NULL AND r.dup_of IS NULL AND r.source IN ('ats', 'search') "
|
||||||
@@ -2054,21 +2058,11 @@ class Store:
|
|||||||
"AND r.uid IN (SELECT value FROM json_each(?))", (json.dumps(list(uids)),))
|
"AND r.uid IN (SELECT value FROM json_each(?))", (json.dumps(list(uids)),))
|
||||||
else:
|
else:
|
||||||
rows = self._rows(
|
rows = self._rows(
|
||||||
f"""SELECT {fields}, MAX(ranked.score) AS score FROM (
|
f"""SELECT {fields}, MAX(s.score) AS score FROM scores s
|
||||||
SELECT s.uid, s.score, ROW_NUMBER() OVER (
|
|
||||||
PARTITION BY s.agent_id
|
|
||||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid) AS n
|
|
||||||
FROM scores s
|
|
||||||
JOIN agents a ON a.id = s.agent_id AND a.enabled = 1
|
JOIN agents a ON a.id = s.agent_id AND a.enabled = 1
|
||||||
AND EXISTS (SELECT 1 FROM agent_prompts p
|
JOIN roles r ON r.uid = s.uid
|
||||||
WHERE p.agent_id = a.id
|
WHERE s.cut <> '' AND {waiting}
|
||||||
AND TRIM(p.text, ' ' || char(9, 10, 13)) <> '')
|
GROUP BY r.uid ORDER BY score DESC, r.uid""")
|
||||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
|
||||||
AND top.dup_of IS NULL
|
|
||||||
WHERE s.gated_reason = '') ranked
|
|
||||||
JOIN roles r ON r.uid = ranked.uid
|
|
||||||
WHERE ranked.n <= ? AND ranked.score >= ? AND {waiting}
|
|
||||||
GROUP BY r.uid ORDER BY score DESC, r.uid""", (top, floor))
|
|
||||||
return [dict(row) for row in rows]
|
return [dict(row) for row in rows]
|
||||||
|
|
||||||
# -------------------------------------------------------------- vectors
|
# -------------------------------------------------------------- vectors
|
||||||
@@ -2220,10 +2214,41 @@ class Store:
|
|||||||
return found
|
return found
|
||||||
|
|
||||||
def delete_agent(self, agent_id: int) -> bool:
|
def delete_agent(self, agent_id: int) -> bool:
|
||||||
"""Its prompts, scores, votes and affinities go with it, by the
|
"""Its prompts, scores, votes, affinities and saved filters go with
|
||||||
foreign keys."""
|
it, by the foreign keys."""
|
||||||
return self._write("DELETE FROM agents WHERE id=?", (agent_id,)) > 0
|
return self._write("DELETE FROM agents WHERE id=?", (agent_id,)) > 0
|
||||||
|
|
||||||
|
# -------------------------------------------------------- saved filters
|
||||||
|
|
||||||
|
def saved_filters(self, agent_id: int) -> list[SavedFilter]:
|
||||||
|
"""The agent's saved filters, by name regardless of case."""
|
||||||
|
return [SavedFilter.from_row(r) for r in self._rows(
|
||||||
|
"SELECT * FROM saved_filters WHERE agent_id=? ORDER BY name COLLATE NOCASE, id",
|
||||||
|
(agent_id,))]
|
||||||
|
|
||||||
|
def save_filter(self, agent_id: int, name: str, query: str) -> SavedFilter:
|
||||||
|
"""Save the feed's filters under `name` for the agent. ValueError on
|
||||||
|
an empty name or one the agent already has regardless of case,
|
||||||
|
KeyError on an unknown agent."""
|
||||||
|
name = " ".join(name.split())
|
||||||
|
if not name:
|
||||||
|
raise ValueError("a saved filter needs a name")
|
||||||
|
try:
|
||||||
|
with self.transaction() as conn:
|
||||||
|
if conn.execute("SELECT 1 FROM agents WHERE id=?", (agent_id,)).fetchone() is None:
|
||||||
|
raise KeyError(agent_id)
|
||||||
|
new_id = conn.execute(
|
||||||
|
"INSERT INTO saved_filters (agent_id, name, query, created_at) "
|
||||||
|
"VALUES (?,?,?,?)", (agent_id, name, query, self.now())).lastrowid
|
||||||
|
except sqlite3.IntegrityError as exc:
|
||||||
|
raise ValueError(f"a filter named {name!r} is already saved") from exc
|
||||||
|
row = self._row("SELECT * FROM saved_filters WHERE id=?", (new_id,))
|
||||||
|
assert row is not None
|
||||||
|
return SavedFilter.from_row(row)
|
||||||
|
|
||||||
|
def delete_filter(self, filter_id: int) -> bool:
|
||||||
|
return self._write("DELETE FROM saved_filters WHERE id=?", (filter_id,)) > 0
|
||||||
|
|
||||||
def prompt_vector(self, agent_id: int, name: str, key: str) -> np.ndarray | None:
|
def prompt_vector(self, agent_id: int, name: str, key: str) -> np.ndarray | None:
|
||||||
"""The cached vector of the agent's prompt `name`, if it was made
|
"""The cached vector of the agent's prompt `name`, if it was made
|
||||||
under `key`."""
|
under `key`."""
|
||||||
@@ -2262,11 +2287,11 @@ class Store:
|
|||||||
|
|
||||||
def score_candidates(self, agent_id: int, gates: Sequence[Gate]) -> list[Candidate]:
|
def score_candidates(self, agent_id: int, gates: Sequence[Gate]) -> list[Candidate]:
|
||||||
"""Every open role of a company this agent has not hidden, copies
|
"""Every open role of a company this agent has not hidden, copies
|
||||||
(`rebuild_dupes`) aside, with the agent's affinity for the company
|
(`rebuild_dupes`) aside, with the agent's affinity for the company,
|
||||||
and how the role meets each gate: 1 match, 0 no match, -1 the column
|
the company's All countries and All roles, and how the role meets
|
||||||
is empty. The gates are evaluated here, in SQL, so a `require` gate is
|
each gate: 1 match, 0 no match, -1 the column is empty. The gates are
|
||||||
the `WHERE` it reads as, written
|
evaluated here, in SQL, so a `require` gate is the `WHERE` it reads
|
||||||
as a column so a gated role keeps its row and reason."""
|
as, written as a column so a gated role keeps its row and reason."""
|
||||||
columns: list[str] = []
|
columns: list[str] = []
|
||||||
params: list[Any] = []
|
params: list[Any] = []
|
||||||
gaz = self.gazetteer()
|
gaz = self.gazetteer()
|
||||||
@@ -2281,31 +2306,41 @@ class Store:
|
|||||||
params += values
|
params += values
|
||||||
columns.append(f"CASE WHEN {empty} THEN -1 {' '.join(whens)} ELSE 0 END AS g{n}")
|
columns.append(f"CASE WHEN {empty} THEN -1 {' '.join(whens)} ELSE 0 END AS g{n}")
|
||||||
select = ", ".join(["r.uid", "r.posted_at",
|
select = ", ".join(["r.uid", "r.posted_at",
|
||||||
"COALESCE(ac.affinity, 0) AS affinity", *columns])
|
"COALESCE(ac.affinity, 0) AS affinity",
|
||||||
|
"COALESCE(c.all_countries, 0) AS all_countries",
|
||||||
|
"COALESCE(c.all_roles, 0) AS all_roles", *columns])
|
||||||
rows = self._rows(
|
rows = self._rows(
|
||||||
f"""SELECT {select} FROM roles r
|
f"""SELECT {select} FROM roles r
|
||||||
LEFT JOIN agent_companies ac
|
LEFT JOIN agent_companies ac
|
||||||
ON ac.company_key = r.company_key AND ac.agent_id = ?
|
ON ac.company_key = r.company_key AND ac.agent_id = ?
|
||||||
|
LEFT JOIN companies c ON c.key = r.company_key
|
||||||
WHERE r.closed_at IS NULL AND r.dup_of IS NULL
|
WHERE r.closed_at IS NULL AND r.dup_of IS NULL
|
||||||
AND COALESCE(ac.affinity, 0) <> -1""",
|
AND COALESCE(ac.affinity, 0) <> -1""",
|
||||||
[*params, agent_id])
|
[*params, agent_id])
|
||||||
return [Candidate(uid=r["uid"], posted_at=r["posted_at"],
|
return [Candidate(uid=r["uid"], posted_at=r["posted_at"],
|
||||||
affinity=int(r["affinity"]),
|
affinity=int(r["affinity"]),
|
||||||
|
all_countries=bool(r["all_countries"]), all_roles=bool(r["all_roles"]),
|
||||||
gates=[int(r[f"g{n}"]) for n in range(len(gates))])
|
gates=[int(r[f"g{n}"]) for n in range(len(gates))])
|
||||||
for r in rows]
|
for r in rows]
|
||||||
|
|
||||||
|
def saved_uids(self) -> set[str]:
|
||||||
|
"""The roles saved (an application names them), which make every
|
||||||
|
agent's cut whatever their levels."""
|
||||||
|
return {r["role_uid"] for r in self._rows(
|
||||||
|
"SELECT DISTINCT role_uid FROM applications WHERE role_uid IS NOT NULL")}
|
||||||
|
|
||||||
def replace_scores(self, agent_id: int,
|
def replace_scores(self, agent_id: int,
|
||||||
rows: Sequence[tuple[str, float, str] | tuple[str, float, str, str]
|
rows: Sequence[tuple[Any, ...]]) -> int:
|
||||||
| tuple[str, float, str, str, float | None]]
|
|
||||||
) -> int:
|
|
||||||
"""`(uid, score, gated_reason)` for every role this agent scored,
|
"""`(uid, score, gated_reason)` for every role this agent scored,
|
||||||
with the name of the prompt that gave the fit as a fourth item ('' when
|
and optionally, in this order, the name of the prompt that gave the
|
||||||
left out) and the role's closeness to the agent's CV as a fifth (None
|
fit ('' when left out), the role's closeness to the agent's CV, its
|
||||||
when left out), replacing whatever it had: a role closed or muted since the last run
|
prompt fit level (both None when left out) and why it is in the cut
|
||||||
drops out rather than keeping a stale score. One transaction, so a
|
('' when left out: not in it). Replaces whatever the agent had: a
|
||||||
reader sees the old list or the new one. An agent deleted while its
|
role closed or muted since the last run drops out rather than keeping
|
||||||
run was scoring gets nothing written and 0 back: its rows are gone
|
a stale score. One transaction, so a reader sees the old list or the
|
||||||
with it, and an insert would only fail the foreign key."""
|
new one. An agent deleted while its run was scoring gets nothing
|
||||||
|
written and 0 back: its rows are gone with it, and an insert would
|
||||||
|
only fail the foreign key."""
|
||||||
stamp = self.now()
|
stamp = self.now()
|
||||||
with self.transaction() as conn:
|
with self.transaction() as conn:
|
||||||
if conn.execute("SELECT 1 FROM agents WHERE id=?", (agent_id,)).fetchone() is None:
|
if conn.execute("SELECT 1 FROM agents WHERE id=?", (agent_id,)).fetchone() is None:
|
||||||
@@ -2313,13 +2348,20 @@ class Store:
|
|||||||
conn.execute("DELETE FROM scores WHERE agent_id=?", (agent_id,))
|
conn.execute("DELETE FROM scores WHERE agent_id=?", (agent_id,))
|
||||||
conn.executemany(
|
conn.executemany(
|
||||||
"""INSERT INTO scores (uid, agent_id, score, gated_reason, prompt, cv_fit,
|
"""INSERT INTO scores (uid, agent_id, score, gated_reason, prompt, cv_fit,
|
||||||
scored_at)
|
fit, cut, scored_at)
|
||||||
VALUES (?,?,?,?,?,?,?)""",
|
VALUES (?,?,?,?,?,?,?,?,?)""",
|
||||||
[(row[0], agent_id, row[1], row[2], row[3] if len(row) > 3 else "",
|
[(row[0], agent_id, row[1], row[2], row[3] if len(row) > 3 else "",
|
||||||
row[4] if len(row) > 4 else None, stamp)
|
row[4] if len(row) > 4 else None, row[5] if len(row) > 5 else None,
|
||||||
|
row[6] if len(row) > 6 else "", stamp)
|
||||||
for row in rows])
|
for row in rows])
|
||||||
return len(rows)
|
return len(rows)
|
||||||
|
|
||||||
|
def cut(self, agent_id: int) -> dict[str, str]:
|
||||||
|
"""`uid -> why` for the roles in one agent's cut: 'fit', 'cv' or
|
||||||
|
'kept'."""
|
||||||
|
return {r["uid"]: str(r["cut"]) for r in self._rows(
|
||||||
|
"SELECT uid, cut FROM scores WHERE agent_id=? AND cut <> ''", (agent_id,))}
|
||||||
|
|
||||||
def scores(self, agent_id: int) -> dict[str, tuple[float, str]]:
|
def scores(self, agent_id: int) -> dict[str, tuple[float, str]]:
|
||||||
"""`uid -> (score, gated_reason)` for one agent."""
|
"""`uid -> (score, gated_reason)` for one agent."""
|
||||||
return {r["uid"]: (float(r["score"]), str(r["gated_reason"]))
|
return {r["uid"]: (float(r["score"]), str(r["gated_reason"]))
|
||||||
|
|||||||
+75
-23
@@ -18,7 +18,7 @@ from app import jobs, places
|
|||||||
from app.config import Config
|
from app.config import Config
|
||||||
from app.models import (
|
from app.models import (
|
||||||
AFFINITY, RUNGS, TRACKS, Agent, Application, Company, CvLanguage, CvLanguages, FetchTerms,
|
AFFINITY, RUNGS, TRACKS, Agent, Application, Company, CvLanguage, CvLanguages, FetchTerms,
|
||||||
Gate, Limits, Prompts, Role, RoleRow,
|
Gate, Limits, Prompts, Role, RoleRow, SavedFilter,
|
||||||
HandReason, ScoredRole, Status, Subscription, Weights, company_key, levels_between,
|
HandReason, ScoredRole, Status, Subscription, Weights, company_key, levels_between,
|
||||||
)
|
)
|
||||||
from app.storage import Store
|
from app.storage import Store
|
||||||
@@ -95,7 +95,8 @@ def _feed_filters(
|
|||||||
empty feed. The three seniority parameters become the levels between
|
empty feed. The three seniority parameters become the levels between
|
||||||
them (`levels_between`), which is what the store filters on. `order=cv`
|
them (`levels_between`), which is what the store filters on. `order=cv`
|
||||||
is the score order with the agent's judged roles first by `cv_score`
|
is the score order with the agent's judged roles first by `cv_score`
|
||||||
(`by_cv`)."""
|
(`by_cv`). A request that names an agent keeps to its fetch gate in
|
||||||
|
every order, newest included (`fetch_gate`), unless `gated`."""
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
if not places.known(token):
|
if not places.known(token):
|
||||||
raise HTTPException(422, f"No place is known as {token!r}.")
|
raise HTTPException(422, f"No place is known as {token!r}.")
|
||||||
@@ -118,6 +119,7 @@ def _feed_filters(
|
|||||||
"tag_mode": tag_mode, "agent": _agent_id(store, agent),
|
"tag_mode": tag_mode, "agent": _agent_id(store, agent),
|
||||||
"by_score": agent is not None and order in ("score", "cv"),
|
"by_score": agent is not None and order in ("score", "cv"),
|
||||||
"by_cv": agent is not None and order == "cv", "gated": gated,
|
"by_cv": agent is not None and order == "cv", "gated": gated,
|
||||||
|
"fetch_gate": agent is not None,
|
||||||
"judged": judged or None, "pay": pay or None, "company_keys": company_keys,
|
"judged": judged or None, "pay": pay or None, "company_keys": company_keys,
|
||||||
"places": tokens, "seniority": list(levels), "seniority_unknown": seniority_unknown,
|
"places": tokens, "seniority": list(levels), "seniority_unknown": seniority_unknown,
|
||||||
"pay_unknown": pay_unknown, "closing": closing}
|
"pay_unknown": pay_unknown, "closing": closing}
|
||||||
@@ -235,14 +237,15 @@ def list_roles(
|
|||||||
`agent` says whose votes, hidden companies and scores are meant. Each
|
`agent` says whose votes, hidden companies and scores are meant. Each
|
||||||
role carries that agent's `vote`; a company it hid is left out unless
|
role carries that agent's `vote`; a company it hid is left out unless
|
||||||
`show_muted` is set; `judged` keeps the liked, the unjudged or the
|
`show_muted` is set; `judged` keeps the liked, the unjudged or the
|
||||||
passed. With `order=score` (the default) the roles are the ones that
|
passed. Every order keeps to the roles that agent's fetch gate passes,
|
||||||
agent scored, best first, carrying `score` and `gated_reason`, a gated
|
a gated one only with `gated=1`: with `order=score` (the default) best
|
||||||
one only with `gated=1`; with `order=newest` every open role, newest
|
first by final score, carrying `score` and `gated_reason`; with
|
||||||
first, with no score; with `order=cv` (CV match) the scored roles
|
`order=newest` newest first, carrying `gated_reason` and no score; with
|
||||||
the agent's `judge` read come first by `cv_score`, the rest after them
|
`order=cv` (CV match) the roles the agent's `judge` read come first by
|
||||||
by score. Without `agent` the default agent's votes and
|
`cv_score`, the rest after them by CV closeness, then score. Without
|
||||||
hidden companies apply, the order is newest and there is no score; with
|
`agent` the default agent's votes and hidden companies apply, the order
|
||||||
no agent at all, every vote is None and nothing is hidden.
|
is newest over every open role and there is no score; with no agent at
|
||||||
|
all, every vote is None and nothing is hidden.
|
||||||
|
|
||||||
`include_read` set false hides a role already marked read. `tags` is
|
`include_read` set false hides a role already marked read. `tags` is
|
||||||
`?tags=a&tags=b`, kept to a role with any of them or, with
|
`?tags=a&tags=b`, kept to a role with any of them or, with
|
||||||
@@ -467,7 +470,7 @@ class StageBody(BaseModel):
|
|||||||
@router.get("/stages")
|
@router.get("/stages")
|
||||||
def list_stages(store: StoreDep, config: ConfigDep) -> list[jobs.stages.Stage]:
|
def list_stages(store: StoreDep, config: ConfigDep) -> list[jobs.stages.Stage]:
|
||||||
"""The stages of a pull with a switch, extract, summarise, judge and
|
"""The stages of a pull with a switch, extract, summarise, judge and
|
||||||
enrich: whether each is on, whether the stored switch or config.yaml says
|
fetch_text: whether each is on, whether the stored switch or config.yaml says
|
||||||
so, its model, and who would answer."""
|
so, its model, and who would answer."""
|
||||||
return jobs.stages.describe(config, store)
|
return jobs.stages.describe(config, store)
|
||||||
|
|
||||||
@@ -778,7 +781,7 @@ def set_affinity(key: str, body: AffinityBody, store: StoreDep,
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise HTTPException(404, f"no such company: {key}") from None
|
raise HTTPException(404, f"no such company: {key}") from None
|
||||||
job = _score_after_change(queue)
|
job = _score_after_change(queue)
|
||||||
jobs.cascade.enrich_after(queue, job)
|
jobs.cascade.fetch_text_after(queue, job)
|
||||||
return AffinityOut(**company.model_dump(), score_job=job.id if job else None)
|
return AffinityOut(**company.model_dump(), score_job=job.id if job else None)
|
||||||
|
|
||||||
|
|
||||||
@@ -804,14 +807,17 @@ class OverrideBody(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Company:
|
def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Company:
|
||||||
"""Switch one of a company's two fetch overrides. On queues a pull right
|
"""Switch one of a company's two overrides of the fetch gate. Either
|
||||||
after, as the other reopening switches do; off queues nothing and asks
|
way the agents' fetch gates change for the roles already stored, so a
|
||||||
nothing first, since no role closes until the next pull reads the board
|
rescore is queued (`_score_after_change`) with the fetch text cascade
|
||||||
with its filters again. 404 for an unknown key."""
|
behind it. On also queues a pull, as the other reopening switches do;
|
||||||
|
off queues no pull, since no role closes until the next pull reads the
|
||||||
|
board with its filters again. 404 for an unknown key."""
|
||||||
try:
|
try:
|
||||||
company = getattr(store, setter)(key, on)
|
company = getattr(store, setter)(key, on)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise HTTPException(404, f"no such company: {key}") from None
|
raise HTTPException(404, f"no such company: {key}") from None
|
||||||
|
jobs.cascade.fetch_text_after(queue, _score_after_change(queue))
|
||||||
if on:
|
if on:
|
||||||
queue.enqueue("pull")
|
queue.enqueue("pull")
|
||||||
return company
|
return company
|
||||||
@@ -821,16 +827,19 @@ def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Comp
|
|||||||
def set_all_countries(key: str, body: OverrideBody, store: StoreDep,
|
def set_all_countries(key: str, body: OverrideBody, store: StoreDep,
|
||||||
queue: QueueDep) -> Company:
|
queue: QueueDep) -> Company:
|
||||||
"""All countries on or off: global, apart from affinity. On, the
|
"""All countries on or off: global, apart from affinity. On, the
|
||||||
company's big boards are read with the agents' wide reach, Europe today,
|
company's roles skip the place part of every agent's fetch gate (the
|
||||||
rather than their places (`app/jobs/reach.py`). See `_override`."""
|
`any` gates, `jobs.score.failed_gates`), and its big boards are read
|
||||||
|
with the agents' wide reach, Europe today, rather than their places
|
||||||
|
(`app/jobs/reach.py`). See `_override`."""
|
||||||
return _override(store, queue, key, body.on, "set_all_countries")
|
return _override(store, queue, key, body.on, "set_all_countries")
|
||||||
|
|
||||||
|
|
||||||
@router.post("/companies/{key}/all-roles")
|
@router.post("/companies/{key}/all-roles")
|
||||||
def set_all_roles(key: str, body: OverrideBody, store: StoreDep, queue: QueueDep) -> Company:
|
def set_all_roles(key: str, body: OverrideBody, store: StoreDep, queue: QueueDep) -> Company:
|
||||||
"""All roles on or off: global, apart from affinity. On, the company's
|
"""All roles on or off: global, apart from affinity. On, the company's
|
||||||
boards are read with no role-type narrowing, no fetch terms today
|
roles skip the role part of every agent's fetch gate, the titles to
|
||||||
(`app/jobs/reach.py`). See `_override`."""
|
leave out (`jobs.score.failed_gates`), and its boards are read with no
|
||||||
|
fetch terms (`app/jobs/reach.py`). See `_override`."""
|
||||||
return _override(store, queue, key, body.on, "set_all_roles")
|
return _override(store, queue, key, body.on, "set_all_roles")
|
||||||
|
|
||||||
|
|
||||||
@@ -1282,7 +1291,7 @@ def cv_languages(body: CvText, config: ConfigDep) -> CvLanguagesOut:
|
|||||||
@router.post("/agents")
|
@router.post("/agents")
|
||||||
def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
|
def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
|
||||||
"""Queues the rescore, which the page's `POST /api/score` after a save
|
"""Queues the rescore, which the page's `POST /api/score` after a save
|
||||||
joins, and the enrich run behind it (`cascade.enrich_after`)."""
|
joins, and the fetch text cascade behind it (`cascade.fetch_text_after`)."""
|
||||||
try:
|
try:
|
||||||
saved = store.save_agent(body.name, body.intent, body.gates, body.weights,
|
saved = store.save_agent(body.name, body.intent, body.gates, body.weights,
|
||||||
body.enabled, agent_id=body.id, limits=body.limits,
|
body.enabled, agent_id=body.id, limits=body.limits,
|
||||||
@@ -1294,13 +1303,56 @@ def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
|
|||||||
raise HTTPException(409, str(exc)) from exc
|
raise HTTPException(409, str(exc)) from exc
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise HTTPException(404, f"no such agent: {body.id}") from None
|
raise HTTPException(404, f"no such agent: {body.id}") from None
|
||||||
jobs.cascade.enrich_after(queue, _score_after_change(queue))
|
jobs.cascade.fetch_text_after(queue, _score_after_change(queue))
|
||||||
return saved
|
return saved
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/agents/{agent_id}", status_code=204)
|
@router.delete("/agents/{agent_id}", status_code=204)
|
||||||
def delete_agent(agent_id: int, store: StoreDep) -> Response:
|
def delete_agent(agent_id: int, store: StoreDep) -> Response:
|
||||||
"""Its prompts, scores, votes and affinities go with it."""
|
"""Its prompts, scores, votes, affinities and saved filters go with it."""
|
||||||
if not store.delete_agent(agent_id):
|
if not store.delete_agent(agent_id):
|
||||||
raise HTTPException(404, f"no such agent: {agent_id}")
|
raise HTTPException(404, f"no such agent: {agent_id}")
|
||||||
return Response(status_code=204)
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------- saved filters
|
||||||
|
|
||||||
|
class FilterBody(BaseModel):
|
||||||
|
#: Checked by `Store.save_filter`, so a blank name is a 422 sentence.
|
||||||
|
name: str
|
||||||
|
#: The feed's query string as `roles.js` `addressFor` writes it, without
|
||||||
|
#: the agent.
|
||||||
|
query: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/agents/{agent_id}/filters")
|
||||||
|
def list_saved_filters(agent_id: int, store: StoreDep) -> list[SavedFilter]:
|
||||||
|
"""The agent's saved filters, by name. 404 for an unknown agent."""
|
||||||
|
if store.agent(agent_id) is None:
|
||||||
|
raise HTTPException(404, f"no such agent: {agent_id}")
|
||||||
|
return store.saved_filters(agent_id)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/agents/{agent_id}/filters", status_code=201)
|
||||||
|
def save_filter(agent_id: int, body: FilterBody, store: StoreDep) -> SavedFilter:
|
||||||
|
"""Save the feed's filters under a name for the agent. 404 for an
|
||||||
|
unknown agent, 422 for an empty name, 409 for a name the agent already
|
||||||
|
has regardless of case. There is no editing: a change is a new one."""
|
||||||
|
if store.agent(agent_id) is None:
|
||||||
|
raise HTTPException(404, f"no such agent: {agent_id}")
|
||||||
|
if not body.name.strip():
|
||||||
|
raise HTTPException(422, "Give the filter a name.")
|
||||||
|
try:
|
||||||
|
return store.save_filter(agent_id, body.name, body.query)
|
||||||
|
except KeyError:
|
||||||
|
raise HTTPException(404, f"no such agent: {agent_id}") from None
|
||||||
|
except ValueError as exc:
|
||||||
|
raise HTTPException(409, f"A filter named {body.name.strip()!r} is already saved.") \
|
||||||
|
from exc
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/filters/{filter_id}", status_code=204)
|
||||||
|
def delete_saved_filter(filter_id: int, store: StoreDep) -> Response:
|
||||||
|
if not store.delete_filter(filter_id):
|
||||||
|
raise HTTPException(404, f"no such saved filter: {filter_id}")
|
||||||
|
return Response(status_code=204)
|
||||||
+44
-44
@@ -66,9 +66,10 @@ extract:
|
|||||||
thinking: off # off | adaptive
|
thinking: off # off | adaptive
|
||||||
|
|
||||||
# About 60 words on a role: what it is, the stack, where, the pay if stated
|
# About 60 words on a role: what it is, the stack, where, the pay if stated
|
||||||
# (app/jobs/summarise.py). Off by default. On, each pull summarises the best
|
# (app/jobs/summarise.py). Off by default. On, each pull summarises the top
|
||||||
# roles of every enabled agent that have none yet, by that agent's limits, so
|
# of every enabled agent's feed that has none yet, the best summarise_top by
|
||||||
# the cost stays bounded however many roles are open. The Summarise button on
|
# final score (its limits), and every role liked or saved, so the cost stays
|
||||||
|
# bounded however many roles are open. The Summarise button on
|
||||||
# a role's page asks for that one role either way. `enabled` is only the
|
# a role's page asks for that one role either way. `enabled` is only the
|
||||||
# default for a fresh database: the switch under Settings, Sources, Runs (or
|
# default for a fresh database: the switch under Settings, Sources, Runs (or
|
||||||
# `app stages summarise on|off`) overrides it and needs no restart.
|
# `app stages summarise on|off`) overrides it and needs no restart.
|
||||||
@@ -81,12 +82,12 @@ summarise:
|
|||||||
# runs summarise when it is on and a model is reachable (app/jobs/cascade.py).
|
# runs summarise when it is on and a model is reachable (app/jobs/cascade.py).
|
||||||
# Only extract reads it.
|
# Only extract reads it.
|
||||||
|
|
||||||
# Each search agent's best roles read against its CV: skills, experience and
|
# Each search agent's cut read against its CV: skills, experience and career 0
|
||||||
# career 0 to 100, a total, and 1 to 3 strengths and gaps (app/jobs/judge.py),
|
# to 100, a total, and 1 to 3 strengths and gaps (app/jobs/judge.py), for the
|
||||||
# for the CV match order on Roles. Off by default. On, each pull judges
|
# CV match order on Roles. Off by default. On, each pull judges the cut of
|
||||||
# the best roles of every enabled agent with a CV, by that agent's judge
|
# every enabled agent with a CV and a prompt, and only the roles not judged
|
||||||
# limits, and only those not judged yet or judged from another CV, prompt,
|
# yet or judged from another CV, prompt, like, avoid or must text, or role
|
||||||
# avoid or must text, or role text. The CV rides in every call, so batches are
|
# text. The CV rides in every call, so batches are
|
||||||
# small. `enabled` is only the default for a fresh database: the switch under
|
# small. `enabled` is only the default for a fresh database: the switch under
|
||||||
# Settings, Sources, Runs (or `app stages judge on|off`) overrides it and needs
|
# Settings, Sources, Runs (or `app stages judge on|off`) overrides it and needs
|
||||||
# no restart. on_ingest is accepted and ignored, as for summarise.
|
# no restart. on_ingest is accepted and ignored, as for summarise.
|
||||||
@@ -96,16 +97,14 @@ judge:
|
|||||||
batch_size: 5 # roles per model call
|
batch_size: 5 # roles per model call
|
||||||
thinking: off # off | adaptive
|
thinking: off # off | adaptive
|
||||||
|
|
||||||
# Reading the best roles on their own pages, for the hosts whose list carries
|
# Fetch text: reading a role's own page, for the hosts whose list carries no
|
||||||
# no text (app/jobs/enrich.py); asks no model. A role is read when it has no
|
# text (app/jobs/fetch_text.py); asks no model. A role is read when it has no
|
||||||
# text and an enabled agent with a prompt ranks it ungated among its best
|
# text and is in the cut of an enabled agent (see limits below), so every role
|
||||||
# `top` and at `min_score` or above. `enabled` is only the default for a fresh
|
# the model reads has its text first. `enabled` is only the default for a
|
||||||
# database: the switch under Settings, Sources, Runs (or `app stages enrich
|
# fresh database: the switch under Settings, Sources, Runs (or `app stages
|
||||||
# on|off`) overrides it and needs no restart.
|
# fetch_text on|off`) overrides it and needs no restart.
|
||||||
enrich:
|
fetch_text:
|
||||||
enabled: true
|
enabled: true
|
||||||
top: 500 # rank depth per agent
|
|
||||||
min_score: 0.5 # 0..1, the score bar
|
|
||||||
per_board: 200 # reads per board and run
|
per_board: 200 # reads per board and run
|
||||||
per_run: 1000 # reads per run
|
per_run: 1000 # reads per run
|
||||||
retry_days: 7 # days before a page that gave no text is read again
|
retry_days: 7 # days before a page that gave no text is read again
|
||||||
@@ -141,30 +140,31 @@ sources: {}
|
|||||||
# search:
|
# search:
|
||||||
# adzuna: {app_id: "...", app_key: "..."}
|
# adzuna: {app_id: "...", app_key: "..."}
|
||||||
|
|
||||||
# Starter search agents, imported once into an empty `agents` table. Each gate
|
# Starter search agents, imported once into an empty `agents` table. The gates
|
||||||
# is {field, values, mode: require|any|prefer, weight}; the any gates are one
|
# are the agent's fetch gate, each {field, values, mode: require|any|exclude}:
|
||||||
# group a role must match one of ("in Denmark, or remote"), and a gate rejects
|
# a require gate is the region, the any gates are one group a role must match
|
||||||
# only a role whose column is filled, since extract fills the rest for the
|
# one of ("in Denmark, or remote"), the place part, and an exclude gate leaves
|
||||||
# roles that rank. Fields are place, country,
|
# out the roles that match one of its values (title: the titles to leave
|
||||||
# remote, seniority, function, salary_min, currency, permit, languages and
|
# out). A gate rejects only a role whose column is filled, since extract fills
|
||||||
# company. weights default to {fit: 0.6, recency: 0.2, affinity: 0.2, taste:
|
# the rest for the roles in the cut. A company set to All countries skips the
|
||||||
# 0.2}; taste is how close a role is to the ones the agent liked minus the
|
# any group, one set to All roles the exclude gates on title. Fields are
|
||||||
# ones it passed. A country is an ISO code, filled from the board's location
|
# place, country, remote, remote_from, seniority, function, salary_min,
|
||||||
# line; EU is a role open anywhere in Europe.
|
# currency, permit, languages, company and title. weights are the final
|
||||||
# limits is how deep into this agent's ranking the model stages read, each a
|
# score's, the feed's order, default {fit: 0.6, recency: 0.2, affinity: 0.2,
|
||||||
# top N (the backstop) and a minimum score (the real stop): extract reads the
|
# taste: 0.2}; taste is how close a role is to the ones the agent liked minus
|
||||||
# best extract_top roles at extract_min or more, summarise the best
|
# the ones it passed. A country is an ISO code, filled from the board's
|
||||||
# summarise_top at summarise_min or more, and judge the best judge_top at
|
# location line; EU is a role open anywhere in Europe.
|
||||||
# judge_min or more for an agent with a CV, and the judge_cv_top ungated roles
|
# limits is the agent's cut, the roles that get fetch text, extract and
|
||||||
# closest to the CV that those leave out. Fit is a calibrated level, so a bar
|
# judge: the best cut_fit_top by fit level at cut_fit_min or more, then the
|
||||||
# means the same in every run: a fresh role with the worst fit scores about
|
# best cut_cv_top by CV closeness at cut_cv_min or more that the first list
|
||||||
# 0.27 on the default weights, a perfect one about 0.87. The defaults are
|
# leaves out, then every role liked or saved. Both levels are calibrated, so
|
||||||
# {extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min:
|
# a minimum means the same in every run, and a liked company's roles sit
|
||||||
# 0.65, judge_top: 150, judge_min: 0.55, judge_cv_top: 50}; measured for "Copenhagen engineering" on 16,841 open roles, 0.55
|
# about 0.05 higher, a favourite's about 0.1. summarise_top is how many of
|
||||||
# admits about 300 roles to extract and 0.65 about 35 to summarise. A wide
|
# the best final scores summarise reads. The defaults are {cut_fit_top: 500,
|
||||||
# monitoring search lowers the bars and raises the counts, a narrow hunt the
|
# cut_fit_min: 0.6, cut_cv_top: 150, cut_cv_min: 0.6, summarise_top: 50}. For
|
||||||
# reverse. An agent without a prompt that has text has no fit and feeds
|
# a broad agent the count stops a list, for a narrow one the minimum. An
|
||||||
# neither stage.
|
# agent without a prompt that has text has no fit, so nothing of it is in
|
||||||
|
# the cut by fit.
|
||||||
# prompts is a list of {name, text}, each what the agent looks for; a role's
|
# prompts is a list of {name, text}, each what the agent looks for; a role's
|
||||||
# fit is its best prompt's, so one agent can hunt several kinds of role
|
# fit is its best prompt's, so one agent can hunt several kinds of role
|
||||||
# without blending them into one paragraph. Votes, gates and limits stay the
|
# without blending them into one paragraph. Votes, gates and limits stay the
|
||||||
@@ -190,7 +190,8 @@ agents: []
|
|||||||
# - {field: country, values: [AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT,
|
# - {field: country, values: [AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT,
|
||||||
# LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, IS, LI, NO,
|
# LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, IS, LI, NO,
|
||||||
# GB, CH, EU], mode: require}
|
# GB, CH, EU], mode: require}
|
||||||
# limits: {extract_top: 1000, extract_min: 0.45, summarise_top: 50, summarise_min: 0.6}
|
# limits: {cut_fit_top: 1000, cut_fit_min: 0.5, cut_cv_top: 150, cut_cv_min: 0.6,
|
||||||
|
# summarise_top: 50}
|
||||||
# - name: Europe hybrid
|
# - name: Europe hybrid
|
||||||
# intent: >-
|
# intent: >-
|
||||||
# Senior backend or platform engineer in a European tech hub, hybrid or
|
# Senior backend or platform engineer in a European tech hub, hybrid or
|
||||||
@@ -199,7 +200,6 @@ agents: []
|
|||||||
# - {field: country, values: [AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT,
|
# - {field: country, values: [AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT,
|
||||||
# LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, IS, LI, NO,
|
# LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE, IS, LI, NO,
|
||||||
# GB, CH, EU], mode: require}
|
# GB, CH, EU], mode: require}
|
||||||
# - {field: remote, values: [hybrid, remote], mode: prefer, weight: 0.05}
|
|
||||||
|
|
||||||
# Starter searches, imported once while there are no `search` subscriptions.
|
# Starter searches, imported once while there are no `search` subscriptions.
|
||||||
# provider is a search reader: jobindex (Denmark, no key: q, area, pages),
|
# provider is a search reader: jobindex (Denmark, no key: q, area, pages),
|
||||||
|
|||||||
+2
-3
@@ -28,8 +28,8 @@ embed:
|
|||||||
sources: {}
|
sources: {}
|
||||||
# The starter ranking, imported once into an empty table. Edit it under
|
# The starter ranking, imported once into an empty table. Edit it under
|
||||||
# Settings, Ranking afterwards; this list is not read again. EU in a country
|
# Settings, Ranking afterwards; this list is not read again. EU in a country
|
||||||
# gate is a role open anywhere in Europe ("Remote - Europe", "EMEA"). How deep
|
# gate is a role open anywhere in Europe ("Remote - Europe", "EMEA"). Which
|
||||||
# into the ranking extract, summarise and judge read is each agent's `limits`, see
|
# roles get fetch text, extract and judge is each agent's cut, its `limits`, see
|
||||||
# config.example.yaml, which has two more agents.
|
# config.example.yaml, which has two more agents.
|
||||||
agents:
|
agents:
|
||||||
- name: Copenhagen engineering
|
- name: Copenhagen engineering
|
||||||
@@ -39,7 +39,6 @@ agents:
|
|||||||
Wants ownership of production systems in a product company.
|
Wants ownership of production systems in a product company.
|
||||||
gates:
|
gates:
|
||||||
- {field: country, values: [DK], mode: require}
|
- {field: country, values: [DK], mode: require}
|
||||||
- {field: remote, values: [hybrid, remote], mode: prefer, weight: 0.05}
|
|
||||||
# Starter searches, imported once while there are none. Each is a query on a
|
# Starter searches, imported once while there are none. Each is a query on a
|
||||||
# job board that spans companies (plugins/search.py); `app searches add` adds
|
# job board that spans companies (plugins/search.py); `app searches add` adds
|
||||||
# more. area 1 is Jobindex's Region Hovedstaden. An adzuna search needs a key:
|
# more. area 1 is Jobindex's Region Hovedstaden. An adzuna search needs a key:
|
||||||
|
|||||||
+3
-3
@@ -37,8 +37,8 @@ whose reader cannot narrow that reach is read whole anyway, and sized by
|
|||||||
that read once it is complete, rather than by a second request.
|
that read once it is complete, rather than by a second request.
|
||||||
|
|
||||||
A pull reads listings only. A host that states a role's text on the role's
|
A pull reads listings only. A host that states a role's text on the role's
|
||||||
own page (`text="detail"`) is read there by `app/jobs/enrich.py` after
|
own page (`text="detail"`) is read there by `app/jobs/fetch_text.py` after
|
||||||
scoring, best roles first, through `read_board_details`. A search provider
|
scoring, for the roles in the agents' cut, through `read_board_details`. A search provider
|
||||||
whose reader has `detail` (Jobbank) is read the same way, under its search
|
whose reader has `detail` (Jobbank) is read the same way, under its search
|
||||||
target `provider:name`; `read_detail` is the one read the Fetch button makes.
|
target `provider:name`; `read_detail` is the one read the Fetch button makes.
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ class ATSSource(Source):
|
|||||||
return f"{host}:{slug}:{source_id}"
|
return f"{host}:{slug}:{source_id}"
|
||||||
|
|
||||||
# A host with `detail` states a role's text on the role's own page,
|
# A host with `detail` states a role's text on the role's own page,
|
||||||
# which the `enrich` stage reads after scoring (`read_board_details`),
|
# which the `fetch_text` stage reads after scoring (`read_board_details`),
|
||||||
# never the pull. Its rows go out without a description, so the text
|
# never the pull. Its rows go out without a description, so the text
|
||||||
# a role's page gave stays, and a role read on its own page goes out
|
# a role's page gave stays, and a role read on its own page goes out
|
||||||
# without the listing's place and remote as well, so what its page
|
# without the listing's place and remote as well, so what its page
|
||||||
|
|||||||
@@ -215,11 +215,11 @@ is shown and embedded until `description` arrives. A reader that sees one
|
|||||||
keeps it.
|
keeps it.
|
||||||
|
|
||||||
**Detail.** `detail(get, slug, row)` reads one role's own page and returns a
|
**Detail.** `detail(get, slug, row)` reads one role's own page and returns a
|
||||||
dict of the fields it found. The pull reads listings only; the `enrich`
|
dict of the fields it found. The pull reads listings only; the `fetch_text`
|
||||||
stage (`app/jobs/enrich.py`) calls `detail` after scoring, so the requests
|
stage (`app/jobs/fetch_text.py`) calls `detail` after scoring, so the
|
||||||
go where the ranking is: the open roles without text that an agent ranks
|
requests go where the model pass will read: the open roles without text in
|
||||||
among its best `enrich.top` at `enrich.min_score` or above, best first, at
|
the cut of an enabled agent, best first, at most `fetch_text.per_board`
|
||||||
most `enrich.per_board` from one board and `enrich.per_run` in all, one
|
from one board and `fetch_text.per_run` in all, one
|
||||||
batch per board through `ats.read_board_details` and
|
batch per board through `ats.read_board_details` and
|
||||||
`_runner.read_details`, `_runner.PAGE_DELAY` apart, the roles never tried
|
`_runner.read_details`, `_runner.PAGE_DELAY` apart, the roles never tried
|
||||||
before those whose read failed. Only `_runner.DETAIL_FIELDS` are taken:
|
before those whose read failed. Only `_runner.DETAIL_FIELDS` are taken:
|
||||||
@@ -230,7 +230,7 @@ any other key is left out with a debug log line, `seniority` among them.
|
|||||||
`title`, `url`, `department` and `salary_text` cannot be filled from
|
`title`, `url`, `department` and `salary_text` cannot be filled from
|
||||||
`detail`: the listing rewrites them every pull. A 404 or a 410 counts as read; any
|
`detail`: the listing rewrites them every pull. A 404 or a 410 counts as read; any
|
||||||
other failure is logged and retried on a later run; a read that gave no text
|
other failure is logged and retried on a later run; a read that gave no text
|
||||||
is retried after `enrich.retry_days`; a 429 ends the reads of that board for
|
is retried after `fetch_text.retry_days`; a 429 ends the reads of that board for
|
||||||
the run. A role read in detail is sent by later pulls without the listing's
|
the run. A role read in detail is sent by later pulls without the listing's
|
||||||
place and remote, so what its own page said about them stays. Completeness
|
place and remote, so what its own page said about them stays. Completeness
|
||||||
is decided by the listing alone.
|
is decided by the listing alone.
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ def test_a_stage_shows_the_model_that_will_answer(tmp_path: Path) -> None:
|
|||||||
config.agent.model = "claude-opus-4-1"
|
config.agent.model = "claude-opus-4-1"
|
||||||
by_name = {s["name"]: s for s in client.get("/api/stages").json()}
|
by_name = {s["name"]: s for s in client.get("/api/stages").json()}
|
||||||
assert by_name["extract"]["model"] == by_name["summarise"]["model"] == "claude-opus-4-1"
|
assert by_name["extract"]["model"] == by_name["summarise"]["model"] == "claude-opus-4-1"
|
||||||
assert by_name["enrich"]["model"] == ""
|
assert by_name["fetch_text"]["model"] == ""
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------- config
|
# ------------------------------------------------------------------- config
|
||||||
@@ -162,7 +162,7 @@ def test_the_example_config_names_every_key_of_the_sections_it_documents() -> No
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
raw = yaml.safe_load((ROOT / "config.example.yaml").read_text("utf-8"))
|
raw = yaml.safe_load((ROOT / "config.example.yaml").read_text("utf-8"))
|
||||||
for name, allowed_missing in (("agent", set()), ("extract", set()), ("enrich", set()),
|
for name, allowed_missing in (("agent", set()), ("extract", set()), ("fetch_text", set()),
|
||||||
("embed", set()), ("workers", set()),
|
("embed", set()), ("workers", set()),
|
||||||
("summarise", {"on_ingest"})): # accepted, ignored
|
("summarise", {"on_ingest"})): # accepted, ignored
|
||||||
fields = set(type(getattr(Config(), name)).model_fields)
|
fields = set(type(getattr(Config(), name)).model_fields)
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ def test_migration_20_seeds_an_old_file_and_leaves_collisions(tmp_path: Path) ->
|
|||||||
"VALUES (?, ?, '', '')", (key, name))
|
"VALUES (?, ?, '', '')", (key, name))
|
||||||
conn.execute("PRAGMA user_version = 19")
|
conn.execute("PRAGMA user_version = 19")
|
||||||
reopened = Store(path)
|
reopened = Store(path)
|
||||||
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
|
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
|
||||||
assert len(reopened.companies()) == 3
|
assert len(reopened.companies()) == 3
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp
|
|||||||
conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
|
conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
|
||||||
conn.execute("PRAGMA user_version = 20")
|
conn.execute("PRAGMA user_version = 20")
|
||||||
reopened = Store(path)
|
reopened = Store(path)
|
||||||
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
# The tag of 21 is All countries and All roles since 24.
|
# The tag of 21 is All countries and All roles since 24.
|
||||||
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
|
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
|
||||||
assert {c.key: c.all_roles for c in reopened.companies()} == tagged
|
assert {c.key: c.all_roles for c in reopened.companies()} == tagged
|
||||||
|
|||||||
@@ -183,10 +183,15 @@ def test_closing_soon_keeps_today_to_four_days_on(client: TestClient, store: Sto
|
|||||||
owner, uid = setup(store)
|
owner, uid = setup(store)
|
||||||
params = {"agent": owner.id, "order": "newest", "closing": 1}
|
params = {"agent": owner.id, "order": "newest", "closing": 1}
|
||||||
page = client.get("/api/roles", params=params).json()
|
page = client.get("/api/roles", params=params).json()
|
||||||
|
# d is gated, so newest leaves it out as every order does.
|
||||||
|
assert sorted(r["uid"] for r in page["items"]) == sorted([uid["a"], uid["b"]])
|
||||||
|
assert page["total"] == 2
|
||||||
|
facets = client.get("/api/roles/facets", params=params).json()
|
||||||
|
assert sum(f["count"] for f in facets["pay"]) == 2
|
||||||
|
params["gated"] = 1
|
||||||
|
page = client.get("/api/roles", params=params).json()
|
||||||
assert sorted(r["uid"] for r in page["items"]) == sorted([uid["a"], uid["b"], uid["d"]])
|
assert sorted(r["uid"] for r in page["items"]) == sorted([uid["a"], uid["b"], uid["d"]])
|
||||||
assert page["total"] == 3
|
assert page["total"] == 3
|
||||||
facets = client.get("/api/roles/facets", params=params).json()
|
|
||||||
assert sum(f["count"] for f in facets["pay"]) == 3
|
|
||||||
|
|
||||||
|
|
||||||
def test_the_role_carries_its_judgement_and_languages(
|
def test_the_role_carries_its_judgement_and_languages(
|
||||||
|
|||||||
+12
-10
@@ -71,9 +71,11 @@ def test_a_cv_language_is_a_code_and_a_level_of_the_ladder() -> None:
|
|||||||
CvLanguage(language="da", level="good")
|
CvLanguage(language="da", level="good")
|
||||||
|
|
||||||
|
|
||||||
def test_new_agents_have_judge_limits_by_default(store: Store) -> None:
|
def test_new_agents_have_the_cut_by_default(store: Store) -> None:
|
||||||
made = store.save_agent("Data")
|
made = store.save_agent("Data")
|
||||||
assert (made.limits.judge_top, made.limits.judge_min) == (150, 0.55)
|
assert made.limits.model_dump() == {"cut_fit_top": 500, "cut_fit_min": 0.6,
|
||||||
|
"cut_cv_top": 150, "cut_cv_min": 0.6,
|
||||||
|
"summarise_top": 50}
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------- migration
|
# --------------------------------------------------------------- migration
|
||||||
@@ -96,7 +98,7 @@ def test_v28_adds_the_cv_columns_and_the_host_deadline_and_runs_twice(tmp_path:
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [28, 29, 30, 31]
|
assert migrated.migrations_applied == [28, 29, 30, 31, 32]
|
||||||
rows = {r["source_id"]: r for r in migrated._rows(
|
rows = {r["source_id"]: r for r in migrated._rows(
|
||||||
"SELECT source_id, languages_required, deadline_host, deadline FROM roles")}
|
"SELECT source_id, languages_required, deadline_host, deadline FROM roles")}
|
||||||
assert (rows["a"]["deadline_host"], rows["a"]["deadline"]) == ("2026-10-18", None)
|
assert (rows["a"]["deadline_host"], rows["a"]["deadline"]) == ("2026-10-18", None)
|
||||||
@@ -108,7 +110,7 @@ def test_v28_adds_the_cv_columns_and_the_host_deadline_and_runs_twice(tmp_path:
|
|||||||
assert migrated.role(posting("a").uid).deadline == "2026-10-18"
|
assert migrated.role(posting("a").uid).deadline == "2026-10-18"
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
conn.execute("PRAGMA user_version = 27")
|
conn.execute("PRAGMA user_version = 27")
|
||||||
assert Store(path).migrations_applied == [28, 29, 30, 31]
|
assert Store(path).migrations_applied == [28, 29, 30, 31, 32]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- deadline
|
# ---------------------------------------------------------------- deadline
|
||||||
@@ -159,7 +161,7 @@ def test_extract_reads_levels_kinds_and_the_deadline(
|
|||||||
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
item = posting("1")
|
item = posting("1")
|
||||||
upsert(store, item)
|
upsert(store, item)
|
||||||
store.replace_scores(store.save_agent("Data", "data").id, [(item.uid, 0.9, "")])
|
store.replace_scores(store.save_agent("Data", "data").id, [(item.uid, 0.9, "", "", None, 0.9, "fit")])
|
||||||
model = Model(lambda roles: [answer(r["uid"], deadline="2026-10-30", languages_required=[
|
model = Model(lambda roles: [answer(r["uid"], deadline="2026-10-30", languages_required=[
|
||||||
{"language": "DA", "level": "fluent", "kind": "required"},
|
{"language": "DA", "level": "fluent", "kind": "required"},
|
||||||
{"language": "en", "level": "", "kind": "required"},
|
{"language": "en", "level": "", "kind": "required"},
|
||||||
@@ -186,7 +188,7 @@ def test_extract_reads_levels_kinds_and_the_deadline(
|
|||||||
def test_a_role_extracted_before_is_read_once_more_for_the_new_fields(store: Store) -> None:
|
def test_a_role_extracted_before_is_read_once_more_for_the_new_fields(store: Store) -> None:
|
||||||
item = posting("1")
|
item = posting("1")
|
||||||
upsert(store, item)
|
upsert(store, item)
|
||||||
store.replace_scores(store.save_agent("Data", "data").id, [(item.uid, 0.9, "")])
|
store.replace_scores(store.save_agent("Data", "data").id, [(item.uid, 0.9, "", "", None, 0.9, "fit")])
|
||||||
store.set_extracted(item.uid, {"seniority": "director"})
|
store.set_extracted(item.uid, {"seniority": "director"})
|
||||||
assert store.extract_pending() == 0
|
assert store.extract_pending() == 0
|
||||||
with store.transaction() as conn:
|
with store.transaction() as conn:
|
||||||
@@ -249,12 +251,12 @@ def test_v29_adds_the_musts_and_broken_columns_and_runs_twice(tmp_path: Path) ->
|
|||||||
conn.execute(f"ALTER TABLE role_judgements DROP COLUMN {column}")
|
conn.execute(f"ALTER TABLE role_judgements DROP COLUMN {column}")
|
||||||
conn.execute("PRAGMA user_version = 28")
|
conn.execute("PRAGMA user_version = 28")
|
||||||
|
|
||||||
assert Store(path).migrations_applied == [29, 30, 31]
|
assert Store(path).migrations_applied == [29, 30, 31, 32]
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
|
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
|
||||||
assert {"musts", "broken"} <= columns
|
assert {"musts", "broken"} <= columns
|
||||||
conn.execute("PRAGMA user_version = 28")
|
conn.execute("PRAGMA user_version = 28")
|
||||||
assert Store(path).migrations_applied == [29, 30, 31]
|
assert Store(path).migrations_applied == [29, 30, 31, 32]
|
||||||
|
|
||||||
|
|
||||||
def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
|
def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
|
||||||
@@ -266,12 +268,12 @@ def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [30, 31]
|
assert migrated.migrations_applied == [30, 31, 32]
|
||||||
[data] = migrated.agents()
|
[data] = migrated.agents()
|
||||||
assert (data.like_text, data.avoid_text) == ("", "Reporting.")
|
assert (data.like_text, data.avoid_text) == ("", "Reporting.")
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
conn.execute("PRAGMA user_version = 29")
|
conn.execute("PRAGMA user_version = 29")
|
||||||
assert Store(path).migrations_applied == [30, 31]
|
assert Store(path).migrations_applied == [30, 31, 32]
|
||||||
|
|
||||||
|
|
||||||
def test_the_musts_text_is_one_must_have_per_line() -> None:
|
def test_the_musts_text_is_one_must_have_per_line() -> None:
|
||||||
|
|||||||
+32
-27
@@ -218,34 +218,39 @@ def window(store: Store) -> list[str]:
|
|||||||
return [row["uid"] for _, row, _, _ in judge.waiting(store)]
|
return [row["uid"] for _, row, _, _ in judge.waiting(store)]
|
||||||
|
|
||||||
|
|
||||||
def test_the_judge_also_reads_the_closest_to_the_cv_the_score_leaves_out(
|
def test_the_cut_takes_the_closest_to_the_cv_the_fit_list_leaves_out_and_judge_reads_it(
|
||||||
store: Store) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
owner = store.save_agent("Data", prompts=[Prompt(name="AI", text="Head of AI")],
|
"""One role in by fit to the prompt, the one closest to the CV that the
|
||||||
cv_text="VP Data.",
|
fit list leaves out by CV closeness, a liked one kept; a gated role is in
|
||||||
limits=Limits(judge_top=2, judge_min=0.5, judge_cv_top=2))
|
no list however close, liked or not."""
|
||||||
top, second, low, near, nearer, nearest_gated, far = ranked(store, owner, [
|
backend = role(store, "1", "Backend Python", "Backend python python.", country="DK")
|
||||||
("top", 0.9, "", 0.1), ("second", 0.8, "", 0.99), ("low", 0.4, "", 0.2),
|
frontend = role(store, "2", "Frontend React", "Frontend react react.", country="DK")
|
||||||
("near", 0.3, "", 0.6), ("nearer", 0.2, "", 0.7), ("gated", 0.0, "country SE", None),
|
data = role(store, "3", "Data", "Data.", country="DK")
|
||||||
("far", 0.1, "", 0.05)])
|
other = role(store, "4", "Data again", "Data data.", country="DK")
|
||||||
assert window(store) == [top, second, nearer, near]
|
gated = role(store, "5", "Frontend React", "Frontend react react.", country="SE")
|
||||||
|
owner = store.save_agent("Data", prompts=[Prompt(name="Backend", text="python backend")],
|
||||||
|
gates=[Gate(field="country", values=["DK"])],
|
||||||
|
cv_text="Frontend react developer.",
|
||||||
|
limits=Limits(cut_fit_top=1, cut_fit_min=0, cut_cv_top=1,
|
||||||
|
cut_cv_min=0))
|
||||||
|
store.set_vote(owner.id, data, 1)
|
||||||
|
store.set_vote(owner.id, gated, 1)
|
||||||
|
run(config, store, embed.run_embed)
|
||||||
|
result = run(config, store, score.run_score)
|
||||||
|
|
||||||
|
assert store.cut(owner.id) == {backend: "fit", frontend: "cv", data: "kept"}
|
||||||
|
assert result["cut"] == 3
|
||||||
|
with store.transaction() as conn:
|
||||||
|
fits = dict(conn.execute("SELECT uid, fit FROM scores WHERE agent_id = ?",
|
||||||
|
(owner.id,)).fetchall())
|
||||||
|
assert fits[backend] > fits[other] and fits[gated] is None
|
||||||
|
assert window(store) == [backend, frontend, data]
|
||||||
|
|
||||||
|
# No count, no list: what is liked is kept all the same.
|
||||||
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
||||||
limits=Limits(judge_top=2, judge_min=0.85, judge_cv_top=2))
|
gates=owner.gates, limits=Limits(cut_fit_top=0, cut_cv_top=0))
|
||||||
assert window(store) == [top, second, nearer], \
|
run(config, store, score.run_score)
|
||||||
"a role under the bar is no part of the first set, so it may come in by the CV"
|
assert store.cut(owner.id) == {data: "kept"}
|
||||||
|
|
||||||
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
|
||||||
limits=Limits(judge_top=2, judge_min=0.5, judge_cv_top=0))
|
|
||||||
assert window(store) == [top, second]
|
|
||||||
assert low and far and nearest_gated
|
|
||||||
|
|
||||||
|
|
||||||
def test_a_gated_role_stays_out_of_the_window_however_close(store: Store) -> None:
|
|
||||||
owner = store.save_agent("Data", prompts=[Prompt(name="AI", text="Head of AI")],
|
|
||||||
cv_text="VP Data.",
|
|
||||||
limits=Limits(judge_top=1, judge_min=0.5, judge_cv_top=5))
|
|
||||||
top, _gated = ranked(store, owner, [("top", 0.9, "", 0.1), ("gated", 0.0, "remote", 1.0)])
|
|
||||||
assert window(store) == [top]
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------- order
|
# ------------------------------------------------------------------- order
|
||||||
@@ -277,7 +282,7 @@ def test_migration_31_adds_the_column_and_the_table_and_runs_twice(tmp_path: Pat
|
|||||||
conn.execute("DROP TABLE agent_cv_vectors")
|
conn.execute("DROP TABLE agent_cv_vectors")
|
||||||
conn.execute("ALTER TABLE scores DROP COLUMN cv_fit")
|
conn.execute("ALTER TABLE scores DROP COLUMN cv_fit")
|
||||||
conn.execute("PRAGMA user_version = 30")
|
conn.execute("PRAGMA user_version = 30")
|
||||||
assert Store(path).migrations_applied == [31]
|
assert Store(path).migrations_applied == [31, 32]
|
||||||
step = {v: s for v, _, s in MIGRATIONS}[31]
|
step = {v: s for v, _, s in MIGRATIONS}[31]
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
assert callable(step)
|
assert callable(step)
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ def test_a_copy_is_left_out_of_the_feed_counts_and_model_stages(store: Store) ->
|
|||||||
assert {r.uid for r in store.roles_to_embed("m", 10)} == {kept.uid, other.uid}
|
assert {r.uid for r in store.roles_to_embed("m", 10)} == {kept.uid, other.uid}
|
||||||
assert store.open_role_counts() == {"sap": 2}
|
assert store.open_role_counts() == {"sap": 2}
|
||||||
assert [count for _, _, count, _ in store.open_companies()] == [2]
|
assert [count for _, _, count, _ in store.open_companies()] == [2]
|
||||||
store.replace_scores(agent.id, [(u, 0.9, "") for u in (kept.uid, copy.uid, other.uid)])
|
store.replace_scores(agent.id, [(u, 0.9, "", "", None, 0.9, "fit")
|
||||||
|
for u in (kept.uid, copy.uid, other.uid)])
|
||||||
assert {r.uid for r in store.extract_waiting(10)} == {kept.uid, other.uid}
|
assert {r.uid for r in store.extract_waiting(10)} == {kept.uid, other.uid}
|
||||||
assert {r.uid for r in store.summarise_waiting(10)} == {kept.uid, other.uid}
|
assert {r.uid for r in store.summarise_waiting(10)} == {kept.uid, other.uid}
|
||||||
|
|
||||||
@@ -278,7 +279,7 @@ def test_a_v17_file_gains_dup_of_with_its_first_rebuild(tmp_path: Path) -> None:
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
|
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
|
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
|
||||||
|
|||||||
+22
-30
@@ -15,7 +15,7 @@ from desk.models import Item
|
|||||||
from desk.tools import agent
|
from desk.tools import agent
|
||||||
from app.config import Config
|
from app.config import Config
|
||||||
from app.jobs import extract
|
from app.jobs import extract
|
||||||
from app.models import LEVELS, Limits
|
from app.models import LEVELS
|
||||||
from app.storage import Store
|
from app.storage import Store
|
||||||
from prepped import upsert
|
from prepped import upsert
|
||||||
|
|
||||||
@@ -61,11 +61,11 @@ def config(tmp_path: Path) -> Config:
|
|||||||
|
|
||||||
|
|
||||||
def ranked(store: Store, *items: Item) -> None:
|
def ranked(store: Store, *items: Item) -> None:
|
||||||
"""Score the roles for one enabled agent, best first, so they are in the
|
"""Score the roles for one enabled agent, best first, each in its cut, so
|
||||||
top extract reads. Every role given must already be stored."""
|
extract reads them. Every role given must already be stored."""
|
||||||
agents = store.agents()
|
agents = store.agents()
|
||||||
agent_id = agents[0].id if agents else store.save_agent("Backend", "python backend").id
|
agent_id = agents[0].id if agents else store.save_agent("Backend", "python backend").id
|
||||||
store.replace_scores(agent_id, [(item.uid, 1.0 - n / 10, "")
|
store.replace_scores(agent_id, [(item.uid, 1.0 - n / 10, "", "", None, None, "fit")
|
||||||
for n, item in enumerate(items)])
|
for n, item in enumerate(items)])
|
||||||
|
|
||||||
|
|
||||||
@@ -167,37 +167,28 @@ def test_an_unknown_uid_is_ignored_and_the_role_left_out_is_charged(
|
|||||||
assert store.extract_pending() == 0, "given up after three unanswered replies"
|
assert store.extract_pending() == 0, "given up after three unanswered replies"
|
||||||
|
|
||||||
|
|
||||||
def test_only_the_best_of_each_agent_above_the_floor_is_read(
|
def test_only_the_cut_of_an_enabled_agent_is_read(
|
||||||
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
"""The bound that keeps extract cheap: the top of an enabled agent's
|
"""The bound that keeps extract cheap: the cut of an enabled agent,
|
||||||
scores, as deep and as low as that agent's own `limits` say, whatever
|
whatever the boards produced. A role in no cut is never sent; a batch
|
||||||
the boards produced. A role nobody ranks is never sent; a batch dealt a
|
dealt a uid finishes it."""
|
||||||
uid finishes it."""
|
for sid in ("best", "kept", "low", "unscored", "gated"):
|
||||||
for sid in ("best", "second", "low", "unscored", "gated"):
|
|
||||||
upsert(store, posting(sid))
|
upsert(store, posting(sid))
|
||||||
one = store.save_agent("One", "python backend",
|
one = store.save_agent("One", "python backend")
|
||||||
limits=Limits(extract_top=1, extract_min=0.5))
|
|
||||||
two = store.save_agent("Two", "python backend", enabled=False)
|
two = store.save_agent("Two", "python backend", enabled=False)
|
||||||
store.replace_scores(one.id, [(posting("best").uid, 0.9, ""),
|
store.replace_scores(one.id, [(posting("best").uid, 0.9, "", "", None, 0.9, "fit"),
|
||||||
(posting("second").uid, 0.8, ""),
|
(posting("kept").uid, 0.3, "", "", None, 0.1, "kept"),
|
||||||
(posting("low").uid, 0.2, ""),
|
(posting("low").uid, 0.2, "", "", None, 0.2, ""),
|
||||||
(posting("gated").uid, 0.95, "country unknown")])
|
(posting("gated").uid, 0.0, "country unknown")])
|
||||||
store.replace_scores(two.id, [(posting("unscored").uid, 0.99, "")])
|
store.replace_scores(two.id, [(posting("unscored").uid, 0.99, "", "", None, 0.99, "fit")])
|
||||||
config = Config(database=str(tmp_path / "x.db"), extract={"enabled": True})
|
config = Config(database=str(tmp_path / "x.db"), extract={"enabled": True})
|
||||||
model = stub(monkeypatch, lambda roles: [answer(r["uid"]) for r in roles])
|
model = stub(monkeypatch, lambda roles: [answer(r["uid"]) for r in roles])
|
||||||
|
|
||||||
assert store.extract_pending() == 1
|
assert store.extract_pending() == 2, "the disabled agent's cut never counts"
|
||||||
store.save_agent("One", "python backend", agent_id=one.id,
|
|
||||||
limits=Limits(extract_top=5, extract_min=0.5))
|
|
||||||
assert store.extract_pending() == 2, "the floor holds the low one back"
|
|
||||||
store.save_agent("One", "python backend", agent_id=one.id,
|
|
||||||
limits=Limits(extract_top=5, extract_min=0))
|
|
||||||
assert store.extract_pending() == 3, "the disabled agent's pick never counts"
|
|
||||||
store.save_agent("One", "python backend", agent_id=one.id,
|
|
||||||
limits=Limits(extract_top=1, extract_min=0.5))
|
|
||||||
modeltask.run(extract.TASK, config, store)
|
modeltask.run(extract.TASK, config, store)
|
||||||
|
|
||||||
assert [[r["uid"] for r in batch] for batch in model.asked] == [[posting("best").uid]]
|
assert [[r["uid"] for r in batch] for batch in model.asked] == [
|
||||||
|
[posting("best").uid, posting("kept").uid]]
|
||||||
assert [r.uid for r in store.extract_waiting(10, uids=[posting("low").uid])] == \
|
assert [r.uid for r in store.extract_waiting(10, uids=[posting("low").uid])] == \
|
||||||
[posting("low").uid], "a dealt uid is read whatever its rank"
|
[posting("low").uid], "a dealt uid is read whatever its rank"
|
||||||
|
|
||||||
@@ -293,9 +284,10 @@ def test_each_agents_best_come_first_then_the_rest(store: Store) -> None:
|
|||||||
upsert(store, item)
|
upsert(store, item)
|
||||||
one = store.save_agent("One", "python backend")
|
one = store.save_agent("One", "python backend")
|
||||||
two = store.save_agent("Two", "python backend")
|
two = store.save_agent("Two", "python backend")
|
||||||
store.replace_scores(one.id, [(items[0].uid, 0.9, ""), (items[1].uid, 0.8, ""),
|
store.replace_scores(one.id, [(items[0].uid, 0.9, "", "", None, None, "fit"),
|
||||||
(items[2].uid, 0.7, "")])
|
(items[1].uid, 0.8, "", "", None, None, "fit"),
|
||||||
store.replace_scores(two.id, [(items[3].uid, 0.6, "")])
|
(items[2].uid, 0.7, "", "", None, None, "cv")])
|
||||||
|
store.replace_scores(two.id, [(items[3].uid, 0.6, "", "", None, None, "kept")])
|
||||||
|
|
||||||
got = [r.uid for r in store.extract_waiting(10)]
|
got = [r.uid for r in store.extract_waiting(10)]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""The `enrich` stage: the best roles without text, read on their own pages
|
"""The `fetch_text` stage: the roles in the cut without text, read on their
|
||||||
after scoring. Which roles and in what order, the budgets, what is stored,
|
own pages after scoring. Which roles and in what order, the budgets, what is
|
||||||
the cascade around it, and what triggers it. No network: a fake host stands
|
stored, the cascade around it, and what triggers it. No network: a fake host
|
||||||
in, answering from a dict."""
|
stands in, answering from a dict."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ if str(ROOT) not in sys.path:
|
|||||||
sys.path.insert(0, str(ROOT))
|
sys.path.insert(0, str(ROOT))
|
||||||
|
|
||||||
from app.config import Config, ServerConfig # noqa: E402
|
from app.config import Config, ServerConfig # noqa: E402
|
||||||
from app.jobs import cascade, embed, enrich, stages # noqa: E402
|
from app.jobs import cascade, embed, fetch_text, stages # noqa: E402
|
||||||
from app.main import create_app # noqa: E402
|
from app.main import create_app # noqa: E402
|
||||||
from app.storage import Store # noqa: E402
|
from app.storage import Store # noqa: E402
|
||||||
from desk.models import Item # noqa: E402
|
from desk.models import Item # noqa: E402
|
||||||
@@ -78,9 +78,9 @@ def store(tmp_path: Path) -> Store:
|
|||||||
return Store(tmp_path / "roledesk.db")
|
return Store(tmp_path / "roledesk.db")
|
||||||
|
|
||||||
|
|
||||||
def config(tmp_path: Path, **enrich_settings: Any) -> Config:
|
def config(tmp_path: Path, **settings: Any) -> Config:
|
||||||
return Config(database=str(tmp_path / "roledesk.db"), embed={"model": "fake"},
|
return Config(database=str(tmp_path / "roledesk.db"), embed={"model": "fake"},
|
||||||
enrich=enrich_settings)
|
fetch_text=settings)
|
||||||
|
|
||||||
|
|
||||||
def board(store: Store, target: str) -> Any:
|
def board(store: Store, target: str) -> Any:
|
||||||
@@ -103,16 +103,20 @@ def role(store: Store, target: str, native: str, *, body: str = "",
|
|||||||
|
|
||||||
|
|
||||||
def scored(store: Store, name: str, scores: dict[str, float], *,
|
def scored(store: Store, name: str, scores: dict[str, float], *,
|
||||||
gated: tuple[str, ...] = ()) -> Any:
|
gated: tuple[str, ...] = (), out: tuple[str, ...] = ()) -> Any:
|
||||||
|
"""An agent whose scores are these, every ungated role in its cut by fit
|
||||||
|
but those in `out`."""
|
||||||
agent = store.save_agent(name, f"{name} python backend")
|
agent = store.save_agent(name, f"{name} python backend")
|
||||||
store.replace_scores(agent.id, [(uid, value, "gated" if uid in gated else "")
|
store.replace_scores(agent.id, [
|
||||||
|
(uid, value, "gated" if uid in gated else "", "", None, value,
|
||||||
|
"" if uid in gated or uid in out else "fit")
|
||||||
for uid, value in scores.items()])
|
for uid, value in scores.items()])
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------- which roles
|
# -------------------------------------------------------------- which roles
|
||||||
|
|
||||||
def test_roles_go_best_first_by_their_best_agent_score(
|
def test_roles_in_the_cut_go_best_first_by_their_best_agent_score(
|
||||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||||
board(store, "fake:acme")
|
board(store, "fake:acme")
|
||||||
board(store, "fake:beta")
|
board(store, "fake:beta")
|
||||||
@@ -121,25 +125,28 @@ def test_roles_go_best_first_by_their_best_agent_score(
|
|||||||
scored(store, "One", {a1: 0.6, a2: 0.9, b1: 0.55})
|
scored(store, "One", {a1: 0.6, a2: 0.9, b1: 0.55})
|
||||||
scored(store, "Two", {a1: 0.95, b1: 0.7})
|
scored(store, "Two", {a1: 0.95, b1: 0.7})
|
||||||
|
|
||||||
assert [(r["uid"], r["score"]) for r in store.enrich_waiting(500, 0.5)] == [
|
assert [(r["uid"], r["score"]) for r in store.fetch_text_waiting()] == [
|
||||||
(a1, 0.95), (a2, 0.9), (b1, 0.7)]
|
(a1, 0.95), (a2, 0.9), (b1, 0.7)]
|
||||||
assert enrich.plan(config(tmp_path), store) == [("fake:acme", [a1, a2]),
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [a1, a2]),
|
||||||
("fake:beta", [b1])]
|
("fake:beta", [b1])]
|
||||||
|
|
||||||
|
|
||||||
def test_a_role_no_agent_ranks_high_enough_gets_no_call(
|
def test_a_role_in_no_cut_gets_no_call(
|
||||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||||
board(store, "fake:acme")
|
board(store, "fake:acme")
|
||||||
low, gated, deep, kept = (role(store, "fake:acme", n) for n in ("1", "2", "3", "4"))
|
low, gated, deep, kept = (role(store, "fake:acme", n) for n in ("1", "2", "3", "4"))
|
||||||
scored(store, "One", {low: 0.4, gated: 0.0, deep: 0.8, kept: 0.9}, gated=(gated,))
|
scored(store, "One", {low: 0.4, gated: 0.0, deep: 0.8, kept: 0.9}, gated=(gated,),
|
||||||
# `top` 1 per agent: only the best ungated role of each agent is in reach.
|
out=(low,))
|
||||||
assert enrich.plan(config(tmp_path, top=1), store) == [("fake:acme", [kept])]
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [kept, deep])]
|
||||||
assert enrich.plan(config(tmp_path), store) == [("fake:acme", [kept, deep])]
|
# In another agent's cut, it is read.
|
||||||
|
scored(store, "Two", {low: 0.4})
|
||||||
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [kept, deep, low])]
|
||||||
|
store.delete_agent(store.agents()[1].id)
|
||||||
# A disabled agent ranks nothing.
|
# A disabled agent ranks nothing.
|
||||||
agent = store.agents()[0]
|
agent = store.agents()[0]
|
||||||
store.save_agent(agent.name, gates=agent.gates, weights=agent.weights, enabled=False,
|
store.save_agent(agent.name, gates=agent.gates, weights=agent.weights, enabled=False,
|
||||||
agent_id=agent.id, limits=agent.limits, prompts=agent.prompts)
|
agent_id=agent.id, limits=agent.limits, prompts=agent.prompts)
|
||||||
assert enrich.plan(config(tmp_path), store) == []
|
assert fetch_text.plan(config(tmp_path), store) == []
|
||||||
|
|
||||||
|
|
||||||
def test_roles_with_text_hosts_without_pages_and_failing_boards_are_left_out(
|
def test_roles_with_text_hosts_without_pages_and_failing_boards_are_left_out(
|
||||||
@@ -152,7 +159,7 @@ def test_roles_with_text_hosts_without_pages_and_failing_boards_are_left_out(
|
|||||||
down = role(store, "fake:down", "1")
|
down = role(store, "fake:down", "1")
|
||||||
store.state["ats:failing:fake:down"] = json.dumps({"since": "2026-09-29", "reason": "500"})
|
store.state["ats:failing:fake:down"] = json.dumps({"since": "2026-09-29", "reason": "500"})
|
||||||
scored(store, "One", {wanted: 0.9, has_text: 0.95, plain: 0.9, down: 0.9})
|
scored(store, "One", {wanted: 0.9, has_text: 0.95, plain: 0.9, down: 0.9})
|
||||||
assert enrich.plan(config(tmp_path), store) == [("fake:acme", [wanted])]
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [wanted])]
|
||||||
|
|
||||||
|
|
||||||
def test_a_role_read_already_waits_for_the_retry_and_a_failed_one_goes_last(
|
def test_a_role_read_already_waits_for_the_retry_and_a_failed_one_goes_last(
|
||||||
@@ -164,7 +171,7 @@ def test_a_role_read_already_waits_for_the_retry_and_a_failed_one_goes_last(
|
|||||||
store.state["ats:detailempty:fake:acme"] = json.dumps({"fake:acme:1": now})
|
store.state["ats:detailempty:fake:acme"] = json.dumps({"fake:acme:1": now})
|
||||||
store.state["ats:detailfailed:fake:acme"] = json.dumps(["fake:acme:2"])
|
store.state["ats:detailfailed:fake:acme"] = json.dumps(["fake:acme:2"])
|
||||||
scored(store, "One", {read: 0.9, failed: 0.8, fresh: 0.6})
|
scored(store, "One", {read: 0.9, failed: 0.8, fresh: 0.6})
|
||||||
assert enrich.plan(config(tmp_path), store) == [("fake:acme", [fresh, failed])]
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [fresh, failed])]
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------ budgets
|
# ------------------------------------------------------------------ budgets
|
||||||
@@ -180,11 +187,11 @@ def test_the_budgets_per_board_and_per_run(
|
|||||||
for n, uid in enumerate(u for pair in zip(acme, beta, strict=True)
|
for n, uid in enumerate(u for pair in zip(acme, beta, strict=True)
|
||||||
for u in pair)})
|
for u in pair)})
|
||||||
|
|
||||||
assert enrich.plan(config(tmp_path, per_board=2), store) == [
|
assert fetch_text.plan(config(tmp_path, per_board=2), store) == [
|
||||||
("fake:acme", acme[:2]), ("fake:beta", beta[:2])]
|
("fake:acme", acme[:2]), ("fake:beta", beta[:2])]
|
||||||
assert enrich.plan(config(tmp_path, per_run=3), store) == [
|
assert fetch_text.plan(config(tmp_path, per_run=3), store) == [
|
||||||
("fake:acme", acme[:2]), ("fake:beta", beta[:1])]
|
("fake:acme", acme[:2]), ("fake:beta", beta[:1])]
|
||||||
assert enrich.plan(config(tmp_path, per_board=1, per_run=5), store) == [
|
assert fetch_text.plan(config(tmp_path, per_board=1, per_run=5), store) == [
|
||||||
("fake:acme", acme[:1]), ("fake:beta", beta[:1])]
|
("fake:acme", acme[:1]), ("fake:beta", beta[:1])]
|
||||||
|
|
||||||
|
|
||||||
@@ -192,12 +199,12 @@ def test_the_stage_off_finds_nothing(
|
|||||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||||
board(store, "fake:acme")
|
board(store, "fake:acme")
|
||||||
scored(store, "One", {role(store, "fake:acme", "1"): 0.9})
|
scored(store, "One", {role(store, "fake:acme", "1"): 0.9})
|
||||||
assert len(enrich.batches(config(tmp_path), store)) == 1
|
assert len(fetch_text.batches(config(tmp_path), store)) == 1
|
||||||
assert enrich.batches(config(tmp_path, enabled=False), store) == []
|
assert fetch_text.batches(config(tmp_path, enabled=False), store) == []
|
||||||
stages.set_stage(store, "enrich", True)
|
stages.set_stage(store, "fetch_text", True)
|
||||||
assert len(enrich.batches(config(tmp_path, enabled=False), store)) == 1
|
assert len(fetch_text.batches(config(tmp_path, enabled=False), store)) == 1
|
||||||
stages.set_stage(store, "enrich", False)
|
stages.set_stage(store, "fetch_text", False)
|
||||||
assert enrich.batches(config(tmp_path), store) == []
|
assert fetch_text.batches(config(tmp_path), store) == []
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------ what is stored
|
# ------------------------------------------------------------ what is stored
|
||||||
@@ -209,7 +216,7 @@ def test_a_batch_stores_what_the_pages_filled_and_drops_those_vectors(
|
|||||||
store.put_vectors("fake", [(uid, np.ones(3, dtype=np.float32)) for uid in (one, two, gone)])
|
store.put_vectors("fake", [(uid, np.ones(3, dtype=np.float32)) for uid in (one, two, gone)])
|
||||||
web["answers"].update({f"{BASE}/acme/1": b"Python in full", f"{BASE}/acme/2": b"Go too"})
|
web["answers"].update({f"{BASE}/acme/1": b"Python in full", f"{BASE}/acme/2": b"Go too"})
|
||||||
|
|
||||||
out = enrich.run_batch(config(tmp_path), store, target="fake:acme", uids=[two, gone, one])
|
out = fetch_text.run_batch(config(tmp_path), store, target="fake:acme", uids=[two, gone, one])
|
||||||
|
|
||||||
assert out == {"target": "fake:acme", "read": 3, "filled": 2, "texts": 2}
|
assert out == {"target": "fake:acme", "read": 3, "filled": 2, "texts": 2}
|
||||||
assert web["asked"] == [f"{BASE}/acme/2", f"{BASE}/acme/3", f"{BASE}/acme/1"]
|
assert web["asked"] == [f"{BASE}/acme/2", f"{BASE}/acme/3", f"{BASE}/acme/1"]
|
||||||
@@ -235,7 +242,7 @@ def test_a_board_switched_off_since_the_plan_reads_nothing(
|
|||||||
sub = board(store, "fake:acme")
|
sub = board(store, "fake:acme")
|
||||||
uid = role(store, "fake:acme", "1")
|
uid = role(store, "fake:acme", "1")
|
||||||
store.update_subscription(sub.id, fetch=0)
|
store.update_subscription(sub.id, fetch=0)
|
||||||
assert enrich.run_batch(config(tmp_path), store, target="fake:acme", uids=[uid])["filled"] == 0
|
assert fetch_text.run_batch(config(tmp_path), store, target="fake:acme", uids=[uid])["filled"] == 0
|
||||||
assert web["asked"] == []
|
assert web["asked"] == []
|
||||||
|
|
||||||
|
|
||||||
@@ -273,15 +280,15 @@ def test_a_search_whose_reader_has_detail_is_planned_like_a_board(
|
|||||||
f = role(store, "fake:acme", "1")
|
f = role(store, "fake:acme", "1")
|
||||||
scored(store, "One", {a: 0.9, b: 0.6, j: 0.95, f: 0.7})
|
scored(store, "One", {a: 0.9, b: 0.6, j: 0.95, f: 0.7})
|
||||||
|
|
||||||
assert enrich.plan(config(tmp_path), store) == [("jobbank:cph", [a, b]), ("fake:acme", [f])]
|
assert fetch_text.plan(config(tmp_path), store) == [("jobbank:cph", [a, b]), ("fake:acme", [f])]
|
||||||
# The budgets are a board's: `per_board` and `per_run` count the search as one.
|
# The budgets are a board's: `per_board` and `per_run` count the search as one.
|
||||||
assert enrich.plan(config(tmp_path, per_board=1), store) == [("jobbank:cph", [a]),
|
assert fetch_text.plan(config(tmp_path, per_board=1), store) == [("jobbank:cph", [a]),
|
||||||
("fake:acme", [f])]
|
("fake:acme", [f])]
|
||||||
assert enrich.plan(config(tmp_path, per_run=2), store) == [("jobbank:cph", [a]),
|
assert fetch_text.plan(config(tmp_path, per_run=2), store) == [("jobbank:cph", [a]),
|
||||||
("fake:acme", [f])]
|
("fake:acme", [f])]
|
||||||
# A failing search is left out, as a failing board is.
|
# A failing search is left out, as a failing board is.
|
||||||
store.state["search:failing:jobbank:cph"] = "{}"
|
store.state["search:failing:jobbank:cph"] = "{}"
|
||||||
assert enrich.plan(config(tmp_path), store) == [("fake:acme", [f])]
|
assert fetch_text.plan(config(tmp_path), store) == [("fake:acme", [f])]
|
||||||
|
|
||||||
|
|
||||||
def test_a_search_role_read_waits_for_the_retry_and_a_failed_one_goes_last(
|
def test_a_search_role_read_waits_for_the_retry_and_a_failed_one_goes_last(
|
||||||
@@ -296,7 +303,7 @@ def test_a_search_role_read_waits_for_the_retry_and_a_failed_one_goes_last(
|
|||||||
"jobbank:cph:2": "2020-01-01T00:00:00+00:00"})
|
"jobbank:cph:2": "2020-01-01T00:00:00+00:00"})
|
||||||
|
|
||||||
# 1 gave no text a moment ago and waits; 2 failed and is due, after 3.
|
# 1 gave no text a moment ago and waits; 2 failed and is due, after 3.
|
||||||
assert enrich.plan(config(tmp_path), store) == [("jobbank:cph", [three, two])]
|
assert fetch_text.plan(config(tmp_path), store) == [("jobbank:cph", [three, two])]
|
||||||
|
|
||||||
|
|
||||||
def test_a_batch_reads_a_search_roles_page_and_stores_its_text(
|
def test_a_batch_reads_a_search_roles_page_and_stores_its_text(
|
||||||
@@ -306,7 +313,7 @@ def test_a_batch_reads_a_search_roles_page_and_stores_its_text(
|
|||||||
store.put_vectors("fake", [(uid, np.ones(3, dtype=np.float32))])
|
store.put_vectors("fake", [(uid, np.ones(3, dtype=np.float32))])
|
||||||
web["answers"][AD_URL] = AD
|
web["answers"][AD_URL] = AD
|
||||||
|
|
||||||
out = enrich.run_batch(config(tmp_path), store, target="jobbank:cph", uids=[uid])
|
out = fetch_text.run_batch(config(tmp_path), store, target="jobbank:cph", uids=[uid])
|
||||||
|
|
||||||
assert out == {"target": "jobbank:cph", "read": 1, "filled": 1, "texts": 1}
|
assert out == {"target": "jobbank:cph", "read": 1, "filled": 1, "texts": 1}
|
||||||
assert web["asked"] == [AD_URL]
|
assert web["asked"] == [AD_URL]
|
||||||
@@ -318,14 +325,14 @@ def test_a_batch_reads_a_search_roles_page_and_stores_its_text(
|
|||||||
assert json.loads(store.state["ats:detailed:jobbank:cph"]) == ["jobbank:cph:1234"]
|
assert json.loads(store.state["ats:detailed:jobbank:cph"]) == ["jobbank:cph:1234"]
|
||||||
# Read, it is not planned again, and has no text left to wait for.
|
# Read, it is not planned again, and has no text left to wait for.
|
||||||
scored(store, "One", {uid: 0.9})
|
scored(store, "One", {uid: 0.9})
|
||||||
assert enrich.plan(config(tmp_path), store) == []
|
assert fetch_text.plan(config(tmp_path), store) == []
|
||||||
|
|
||||||
|
|
||||||
def test_a_search_batch_counts_a_404_as_read_as_a_board_does(
|
def test_a_search_batch_counts_a_404_as_read_as_a_board_does(
|
||||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||||
search(store)
|
search(store)
|
||||||
one, two = search_role(store, "jobbank:cph", "1"), search_role(store, "jobbank:cph", "2")
|
one, two = search_role(store, "jobbank:cph", "1"), search_role(store, "jobbank:cph", "2")
|
||||||
out = enrich.run_batch(config(tmp_path), store, target="jobbank:cph", uids=[one, two])
|
out = fetch_text.run_batch(config(tmp_path), store, target="jobbank:cph", uids=[one, two])
|
||||||
assert out["filled"] == 0 and out["read"] == 2
|
assert out["filled"] == 0 and out["read"] == 2
|
||||||
assert json.loads(store.state["ats:detailed:jobbank:cph"]) == [
|
assert json.loads(store.state["ats:detailed:jobbank:cph"]) == [
|
||||||
"jobbank:cph:1", "jobbank:cph:2"]
|
"jobbank:cph:1", "jobbank:cph:2"]
|
||||||
@@ -356,20 +363,21 @@ class _Context:
|
|||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
def test_nothing_filled_passes_over_the_prep_embed_and_score_behind_enrich() -> None:
|
def test_nothing_filled_passes_over_the_prep_embed_and_score_behind_fetch_text() -> None:
|
||||||
context = _Context()
|
context = _Context()
|
||||||
empty = Tally(results=({"filled": 0},))
|
empty = Tally(results=({"filled": 0},))
|
||||||
out = cascade.step(None, None, empty, {"cascade": "pull", "task": "enrich", "at": 4},
|
out = cascade.step(None, None, empty, {"cascade": "pull", "task": "fetch_text", "at": 4},
|
||||||
context=context)
|
context=context)
|
||||||
assert out["next"] == "extract" and context.made[0].carries["at"] == 8
|
assert out["next"] == "extract" and context.made[0].carries["at"] == 8
|
||||||
|
|
||||||
out = cascade.step(None, None, Tally(results=({"filled": 2}, {"filled": 0})),
|
out = cascade.step(None, None, Tally(results=({"filled": 2}, {"filled": 0})),
|
||||||
{"cascade": "pull", "task": "enrich", "at": 4}, context=context)
|
{"cascade": "pull", "task": "fetch_text", "at": 4}, context=context)
|
||||||
assert out["next"] == "prep" and context.made[1].carries["at"] == 5
|
assert out["next"] == "prep" and context.made[1].carries["at"] == 5
|
||||||
|
|
||||||
out = cascade.step(None, None, empty, {"cascade": "enrich", "task": "enrich", "at": 0},
|
out = cascade.step(None, None, empty,
|
||||||
|
{"cascade": "fetch_text", "task": "fetch_text", "at": 0},
|
||||||
context=context)
|
context=context)
|
||||||
assert out["next"] == "judge" and context.made[2].carries["at"] == 4
|
assert out["next"] == "extract" and context.made[2].carries["at"] == 4
|
||||||
|
|
||||||
|
|
||||||
class _Embedder:
|
class _Embedder:
|
||||||
@@ -378,28 +386,28 @@ class _Embedder:
|
|||||||
for t in texts])
|
for t in texts])
|
||||||
|
|
||||||
|
|
||||||
def test_the_enrich_job_reads_the_pages_then_embeds_and_scores_those_roles(
|
def test_the_fetch_text_job_reads_the_pages_then_embeds_and_scores_those_roles(
|
||||||
store: Store, tmp_path: Path, web: dict[str, Any],
|
store: Store, tmp_path: Path, web: dict[str, Any],
|
||||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
monkeypatch.setattr(embed, "load_embedder", lambda model: _Embedder())
|
monkeypatch.setattr(embed, "load_embedder", lambda model: _Embedder())
|
||||||
board(store, "fake:acme")
|
board(store, "fake:acme")
|
||||||
one, two = role(store, "fake:acme", "1"), role(store, "fake:acme", "2")
|
one, two = role(store, "fake:acme", "1"), role(store, "fake:acme", "2")
|
||||||
store.put_vectors("fake", [(uid, np.ones(2, dtype=np.float32)) for uid in (one, two)])
|
store.put_vectors("fake", [(uid, np.ones(2, dtype=np.float32)) for uid in (one, two)])
|
||||||
agent = scored(store, "One", {one: 0.9, two: 0.1})
|
agent = scored(store, "One", {one: 0.9, two: 0.1}, out=(two,))
|
||||||
web["answers"][f"{BASE}/acme/1"] = b"Python in full"
|
web["answers"][f"{BASE}/acme/1"] = b"Python in full"
|
||||||
queue = JobQueue(Jobs(tmp_path / "roledesk.db"), config(tmp_path), store,
|
queue = JobQueue(Jobs(tmp_path / "roledesk.db"), config(tmp_path), store,
|
||||||
workers={"cpu": 1, "http": 1, "llm": 1})
|
workers={"cpu": 1, "http": 1, "llm": 1})
|
||||||
|
|
||||||
started = queue.enqueue("enrich")
|
started = queue.enqueue("fetch_text")
|
||||||
queue.drain(timeout=60)
|
queue.drain(timeout=60)
|
||||||
|
|
||||||
assert started is not None
|
assert started is not None
|
||||||
jobs = sorted(queue.jobs.of_cascade(queue.jobs.last(enrich.KIND).cascade_id), # type: ignore[union-attr]
|
jobs = sorted(queue.jobs.of_cascade(queue.jobs.last(fetch_text.KIND).cascade_id), # type: ignore[union-attr]
|
||||||
key=lambda j: j.id)
|
key=lambda j: j.id)
|
||||||
assert [j.result.get("task") for j in jobs if j.kind == FINAL] == \
|
assert [j.result.get("task") for j in jobs if j.kind == FINAL] == \
|
||||||
["enrich", "prep", "embed", "score", "judge"]
|
["fetch_text", "prep", "embed", "score", "extract", "score", "judge", "summarise"]
|
||||||
assert [j.kind for j in jobs if j.kind != FINAL] == \
|
assert [j.kind for j in jobs if j.kind != FINAL] == \
|
||||||
["enrich", enrich.KIND, "prep", "embed", "score"]
|
["fetch_text", fetch_text.KIND, "prep", "embed", "score", "score"]
|
||||||
assert web["asked"] == [f"{BASE}/acme/1"]
|
assert web["asked"] == [f"{BASE}/acme/1"]
|
||||||
embedded = next(j for j in jobs if j.kind == "embed")
|
embedded = next(j for j in jobs if j.kind == "embed")
|
||||||
assert embedded.result["embedded"] == 1
|
assert embedded.result["embedded"] == 1
|
||||||
@@ -424,43 +432,43 @@ def client(app: FastAPI) -> Iterator[TestClient]:
|
|||||||
ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
|
ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
|
||||||
|
|
||||||
|
|
||||||
def _enrich_behind_a_score(queue: Any) -> Any:
|
def _fetch_text_behind_a_score(queue: Any) -> Any:
|
||||||
found = queue.jobs.last("enrich", states=ANY_STATE)
|
found = queue.jobs.last("fetch_text", states=ANY_STATE)
|
||||||
assert found is not None
|
assert found is not None
|
||||||
assert [queue.jobs.get(i).kind for i in found.depends_on] == ["score"]
|
assert [queue.jobs.get(i).kind for i in found.depends_on] == ["score"]
|
||||||
assert found.after == "done"
|
assert found.after == "done"
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
|
||||||
def test_saving_an_agent_queues_a_score_then_enrich(client: TestClient, app: FastAPI) -> None:
|
def test_saving_an_agent_queues_a_score_then_fetch_text(client: TestClient, app: FastAPI) -> None:
|
||||||
res = client.post("/api/agents", json={"name": "Backend", "intent": "python backend"})
|
res = client.post("/api/agents", json={"name": "Backend", "intent": "python backend"})
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
_enrich_behind_a_score(app.state.queue)
|
_fetch_text_behind_a_score(app.state.queue)
|
||||||
res = client.post("/api/agents", json={"id": res.json()["id"], "name": "Backend",
|
res = client.post("/api/agents", json={"id": res.json()["id"], "name": "Backend",
|
||||||
"intent": "go backend"})
|
"intent": "go backend"})
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_a_company_affinity_queues_a_score_then_enrich(
|
def test_a_company_affinity_queues_a_score_then_fetch_text(
|
||||||
client: TestClient, app: FastAPI) -> None:
|
client: TestClient, app: FastAPI) -> None:
|
||||||
store: Store = app.state.store
|
store: Store = app.state.store
|
||||||
store.save_agent("Backend", "python backend")
|
store.save_agent("Backend", "python backend")
|
||||||
store.add_company("Acme")
|
store.add_company("Acme")
|
||||||
res = client.post("/api/companies/acme/affinity", json={"affinity": 2})
|
res = client.post("/api/companies/acme/affinity", json={"affinity": 2})
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
found = _enrich_behind_a_score(app.state.queue)
|
found = _fetch_text_behind_a_score(app.state.queue)
|
||||||
assert found.depends_on == [res.json()["score_job"]]
|
assert found.depends_on == [res.json()["score_job"]]
|
||||||
|
|
||||||
|
|
||||||
def test_one_score_is_one_enrich(app: FastAPI) -> None:
|
def test_one_score_is_one_fetch_text(app: FastAPI) -> None:
|
||||||
queue = app.state.queue
|
queue = app.state.queue
|
||||||
score = queue.enqueue("score")
|
score = queue.enqueue("score")
|
||||||
first = cascade.enrich_after(queue, score)
|
first = cascade.fetch_text_after(queue, score)
|
||||||
assert cascade.enrich_after(queue, score).id == first.id
|
assert cascade.fetch_text_after(queue, score).id == first.id
|
||||||
assert cascade.enrich_after(queue, None) is None
|
assert cascade.fetch_text_after(queue, None) is None
|
||||||
|
|
||||||
|
|
||||||
def test_a_vote_queues_neither_score_nor_enrich(client: TestClient, app: FastAPI) -> None:
|
def test_a_vote_queues_neither_score_nor_fetch_text(client: TestClient, app: FastAPI) -> None:
|
||||||
store: Store = app.state.store
|
store: Store = app.state.store
|
||||||
store.save_agent("Backend", "python backend")
|
store.save_agent("Backend", "python backend")
|
||||||
item = Item(source_id="fake:acme:1", location=f"{BASE}/acme/1", title="Backend Engineer",
|
item = Item(source_id="fake:acme:1", location=f"{BASE}/acme/1", title="Backend Engineer",
|
||||||
@@ -472,5 +480,5 @@ def test_a_vote_queues_neither_score_nor_enrich(client: TestClient, app: FastAPI
|
|||||||
assert client.delete(f"/api/roles/{item.uid}/vote").status_code == 200
|
assert client.delete(f"/api/roles/{item.uid}/vote").status_code == 200
|
||||||
|
|
||||||
queue = app.state.queue
|
queue = app.state.queue
|
||||||
assert queue.jobs.last("enrich", states=ANY_STATE) is None
|
assert queue.jobs.last("fetch_text", states=ANY_STATE) is None
|
||||||
assert queue.jobs.last("score", states=ANY_STATE) is None
|
assert queue.jobs.last("score", states=ANY_STATE) is None
|
||||||
@@ -440,7 +440,6 @@ EUROPE_DK_SE = [
|
|||||||
Gate(field="country", values=["DK", "SE"], mode="any"),
|
Gate(field="country", values=["DK", "SE"], mode="any"),
|
||||||
Gate(field="remote", values=["remote"], mode="any"),
|
Gate(field="remote", values=["remote"], mode="any"),
|
||||||
Gate(field="place", values=["Malmö", "copenhagen"], mode="any"),
|
Gate(field="place", values=["Malmö", "copenhagen"], mode="any"),
|
||||||
Gate(field="remote", values=["hybrid"], mode="prefer", weight=0.05),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-14
@@ -14,7 +14,7 @@ import pytest
|
|||||||
|
|
||||||
from app.config import Config
|
from app.config import Config
|
||||||
from app.jobs import judge, stages
|
from app.jobs import judge, stages
|
||||||
from app.models import CvLanguage, Limits, Prompt
|
from app.models import CvLanguage, Prompt
|
||||||
from app.storage import Store
|
from app.storage import Store
|
||||||
from desk import modeltask
|
from desk import modeltask
|
||||||
from desk.models import Item
|
from desk.models import Item
|
||||||
@@ -85,7 +85,8 @@ def ranked(store: Store, owner: Any, *ids: str) -> list[str]:
|
|||||||
for sid in ids:
|
for sid in ids:
|
||||||
store.upsert_role(posting(sid))
|
store.upsert_role(posting(sid))
|
||||||
uids.append(posting(sid).uid)
|
uids.append(posting(sid).uid)
|
||||||
store.replace_scores(owner.id, [(uid, 0.9 - n / 100, "") for n, uid in enumerate(uids)])
|
store.replace_scores(owner.id, [(uid, 0.9 - n / 100, "", "", None, 0.9 - n / 100, "fit")
|
||||||
|
for n, uid in enumerate(uids)])
|
||||||
return uids
|
return uids
|
||||||
|
|
||||||
|
|
||||||
@@ -192,20 +193,27 @@ def test_only_enabled_agents_with_a_cv_and_a_prompt_are_judged(store: Store) ->
|
|||||||
assert judge.waiting(store) == []
|
assert judge.waiting(store) == []
|
||||||
|
|
||||||
|
|
||||||
def test_the_agents_judge_limits_bound_what_is_read(store: Store) -> None:
|
def test_the_agents_cut_is_what_is_read_by_fit_then_cv_then_kept(store: Store) -> None:
|
||||||
owner = hunter(store, limits=Limits(judge_top=2, judge_min=0.885))
|
owner = hunter(store)
|
||||||
uids = ranked(store, owner, "a", "b", "c")
|
for sid in "abcdef":
|
||||||
assert [row["uid"] for _, row, _, _ in judge.waiting(store)] == uids[:2]
|
store.upsert_role(posting(sid))
|
||||||
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
uid = {sid: posting(sid).uid for sid in "abcdef"}
|
||||||
limits=Limits(judge_top=2, judge_min=0.895))
|
store.replace_scores(owner.id, [
|
||||||
assert [row["uid"] for _, row, _, _ in judge.waiting(store)] == uids[:1]
|
(uid["a"], 0.5, "", "", 0.9, 0.5, "kept"),
|
||||||
|
(uid["b"], 0.6, "", "", 0.7, 0.4, "cv"),
|
||||||
|
(uid["c"], 0.7, "", "", 0.1, 0.7, "fit"),
|
||||||
|
(uid["d"], 0.8, "", "", 0.1, 0.8, "fit"),
|
||||||
|
(uid["e"], 0.9, "", "", 0.9, 0.9, ""),
|
||||||
|
(uid["f"], 0.9, "", "", 0.8, 0.3, "cv")])
|
||||||
|
assert [row["uid"] for _, row, _, _ in judge.waiting(store)] == [
|
||||||
|
uid["d"], uid["c"], uid["f"], uid["b"], uid["a"]]
|
||||||
|
|
||||||
|
|
||||||
def test_a_role_without_text_is_not_judged(store: Store) -> None:
|
def test_a_role_without_text_is_not_judged(store: Store) -> None:
|
||||||
owner = hunter(store)
|
owner = hunter(store)
|
||||||
item = posting("empty", body="")
|
item = posting("empty", body="")
|
||||||
store.upsert_role(item)
|
store.upsert_role(item)
|
||||||
store.replace_scores(owner.id, [(item.uid, 0.9, "")])
|
store.replace_scores(owner.id, [(item.uid, 0.9, "", "", None, 0.9, "fit")])
|
||||||
assert judge.waiting(store) == []
|
assert judge.waiting(store) == []
|
||||||
|
|
||||||
|
|
||||||
@@ -218,7 +226,7 @@ def test_a_judgement_is_read_again_only_when_what_it_read_changed(
|
|||||||
assert judge.pending(store) == 0
|
assert judge.pending(store) == 0
|
||||||
|
|
||||||
# A rescore and the role closing leave it be.
|
# A rescore and the role closing leave it be.
|
||||||
store.replace_scores(owner.id, [(uid, 0.8, "")])
|
store.replace_scores(owner.id, [(uid, 0.8, "", "", None, 0.8, "fit")])
|
||||||
assert judge.pending(store) == 0
|
assert judge.pending(store) == 0
|
||||||
with store.transaction() as conn:
|
with store.transaction() as conn:
|
||||||
conn.execute("UPDATE roles SET closed_at = '2026-10-01' WHERE uid = ?", (uid,))
|
conn.execute("UPDATE roles SET closed_at = '2026-10-01' WHERE uid = ?", (uid,))
|
||||||
@@ -274,7 +282,7 @@ def test_a_batch_holds_one_agents_pairs_with_that_agents_profile(
|
|||||||
first = hunter(store, "First", cv="First CV.")
|
first = hunter(store, "First", cv="First CV.")
|
||||||
second = hunter(store, "Second", cv="Second CV.")
|
second = hunter(store, "Second", cv="Second CV.")
|
||||||
shared = ranked(store, first, "a", "b")
|
shared = ranked(store, first, "a", "b")
|
||||||
store.replace_scores(second.id, [(uid, 0.9, "") for uid in shared])
|
store.replace_scores(second.id, [(uid, 0.9, "", "", None, 0.9, "fit") for uid in shared])
|
||||||
model = stub(monkeypatch)
|
model = stub(monkeypatch)
|
||||||
|
|
||||||
modeltask.run(judge.TASK, config, store)
|
modeltask.run(judge.TASK, config, store)
|
||||||
@@ -295,7 +303,7 @@ def test_the_finder_cuts_per_agent_and_finds_nothing_while_the_switch_is_off(
|
|||||||
first = hunter(store, "First")
|
first = hunter(store, "First")
|
||||||
second = hunter(store, "Second")
|
second = hunter(store, "Second")
|
||||||
uids = ranked(store, first, *"abcdefg")
|
uids = ranked(store, first, *"abcdefg")
|
||||||
store.replace_scores(second.id, [(uids[0], 0.9, "")])
|
store.replace_scores(second.id, [(uids[0], 0.9, "", "", None, 0.9, "fit")])
|
||||||
found = judge.judge_task().finder(config, store)
|
found = judge.judge_task().finder(config, store)
|
||||||
assert [len(b.payload["uids"]) for b in found] == [5, 2, 1]
|
assert [len(b.payload["uids"]) for b in found] == [5, 2, 1]
|
||||||
assert found[0].label == "Judging 5 roles for First, 1 of 3"
|
assert found[0].label == "Judging 5 roles for First, 1 of 3"
|
||||||
@@ -309,7 +317,7 @@ def test_a_job_given_two_agents_keys_asks_once_for_each(
|
|||||||
first = hunter(store, "First", cv="First CV.")
|
first = hunter(store, "First", cv="First CV.")
|
||||||
second = hunter(store, "Second", cv="Second CV.")
|
second = hunter(store, "Second", cv="Second CV.")
|
||||||
[uid] = ranked(store, first, "a")
|
[uid] = ranked(store, first, "a")
|
||||||
store.replace_scores(second.id, [(uid, 0.9, "")])
|
store.replace_scores(second.id, [(uid, 0.9, "", "", None, 0.9, "fit")])
|
||||||
model = stub(monkeypatch)
|
model = stub(monkeypatch)
|
||||||
|
|
||||||
result = judge.run_batch(config, store, uids=[f"{first.id}:{uid}", f"{second.id}:{uid}"])
|
result = judge.run_batch(config, store, uids=[f"{first.id}:{uid}", f"{second.id}:{uid}"])
|
||||||
|
|||||||
+1
-1
@@ -316,7 +316,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
one = row(migrated, "1")
|
one = row(migrated, "1")
|
||||||
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
|
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
|
||||||
one["country_host"]) == ("senior", "full_time", "true", "DK")
|
one["country_host"]) == ("senior", "full_time", "true", "DK")
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ def test_extract_reads_the_area_once_more_and_maps_the_role_before_the_rescore(
|
|||||||
uid = add(store, "1", "Freiburg, Germany", board="ashby", remote="OnSite")
|
uid = add(store, "1", "Freiburg, Germany", board="ashby", remote="OnSite")
|
||||||
prep.run(store, dupes=False)
|
prep.run(store, dupes=False)
|
||||||
agent = store.save_agent("Backend", "python backend")
|
agent = store.save_agent("Backend", "python backend")
|
||||||
store.replace_scores(agent.id, [(uid, 1.0, "")])
|
store.replace_scores(agent.id, [(uid, 1.0, "", "", None, 1.0, "fit")])
|
||||||
with store.transaction() as conn:
|
with store.transaction() as conn:
|
||||||
conn.execute("UPDATE roles SET extracted_at = '2026-09-22T00:00:00+00:00', "
|
conn.execute("UPDATE roles SET extracted_at = '2026-09-22T00:00:00+00:00', "
|
||||||
"seniority_model = 'senior' WHERE uid = ?", (uid,))
|
"seniority_model = 'senior' WHERE uid = ?", (uid,))
|
||||||
@@ -530,7 +530,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [27, 28, 29, 30, 31, 32]
|
||||||
assert migrated.gazetteer().anywhere is not None
|
assert migrated.gazetteer().anywhere is not None
|
||||||
row = migrated._row("SELECT remote_host, remote_model, remote_where_model FROM roles "
|
row = migrated._row("SELECT remote_host, remote_model, remote_where_model FROM roles "
|
||||||
"WHERE uid = ?", (board,))
|
"WHERE uid = ?", (board,))
|
||||||
@@ -540,7 +540,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
|
|||||||
assert area(migrated, search.uid) == ("", "")
|
assert area(migrated, search.uid) == ("", "")
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
conn.execute("PRAGMA user_version = 26")
|
conn.execute("PRAGMA user_version = 26")
|
||||||
assert Store(path).migrations_applied == [27, 28, 29, 30, 31]
|
assert Store(path).migrations_applied == [27, 28, 29, 30, 31, 32]
|
||||||
|
|
||||||
|
|
||||||
def test_a_role_waits_for_extract_until_it_was_asked_where(store: Store) -> None:
|
def test_a_role_waits_for_extract_until_it_was_asked_where(store: Store) -> None:
|
||||||
|
|||||||
+80
-78
@@ -12,6 +12,7 @@ from typing import Any
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
if str(ROOT) not in sys.path:
|
if str(ROOT) not in sys.path:
|
||||||
@@ -353,18 +354,25 @@ def test_any_gates_are_one_group_a_role_must_match_one_of(
|
|||||||
def test_failed_gates_reads_evidence_only() -> None:
|
def test_failed_gates_reads_evidence_only() -> None:
|
||||||
gates = [Gate(field="country", values=["DK"]),
|
gates = [Gate(field="country", values=["DK"]),
|
||||||
Gate(field="remote", values=["remote"], mode="any"),
|
Gate(field="remote", values=["remote"], mode="any"),
|
||||||
Gate(field="seniority", values=["senior"], mode="any"),
|
Gate(field="seniority", values=["senior"], mode="any")]
|
||||||
Gate(field="function", values=["engineering"], mode="prefer")]
|
|
||||||
def cand(*states: int) -> Candidate:
|
def cand(*states: int) -> Candidate:
|
||||||
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=0, gates=list(states))
|
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=0, gates=list(states))
|
||||||
assert score.failed_gates(cand(1, 1, 0, 0), gates) == []
|
assert score.failed_gates(cand(1, 1, 0), gates) == []
|
||||||
assert score.failed_gates(cand(-1, -1, -1, 0), gates) == []
|
assert score.failed_gates(cand(-1, -1, -1), gates) == []
|
||||||
assert score.failed_gates(cand(0, 0, -1, 1), gates) == [
|
assert score.failed_gates(cand(0, 0, -1), gates) == [
|
||||||
"country not DK", "none of remote remote, seniority senior"]
|
"country not DK", "none of remote remote, seniority senior"]
|
||||||
assert score.failed_gates(cand(1, 0, 0, 1), gates) == [
|
assert score.failed_gates(cand(1, 0, 0), gates) == [
|
||||||
"none of remote remote, seniority senior"]
|
"none of remote remote, seniority senior"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_gate_is_require_any_or_exclude_and_has_no_weight() -> None:
|
||||||
|
"""Prefer gates left the agent: hybrid is a feed filter now."""
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
Gate(field="remote", values=["hybrid"], mode="prefer") # type: ignore[arg-type]
|
||||||
|
with pytest.raises(ValidationError):
|
||||||
|
Gate.model_validate({"field": "remote", "values": ["remote"], "weight": 1.0})
|
||||||
|
|
||||||
|
|
||||||
def test_an_exclude_gate_on_title_gates_whole_words_and_names_the_value(
|
def test_an_exclude_gate_on_title_gates_whole_words_and_names_the_value(
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
"""The sales and data engineering titles the owner does not want: a
|
"""The sales and data engineering titles the owner does not want: a
|
||||||
@@ -389,7 +397,7 @@ def test_an_exclude_gate_on_title_gates_whole_words_and_names_the_value(
|
|||||||
|
|
||||||
def test_a_favourite_is_gated_by_an_exclude_gate_it_matches(
|
def test_a_favourite_is_gated_by_an_exclude_gate_it_matches(
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
"""A star skips the `any` group, not the titles the agent leaves out."""
|
"""A star raises the level only: it skips no part of the fetch gate."""
|
||||||
store.add_company("Fave")
|
store.add_company("Fave")
|
||||||
director = role(store, "1", "Account Director, Nordics", company="Fave")
|
director = role(store, "1", "Account Director, Nordics", company="Fave")
|
||||||
engineer = role(store, "2", "Forward Deployed Engineer", company="Fave")
|
engineer = role(store, "2", "Forward Deployed Engineer", company="Fave")
|
||||||
@@ -415,21 +423,6 @@ def test_failed_gates_names_the_value_an_exclude_gate_matched() -> None:
|
|||||||
assert score.failed_gates(cand(0, 1), gates) == ["country not DK", "title account executive"]
|
assert score.failed_gates(cand(0, 1), gates) == ["country not DK", "title account executive"]
|
||||||
|
|
||||||
|
|
||||||
def test_a_prefer_gate_adds_its_weight_to_the_score(
|
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
|
||||||
remote = role(store, "1", remote="remote")
|
|
||||||
office = role(store, "2", remote="onsite")
|
|
||||||
agent = store.save_agent("Remote", "", [Gate(field="remote", values=["remote"],
|
|
||||||
mode="prefer", weight=0.5)])
|
|
||||||
|
|
||||||
run(config, store, score.run_score)
|
|
||||||
|
|
||||||
scores = store.scores(agent.id)
|
|
||||||
# No intent, so fit is out: recency 0.2 + affinity 0.2 + the gate's 0.5.
|
|
||||||
assert scores[remote][0] - scores[office][0] == pytest.approx(0.5 / 0.9, abs=1e-5)
|
|
||||||
assert scores[office][1] == ""
|
|
||||||
|
|
||||||
|
|
||||||
def test_a_favourite_is_gated_by_a_require_gate_it_fails(
|
def test_a_favourite_is_gated_by_a_require_gate_it_fails(
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
"""A star widens the search to the company, not past a require gate: the
|
"""A star widens the search to the company, not past a require gate: the
|
||||||
@@ -447,40 +440,70 @@ def test_a_favourite_is_gated_by_a_require_gate_it_fails(
|
|||||||
assert scores[berlin][1] == "" and scores[berlin][0] > 0
|
assert scores[berlin][1] == "" and scores[berlin][0] > 0
|
||||||
|
|
||||||
|
|
||||||
def test_a_favourite_passes_the_any_group_others_fail(
|
def test_all_countries_passes_the_any_group_a_favourite_does_not(
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
""""Denmark or remote" gates the onsite German role of a neutral company
|
""""Denmark or remote" gates the onsite German role of a neutral company
|
||||||
and lets the same role of a starred one through."""
|
and of a favourite, and lets the same role of an All countries company
|
||||||
store.add_company("Fave")
|
through."""
|
||||||
|
for name in ("Fave", "Wide", "Other"):
|
||||||
|
store.add_company(name)
|
||||||
fave = role(store, "1", company="Fave", place="Berlin, Germany", remote="onsite")
|
fave = role(store, "1", company="Fave", place="Berlin, Germany", remote="onsite")
|
||||||
other = role(store, "2", company="Other", place="Berlin, Germany", remote="onsite")
|
wide = role(store, "2", company="Wide", place="Berlin, Germany", remote="onsite")
|
||||||
|
other = role(store, "3", company="Other", place="Berlin, Germany", remote="onsite")
|
||||||
agent = store.save_agent("Copenhagen or remote", "", [
|
agent = store.save_agent("Copenhagen or remote", "", [
|
||||||
Gate(field="country", values=["DK"], mode="any"),
|
Gate(field="country", values=["DK"], mode="any"),
|
||||||
Gate(field="remote", values=["remote"], mode="any")])
|
Gate(field="remote", values=["remote"], mode="any")])
|
||||||
store.set_affinity(agent.id, "fave", 2)
|
store.set_affinity(agent.id, "fave", 2)
|
||||||
|
store.set_all_countries("wide", True)
|
||||||
|
|
||||||
run(config, store, score.run_score)
|
run(config, store, score.run_score)
|
||||||
|
|
||||||
scores = store.scores(agent.id)
|
scores = store.scores(agent.id)
|
||||||
assert scores[fave][1] == "" and scores[fave][0] > 0
|
assert scores[wide][1] == "" and scores[wide][0] > 0
|
||||||
|
assert scores[fave] == (0.0, "none of country DK, remote remote")
|
||||||
assert scores[other] == (0.0, "none of country DK, remote remote")
|
assert scores[other] == (0.0, "none of country DK, remote remote")
|
||||||
|
|
||||||
|
|
||||||
def test_a_favourite_takes_both_halves_of_the_rule_in_one_agent() -> None:
|
def test_all_countries_skips_the_place_part_and_all_roles_the_titles() -> None:
|
||||||
gates = [Gate(field="country", values=["DK"]),
|
"""The region applies to every company; All countries lifts the `any`
|
||||||
|
group, All roles the exclude gates on title and no other exclude gate."""
|
||||||
|
gates = [Gate(field="country", values=["DK", "SE", "EU"]),
|
||||||
|
Gate(field="country", values=["DK"], mode="any"),
|
||||||
Gate(field="remote", values=["remote"], mode="any"),
|
Gate(field="remote", values=["remote"], mode="any"),
|
||||||
Gate(field="seniority", values=["senior"], mode="any")]
|
Gate(field="title", values=["account executive"], mode="exclude"),
|
||||||
def cand(affinity: int, *states: int) -> Candidate:
|
Gate(field="company", values=["acme"], mode="exclude")]
|
||||||
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=affinity,
|
def cand(*states: int, wide: bool = False, every: bool = False) -> Candidate:
|
||||||
gates=list(states))
|
return Candidate(uid="u", posted_at=NOW.isoformat(), all_countries=wide,
|
||||||
# The any group fails for both; only the neutral company is gated by it.
|
all_roles=every, gates=list(states))
|
||||||
assert score.failed_gates(cand(2, 1, 0, 0), gates) == []
|
assert score.failed_gates(cand(1, 0, 0, 0, 0), gates) == [
|
||||||
assert score.failed_gates(cand(0, 1, 0, 0), gates) == [
|
"none of country DK, remote remote"]
|
||||||
"none of remote remote, seniority senior"]
|
assert score.failed_gates(cand(1, 0, 0, 0, 0, wide=True), gates) == []
|
||||||
# The require gate fails for both.
|
assert score.failed_gates(cand(0, 0, 0, 0, 0, wide=True, every=True), gates) == [
|
||||||
assert score.failed_gates(cand(2, 0, 0, 0), gates) == ["country not DK"]
|
"country not DK / SE / EU"]
|
||||||
assert score.failed_gates(cand(0, 0, 0, 0), gates) == [
|
assert score.failed_gates(cand(1, 1, 0, 1, 0), gates) == ["title account executive"]
|
||||||
"country not DK", "none of remote remote, seniority senior"]
|
assert score.failed_gates(cand(1, 1, 0, 1, 0, wide=True), gates) == [
|
||||||
|
"title account executive"]
|
||||||
|
assert score.failed_gates(cand(1, 1, 0, 1, 0, every=True), gates) == []
|
||||||
|
assert score.failed_gates(cand(1, 1, 0, 1, 1, every=True), gates) == ["company acme"]
|
||||||
|
assert score.failed_gates(cand(1, 0, 0, 1, 0, every=True), gates) == [
|
||||||
|
"none of country DK, remote remote"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_all_roles_keeps_a_title_the_agent_leaves_out(
|
||||||
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
|
for name in ("Small", "Other"):
|
||||||
|
store.add_company(name)
|
||||||
|
small = role(store, "1", "Account Executive", company="Small")
|
||||||
|
other = role(store, "2", "Account Executive", company="Other")
|
||||||
|
agent = store.save_agent("No sales", "", [
|
||||||
|
Gate(field="title", values=["account executive"], mode="exclude")])
|
||||||
|
store.set_all_roles("small", True)
|
||||||
|
|
||||||
|
run(config, store, score.run_score)
|
||||||
|
|
||||||
|
scores = store.scores(agent.id)
|
||||||
|
assert scores[small][1] == ""
|
||||||
|
assert scores[other] == (0.0, "title account executive")
|
||||||
|
|
||||||
|
|
||||||
def test_a_favourite_with_an_empty_column_is_not_gated() -> None:
|
def test_a_favourite_with_an_empty_column_is_not_gated() -> None:
|
||||||
@@ -808,12 +831,13 @@ def test_a_bad_calibration_is_a_config_error(
|
|||||||
def test_an_agent_without_an_intent_feeds_neither_model_stage_and_is_named(
|
def test_an_agent_without_an_intent_feeds_neither_model_stage_and_is_named(
|
||||||
store: Store, config: Config, clock: Clock, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, clock: Clock, fake: FakeEmbedder) -> None:
|
||||||
"""Its scores have no fit, so they rank fresh roles, not wanted ones: the
|
"""Its scores have no fit, so they rank fresh roles, not wanted ones: the
|
||||||
newer role tops it, and extract and summarise must not read it on that."""
|
newer role tops it, and nothing of it enters the cut by fit, nor does its
|
||||||
|
top choose what summarise reads."""
|
||||||
clock.at = NOW - timedelta(days=1)
|
clock.at = NOW - timedelta(days=1)
|
||||||
wanted = role(store, "1", "Backend Engineer", body="Python backend")
|
wanted = role(store, "1", "Backend Engineer", body="Python backend")
|
||||||
clock.at = NOW
|
clock.at = NOW
|
||||||
fresh = role(store, "2", "Frontend Engineer", body="React apps")
|
fresh = role(store, "2", "Frontend Engineer", body="React apps")
|
||||||
top_one = Limits(extract_top=1, extract_min=0, summarise_top=1, summarise_min=0)
|
top_one = Limits(cut_fit_top=1, cut_fit_min=0, summarise_top=1)
|
||||||
store.save_agent("Backend", "python backend", limits=top_one)
|
store.save_agent("Backend", "python backend", limits=top_one)
|
||||||
blind = store.save_agent("Fresh", "", limits=top_one)
|
blind = store.save_agent("Fresh", "", limits=top_one)
|
||||||
store.save_agent("Also fresh", " \n", limits=top_one)
|
store.save_agent("Also fresh", " \n", limits=top_one)
|
||||||
@@ -854,26 +878,6 @@ def test_a_gated_role_does_not_stretch_the_fit_range_under_the_fallback(
|
|||||||
assert scores[close][0] == 1.0 and scores[far][0] == 0.0
|
assert scores[close][0] == 1.0 and scores[far][0] == 0.0
|
||||||
|
|
||||||
|
|
||||||
def test_a_small_prefer_gate_no_longer_outweighs_fit(
|
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
|
||||||
"""The flaw the last real run showed: real cosines sit close together, so
|
|
||||||
under `(cos + 1) / 2` a prefer gate decided the order over fit. Here the
|
|
||||||
cosines are about 0.95 and 0.87: the old fit terms differ by 0.04, which
|
|
||||||
at weight 0.6 is less than the gate's 0.05, so the remote role won.
|
|
||||||
Calibrated, they are 1 and about 0.89, and the closer role wins."""
|
|
||||||
close = role(store, "1", "Backend Engineer", body="Python backend", remote="onsite")
|
|
||||||
far = role(store, "2", "Backend Engineer", body="Python backend data", remote="remote")
|
|
||||||
agent = store.save_agent("Backend", "python backend",
|
|
||||||
[Gate(field="remote", values=["remote"], mode="prefer",
|
|
||||||
weight=0.05)])
|
|
||||||
|
|
||||||
run(config, store, embed.run_embed)
|
|
||||||
run(config, store, score.run_score)
|
|
||||||
|
|
||||||
scores = store.scores(agent.id)
|
|
||||||
assert scores[close][0] > scores[far][0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_the_intent_vector_is_cached_until_the_intent_changes(
|
def test_the_intent_vector_is_cached_until_the_intent_changes(
|
||||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||||
role(store, "1")
|
role(store, "1")
|
||||||
@@ -1018,9 +1022,7 @@ def test_the_shipped_starter_agents_validate() -> None:
|
|||||||
block = [line[2:] for line in lines[start:] if line.startswith("# ")]
|
block = [line[2:] for line in lines[start:] if line.startswith("# ")]
|
||||||
examples = [AgentSeed.model_validate(a) for a in yaml.safe_load("\n".join(block))]
|
examples = [AgentSeed.model_validate(a) for a in yaml.safe_load("\n".join(block))]
|
||||||
assert [a.name for a in examples] == ["Remote from Europe", "Europe hybrid"]
|
assert [a.name for a in examples] == ["Remote from Europe", "Europe hybrid"]
|
||||||
# Small enough that a prefer gate breaks ties rather than overrides fit.
|
assert examples[0].limits.cut_fit_top == 1000
|
||||||
assert {g.weight for a in [*agents, *examples]
|
|
||||||
for g in a.gates if g.mode == "prefer"} == {0.05}
|
|
||||||
|
|
||||||
|
|
||||||
def test_a_starter_agent_may_list_prompts_or_give_an_intent(
|
def test_a_starter_agent_may_list_prompts_or_give_an_intent(
|
||||||
@@ -1074,7 +1076,7 @@ def test_the_shipped_starter_searches_validate() -> None:
|
|||||||
|
|
||||||
# ---------------------------------------------------------------- cascade
|
# ---------------------------------------------------------------- cascade
|
||||||
|
|
||||||
def test_the_pull_job_runs_pull_prep_embed_score_extract_score_then_summarise(
|
def test_the_pull_job_runs_pull_prep_embed_score_extract_score_judge_then_summarise(
|
||||||
store: Store, config: Config, fake: FakeEmbedder, tmp_path: Path,
|
store: Store, config: Config, fake: FakeEmbedder, tmp_path: Path,
|
||||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
|
store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
|
||||||
@@ -1104,10 +1106,10 @@ def test_the_pull_job_runs_pull_prep_embed_score_extract_score_then_summarise(
|
|||||||
assert batch is not None
|
assert batch is not None
|
||||||
jobs = sorted(queue.jobs.of_cascade(batch.cascade_id), key=lambda j: j.id)
|
jobs = sorted(queue.jobs.of_cascade(batch.cascade_id), key=lambda j: j.id)
|
||||||
stages = [j.result.get("task") for j in jobs if j.kind == FINAL]
|
stages = [j.result.get("task") for j in jobs if j.kind == FINAL]
|
||||||
# Enrich found no board with role pages, so the prep, embed and score
|
# Fetch text found no board with role pages, so the prep, embed and score
|
||||||
# behind it are passed over.
|
# behind it are passed over.
|
||||||
assert stages == ["pull", "prep", "embed", "score", "enrich", "extract", "score",
|
assert stages == ["pull", "prep", "embed", "score", "fetch_text", "extract", "score",
|
||||||
"summarise", "judge"]
|
"judge", "summarise"]
|
||||||
work = [j.kind for j in jobs if j.kind != FINAL]
|
work = [j.kind for j in jobs if j.kind != FINAL]
|
||||||
# The `pull` job and the chain it asked for are one cascade, so the Jobs
|
# The `pull` job and the chain it asked for are one cascade, so the Jobs
|
||||||
# tab shows a scheduled pull as one run. Extract and summarise are off and
|
# tab shows a scheduled pull as one run. Extract and summarise are off and
|
||||||
@@ -1159,14 +1161,14 @@ def test_the_model_batches_are_isolated_with_a_timeout() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_follows_walks_the_cascade_by_position_and_stops_at_its_end() -> None:
|
def test_follows_walks_the_cascade_by_position_and_stops_at_its_end() -> None:
|
||||||
"""By position, not by name: `score` is in the chain twice, once before
|
"""By position, not by name: `score` is in the chain three times, and the
|
||||||
extract and once after, and the second must lead on to summarise."""
|
one after extract must lead on to judge."""
|
||||||
assert cascade.CASCADES["pull"] == ("pull", "prep", "embed", "score", "enrich", "prep",
|
assert cascade.CASCADES["pull"] == ("pull", "prep", "embed", "score", "fetch_text", "prep",
|
||||||
"embed", "score", "extract", "score", "summarise",
|
"embed", "score", "extract", "score", "judge",
|
||||||
"judge")
|
"summarise")
|
||||||
assert [cascade.follows("pull", at) for at in range(12)] == \
|
assert [cascade.follows("pull", at) for at in range(12)] == \
|
||||||
["prep", "embed", "score", "enrich", "prep", "embed", "score", "extract", "score",
|
["prep", "embed", "score", "fetch_text", "prep", "embed", "score", "extract", "score",
|
||||||
"summarise", "judge", ""]
|
"judge", "summarise", ""]
|
||||||
assert cascade.follows("pull", -1) == "" and cascade.follows("pull", 11) == ""
|
assert cascade.follows("pull", -1) == "" and cascade.follows("pull", 11) == ""
|
||||||
assert cascade.follows("nope", 0) == ""
|
assert cascade.follows("nope", 0) == ""
|
||||||
assert cascade.chain("pull").carries == {"cascade": "pull", "task": "pull", "at": 0}
|
assert cascade.chain("pull").carries == {"cascade": "pull", "task": "pull", "at": 0}
|
||||||
@@ -1186,4 +1188,4 @@ def test_step_hands_the_position_on(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
assert made[0].carries == {"cascade": "pull", "task": "extract", "at": 8}
|
assert made[0].carries == {"cascade": "pull", "task": "extract", "at": 8}
|
||||||
out = cascade.step(None, None, Tally(), {"cascade": "pull", "task": "score", "at": 9},
|
out = cascade.step(None, None, Tally(), {"cascade": "pull", "task": "score", "at": 9},
|
||||||
context=Context())
|
context=Context())
|
||||||
assert out["next"] == "summarise" and made[1].carries["at"] == 10
|
assert out["next"] == "judge" and made[1].carries["at"] == 10
|
||||||
+11
-10
@@ -45,11 +45,12 @@ def store(tmp_path: Path) -> Store:
|
|||||||
|
|
||||||
|
|
||||||
def ranked(store: Store) -> None:
|
def ranked(store: Store) -> None:
|
||||||
"""Two roles scored well for one enabled agent: inside both stages' bounds."""
|
"""Two roles scored well for one enabled agent, both in its cut."""
|
||||||
for sid in ("1", "2"):
|
for sid in ("1", "2"):
|
||||||
store.upsert_role(posting(sid))
|
store.upsert_role(posting(sid))
|
||||||
one = store.save_agent("Backend", "python backend")
|
one = store.save_agent("Backend", "python backend")
|
||||||
store.replace_scores(one.id, [(posting("1").uid, 1.0, ""), (posting("2").uid, 0.9, "")])
|
store.replace_scores(one.id, [(posting("1").uid, 1.0, "", "", None, 1.0, "fit"),
|
||||||
|
(posting("2").uid, 0.9, "", "", None, 0.9, "fit")])
|
||||||
|
|
||||||
|
|
||||||
def answered_by(monkeypatch: pytest.MonkeyPatch, backend: str) -> None:
|
def answered_by(monkeypatch: pytest.MonkeyPatch, backend: str) -> None:
|
||||||
@@ -159,7 +160,7 @@ def test_get_stages_lists_all_four_with_their_source_model_and_who_answers(
|
|||||||
{"name": "judge", "on": False, "source": "config",
|
{"name": "judge", "on": False, "source": "config",
|
||||||
"model": "claude-haiku-4-5-20251001", "backend": "api",
|
"model": "claude-haiku-4-5-20251001", "backend": "api",
|
||||||
"answer": "answered by the Claude API"},
|
"answer": "answered by the Claude API"},
|
||||||
{"name": "enrich", "on": True, "source": "config", "model": "", "backend": "",
|
{"name": "fetch_text", "on": True, "source": "config", "model": "", "backend": "",
|
||||||
"answer": "reads role pages, asks no model"},
|
"answer": "reads role pages, asks no model"},
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ def test_who_answers_is_said_for_the_api_claude_code_and_nobody(
|
|||||||
answers = {}
|
answers = {}
|
||||||
for backend in ("api", "claude_code", ""):
|
for backend in ("api", "claude_code", ""):
|
||||||
answered_by(monkeypatch, backend)
|
answered_by(monkeypatch, backend)
|
||||||
[first, second, third, _enrich] = client.get("/api/stages").json()
|
[first, second, third, _fetch_text] = client.get("/api/stages").json()
|
||||||
assert first["backend"] == second["backend"] == third["backend"] == backend
|
assert first["backend"] == second["backend"] == third["backend"] == backend
|
||||||
answers[backend] = first["answer"]
|
answers[backend] = first["answer"]
|
||||||
|
|
||||||
@@ -196,16 +197,16 @@ def test_put_stores_the_setting_returns_the_same_shape_and_starts_nothing(
|
|||||||
assert res.json()["on"] is False and store.state["stage:summarise"] == "off"
|
assert res.json()["on"] is False and store.state["stage:summarise"] == "off"
|
||||||
|
|
||||||
|
|
||||||
def test_the_enrich_switch_is_listed_and_stored_like_the_others(
|
def test_the_fetch_text_switch_is_listed_and_stored_like_the_others(
|
||||||
client: TestClient, store: Store) -> None:
|
client: TestClient, store: Store) -> None:
|
||||||
res = client.put("/api/stages/enrich", json={"on": False})
|
res = client.put("/api/stages/fetch_text", json={"on": False})
|
||||||
|
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
assert res.json()["name"] == "enrich" and res.json()["on"] is False
|
assert res.json()["name"] == "fetch_text" and res.json()["on"] is False
|
||||||
assert store.state["stage:enrich"] == "off"
|
assert store.state["stage:fetch_text"] == "off"
|
||||||
listed = {stage["name"]: stage for stage in client.get("/api/stages").json()}
|
listed = {stage["name"]: stage for stage in client.get("/api/stages").json()}
|
||||||
assert list(listed) == ["extract", "summarise", "judge", "enrich"]
|
assert list(listed) == ["extract", "summarise", "judge", "fetch_text"]
|
||||||
assert listed["enrich"]["on"] is False and listed["enrich"]["source"] == "stored"
|
assert listed["fetch_text"]["on"] is False and listed["fetch_text"]["source"] == "stored"
|
||||||
|
|
||||||
|
|
||||||
def test_an_unknown_stage_is_404_and_a_bad_body_is_422(client: TestClient) -> None:
|
def test_an_unknown_stage_is_404_and_a_bad_body_is_422(client: TestClient) -> None:
|
||||||
|
|||||||
+42
-39
@@ -70,7 +70,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
|
|||||||
"application_events", "agents", "scores", "state"} <= tables
|
"application_events", "agents", "scores", "state"} <= tables
|
||||||
assert "idx_roles_cluster" in indexes
|
assert "idx_roles_cluster" in indexes
|
||||||
assert store.migrations_applied == []
|
assert store.migrations_applied == []
|
||||||
assert LATEST == 31
|
assert LATEST == 32
|
||||||
# A second open finds it current and applies nothing.
|
# A second open finds it current and applies nothing.
|
||||||
assert Store(path).migrations_applied == []
|
assert Store(path).migrations_applied == []
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
acme = migrated.company("acme")
|
acme = migrated.company("acme")
|
||||||
assert acme is not None
|
assert acme is not None
|
||||||
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
|
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
|
||||||
@@ -395,7 +395,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
|
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
|
||||||
Prompt(name="Backend", text="python backend")]
|
Prompt(name="Backend", text="python backend")]
|
||||||
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
|
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
|
||||||
@@ -419,7 +419,7 @@ def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
acme = migrated.company("acme")
|
acme = migrated.company("acme")
|
||||||
assert acme is not None
|
assert acme is not None
|
||||||
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
|
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
|
||||||
@@ -448,7 +448,7 @@ def test_v17_folds_every_place_and_levels_the_titles_extract_has_not_read(
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
|
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
|
||||||
"SELECT uid, place_fold, seniority FROM roles")}
|
"SELECT uid, place_fold, seniority FROM roles")}
|
||||||
@@ -494,22 +494,21 @@ def test_prompts_are_saved_replaced_reordered_and_deleted(store: Store) -> None:
|
|||||||
assert conn.execute("SELECT COUNT(*) FROM agent_prompts").fetchone()[0] == 0
|
assert conn.execute("SELECT COUNT(*) FROM agent_prompts").fetchone()[0] == 0
|
||||||
|
|
||||||
|
|
||||||
def test_an_agent_whose_prompts_are_all_empty_feeds_neither_model_stage(
|
def test_an_agent_whose_prompts_are_all_empty_does_not_choose_what_summarise_reads(
|
||||||
store: Store) -> None:
|
store: Store) -> None:
|
||||||
upsert(store, posting("a"))
|
upsert(store, posting("a"))
|
||||||
upsert(store, posting("b"))
|
upsert(store, posting("b"))
|
||||||
a, b = posting("a").uid, posting("b").uid
|
a, b = posting("a").uid, posting("b").uid
|
||||||
top = Limits(extract_top=1, extract_min=0, summarise_top=1, summarise_min=0)
|
top = Limits(summarise_top=1)
|
||||||
blank = store.save_agent("Blank", limits=top,
|
blank = store.save_agent("Blank", limits=top,
|
||||||
prompts=[Prompt(name="One"), Prompt(name="Two", text=" \n")])
|
prompts=[Prompt(name="One"), Prompt(name="Two", text=" \n")])
|
||||||
store.replace_scores(blank.id, [(a, 0.9, "")])
|
store.replace_scores(blank.id, [(a, 0.9, ""), (b, 0.8, "")])
|
||||||
assert store.extract_waiting(10) == [] and store.summarise_waiting(10) == []
|
assert store.summarise_waiting(10) == []
|
||||||
|
|
||||||
# One prompt with text is enough.
|
# One prompt with text is enough.
|
||||||
store.save_agent("Blank", agent_id=blank.id, limits=top,
|
store.save_agent("Blank", agent_id=blank.id, limits=top,
|
||||||
prompts=[Prompt(name="One"), Prompt(name="Two", text="python")])
|
prompts=[Prompt(name="One"), Prompt(name="Two", text="python")])
|
||||||
assert [r.uid for r in store.extract_waiting(10)] == [a]
|
assert [r.uid for r in store.summarise_waiting(10)] == [a]
|
||||||
assert b not in {r.uid for r in store.summarise_waiting(10)}
|
|
||||||
|
|
||||||
|
|
||||||
def test_state_is_a_mapping(store: Store) -> None:
|
def test_state_is_a_mapping(store: Store) -> None:
|
||||||
@@ -691,7 +690,7 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
|
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
|
||||||
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
|
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
|
||||||
assert migrated.role_places(stated.uid) == []
|
assert migrated.role_places(stated.uid) == []
|
||||||
@@ -733,7 +732,7 @@ def test_v25_clears_the_model_levels_the_ladder_splits_and_sets_the_level(
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30, 31, 32]
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
found = {sid: rest for sid, *rest in conn.execute(
|
found = {sid: rest for sid, *rest in conn.execute(
|
||||||
"SELECT source_id, seniority_model, seniority_stated, seniority_title, seniority "
|
"SELECT source_id, seniority_model, seniority_stated, seniority_title, seniority "
|
||||||
@@ -751,12 +750,12 @@ def test_v26_adds_posting_url_empty_and_runs_twice_without_harm(tmp_path: Path)
|
|||||||
|
|
||||||
migrated = Store(path)
|
migrated = Store(path)
|
||||||
|
|
||||||
assert migrated.migrations_applied == [26, 27, 28, 29, 30, 31]
|
assert migrated.migrations_applied == [26, 27, 28, 29, 30, 31, 32]
|
||||||
role = migrated.role(posting("a").uid)
|
role = migrated.role(posting("a").uid)
|
||||||
assert role is not None and role.posting_url == ""
|
assert role is not None and role.posting_url == ""
|
||||||
with sqlite3.connect(path) as conn:
|
with sqlite3.connect(path) as conn:
|
||||||
conn.execute("PRAGMA user_version = 25") # the column is there already
|
conn.execute("PRAGMA user_version = 25") # the column is there already
|
||||||
assert Store(path).migrations_applied == [26, 27, 28, 29, 30, 31]
|
assert Store(path).migrations_applied == [26, 27, 28, 29, 30, 31, 32]
|
||||||
|
|
||||||
|
|
||||||
def test_a_pull_keeps_the_posting_url(store: Store) -> None:
|
def test_a_pull_keeps_the_posting_url(store: Store) -> None:
|
||||||
@@ -1277,21 +1276,34 @@ def test_votes_are_per_agent(store: Store) -> None:
|
|||||||
|
|
||||||
def test_roles_with_an_agent_but_not_by_score_are_newest_first_with_votes(
|
def test_roles_with_an_agent_but_not_by_score_are_newest_first_with_votes(
|
||||||
store: Store, clock: Clock) -> None:
|
store: Store, clock: Clock) -> None:
|
||||||
for sid in ("1", "2", "3"):
|
for sid in ("1", "2", "3", "4"):
|
||||||
upsert(store, posting(sid))
|
upsert(store, posting(sid))
|
||||||
clock.tick()
|
clock.tick()
|
||||||
uid = {r.source_id: r.uid for r in store.roles()}
|
uid = {r.source_id: r.uid for r in store.roles()}
|
||||||
agent = store.save_agent("A")
|
agent = store.save_agent("A")
|
||||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, ""),
|
||||||
|
(uid["4"], 0.0, "country not DK")]) # 3 unscored
|
||||||
store.set_vote(agent.id, uid["1"], 1)
|
store.set_vote(agent.id, uid["1"], 1)
|
||||||
|
|
||||||
newest = store.roles(agent=agent.id, by_score=False)
|
newest = store.roles(agent=agent.id, by_score=False)
|
||||||
assert [r.source_id for r in newest] == ["3", "2", "1"]
|
assert [r.source_id for r in newest] == ["4", "3", "2", "1"]
|
||||||
assert [r.score for r in newest] == [None, None, None]
|
assert [r.score for r in newest] == [None, None, None, None]
|
||||||
assert [r.vote for r in newest] == [None, None, 1]
|
assert [r.vote for r in newest] == [None, None, None, 1]
|
||||||
assert store.count_roles(agent=agent.id, by_score=False) == 3
|
assert store.count_roles(agent=agent.id, by_score=False) == 4
|
||||||
assert [r.source_id for r in store.roles(agent=agent.id)] == ["1", "2"]
|
assert [r.source_id for r in store.roles(agent=agent.id)] == ["1", "2"]
|
||||||
|
|
||||||
|
# Kept to the agent's fetch gate, newest lists only what it scored and
|
||||||
|
# passed, as the score order does; `gated` shows the rest with the reason.
|
||||||
|
fenced = store.roles(agent=agent.id, by_score=False, fetch_gate=True)
|
||||||
|
assert [r.source_id for r in fenced] == ["2", "1"]
|
||||||
|
assert [r.score for r in fenced] == [None, None]
|
||||||
|
assert store.count_roles(agent=agent.id, by_score=False, fetch_gate=True) == 2
|
||||||
|
page = store.roles_page(agent=agent.id, by_score=False, fetch_gate=True, gated=True)
|
||||||
|
assert [(r.uid, r.gated_reason) for r in page] == [
|
||||||
|
(uid["4"], "country not DK"), (uid["2"], ""), (uid["1"], "")]
|
||||||
|
assert store.count_roles(agent=agent.id, by_score=False, fetch_gate=True,
|
||||||
|
gated=True) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_read_state_is_set_cleared_and_a_vote_marks_read(
|
def test_read_state_is_set_cleared_and_a_vote_marks_read(
|
||||||
store: Store, clock: Clock) -> None:
|
store: Store, clock: Clock) -> None:
|
||||||
@@ -1738,39 +1750,30 @@ def test_a_summarys_tags_land_with_it_and_not_on_a_rejected_late_answer(
|
|||||||
|
|
||||||
def test_summarise_waits_on_the_top_of_each_enabled_agent_by_its_own_limits(
|
def test_summarise_waits_on_the_top_of_each_enabled_agent_by_its_own_limits(
|
||||||
store: Store) -> None:
|
store: Store) -> None:
|
||||||
"""Each agent contributes its own top, as deep and as low as its own
|
"""Each agent contributes the top of its feed, its best `summarise_top`
|
||||||
`limits` say; a closed role and a gated score are in nobody's top. A
|
final scores; a closed role and a gated score are in nobody's top. A
|
||||||
hidden company needs no case: `score` writes no rows for it under the
|
hidden company needs no case: `score` writes no rows for it under the
|
||||||
agent that hid it. An agent saved before v8 has `limits` of '{}', which
|
agent that hid it. `limits` of '{}' reads as the defaults."""
|
||||||
reads as the defaults."""
|
|
||||||
for sid in "abcd":
|
for sid in "abcd":
|
||||||
upsert(store, posting(sid))
|
upsert(store, posting(sid))
|
||||||
a, b, c, d = (posting(s).uid for s in "abcd")
|
a, b, c, d = (posting(s).uid for s in "abcd")
|
||||||
with store.transaction() as conn:
|
with store.transaction() as conn:
|
||||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), d))
|
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), d))
|
||||||
one = store.save_agent("One", "python backend",
|
one = store.save_agent("One", "python backend", limits=Limits(summarise_top=1))
|
||||||
limits=Limits(summarise_top=1, summarise_min=0))
|
two = store.save_agent("Two", "python backend", limits=Limits(summarise_top=1))
|
||||||
two = store.save_agent("Two", "python backend",
|
|
||||||
limits=Limits(summarise_top=1, summarise_min=0))
|
|
||||||
store.replace_scores(one.id, [(d, 0.99, ""), (a, 0.9, ""), (b, 0.5, "")])
|
store.replace_scores(one.id, [(d, 0.99, ""), (a, 0.9, ""), (b, 0.5, "")])
|
||||||
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.7, ""), (b, 0.8, "")])
|
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.7, ""), (b, 0.8, "")])
|
||||||
|
|
||||||
assert {r.uid for r in store.summarise_waiting(10)} == {a, b}
|
assert {r.uid for r in store.summarise_waiting(10)} == {a, b}
|
||||||
|
|
||||||
# Two goes deeper: its second, c, joins; One's second, b, was in already.
|
# Two goes deeper: its second, c, joins; One's second, b, was in already.
|
||||||
store.save_agent("Two", "python backend", agent_id=two.id,
|
store.save_agent("Two", "python backend", agent_id=two.id, limits=Limits(summarise_top=2))
|
||||||
limits=Limits(summarise_top=2, summarise_min=0))
|
|
||||||
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
|
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
|
||||||
assert store.summarise_pending() == 3
|
assert store.summarise_pending() == 3
|
||||||
assert [r.uid for r in store.summarise_waiting(10, uids=[d])] == [d]
|
assert [r.uid for r in store.summarise_waiting(10, uids=[d])] == [d]
|
||||||
# The floor is Two's own: c at 0.7 drops, One's b at 0.5 stays.
|
store.save_agent("Two", "python backend", agent_id=two.id, limits=Limits(summarise_top=0))
|
||||||
store.save_agent("Two", "python backend", agent_id=two.id,
|
assert {r.uid for r in store.summarise_waiting(10)} == {a}
|
||||||
limits=Limits(summarise_top=2, summarise_min=0.75))
|
# '{}' is the defaults, 50 deep.
|
||||||
store.save_agent("One", "python backend", agent_id=one.id,
|
|
||||||
limits=Limits(summarise_top=2, summarise_min=0))
|
|
||||||
assert {r.uid for r in store.summarise_waiting(10)} == {a, b}
|
|
||||||
# '{}' is the defaults, 30 at 0.65: One's b at 0.5 drops, but Two's b at
|
|
||||||
# 0.8 and c at 0.7 clear it.
|
|
||||||
with store.transaction() as conn:
|
with store.transaction() as conn:
|
||||||
conn.execute("UPDATE agents SET limits = '{}'")
|
conn.execute("UPDATE agents SET limits = '{}'")
|
||||||
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
|
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
|
||||||
|
|||||||
+23
-13
@@ -351,6 +351,7 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
|
|||||||
upsert(store, posting(sid))
|
upsert(store, posting(sid))
|
||||||
uid = {r.source_id: r.uid for r in store.roles()}
|
uid = {r.source_id: r.uid for r in store.roles()}
|
||||||
agent = store.save_agent("A")
|
agent = store.save_agent("A")
|
||||||
|
store.replace_scores(agent.id, [(u, 0.5, "") for u in uid.values()])
|
||||||
|
|
||||||
# No `agent` in the body: the default agent's vote.
|
# No `agent` in the body: the default agent's vote.
|
||||||
res = client.post(f"/api/roles/{uid['liked']}/vote", json={"value": 1})
|
res = client.post(f"/api/roles/{uid['liked']}/vote", json={"value": 1})
|
||||||
@@ -394,6 +395,8 @@ def test_votes_are_per_agent_over_the_api(client: TestClient, store: Store) -> N
|
|||||||
uid = posting("1").uid
|
uid = posting("1").uid
|
||||||
one = store.save_agent("One")
|
one = store.save_agent("One")
|
||||||
two = store.save_agent("Two")
|
two = store.save_agent("Two")
|
||||||
|
for agent in (one, two):
|
||||||
|
store.replace_scores(agent.id, [(uid, 0.5, "")])
|
||||||
|
|
||||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": one.id}).json()["vote"] == 1
|
assert client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": one.id}).json()["vote"] == 1
|
||||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": two.id}).json()["vote"] == -1
|
assert client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": two.id}).json()["vote"] == -1
|
||||||
@@ -439,11 +442,15 @@ def test_roles_with_an_agent_can_be_ordered_newest_and_keep_the_votes(
|
|||||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||||
store.set_vote(agent.id, uid["1"], 1)
|
store.set_vote(agent.id, uid["1"], 1)
|
||||||
|
|
||||||
|
# Newest keeps to the agent's fetch gate: only what it scored and passed.
|
||||||
page = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
|
page = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
|
||||||
|
assert [r["uid"] for r in page["items"]] == [uid["2"], uid["1"]]
|
||||||
|
assert [r["score"] for r in page["items"]] == [None, None]
|
||||||
|
assert [r["vote"] for r in page["items"]] == [None, 1]
|
||||||
|
assert page["total"] == 2
|
||||||
|
# Without an agent named, newest is every open role.
|
||||||
|
page = client.get("/api/roles", params={"order": "newest"}).json()
|
||||||
assert [r["uid"] for r in page["items"]] == [uid["3"], uid["2"], uid["1"]]
|
assert [r["uid"] for r in page["items"]] == [uid["3"], uid["2"], uid["1"]]
|
||||||
assert [r["score"] for r in page["items"]] == [None, None, None]
|
|
||||||
assert [r["vote"] for r in page["items"]] == [None, None, 1]
|
|
||||||
assert page["total"] == 3
|
|
||||||
scored = client.get("/api/roles", params={"agent": agent.id, "order": "score"}).json()
|
scored = client.get("/api/roles", params={"agent": agent.id, "order": "score"}).json()
|
||||||
assert [r["uid"] for r in scored["items"]] == [uid["1"], uid["2"]]
|
assert [r["uid"] for r in scored["items"]] == [uid["1"], uid["2"]]
|
||||||
assert client.get("/api/roles", params={"agent": agent.id,
|
assert client.get("/api/roles", params={"agent": agent.id,
|
||||||
@@ -1086,7 +1093,9 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
|||||||
agent = created.json()
|
agent = created.json()
|
||||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2, "taste": 0.2,
|
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2, "taste": 0.2,
|
||||||
"cv_skills": 30, "cv_experience": 25, "cv_career": 30}
|
"cv_skills": 30, "cv_experience": 25, "cv_career": 30}
|
||||||
assert agent["gates"][0]["weight"] == 1.0
|
assert agent["gates"] == body["gates"]
|
||||||
|
prefer = {**body, "gates": [{"field": "remote", "values": ["hybrid"], "mode": "prefer"}]}
|
||||||
|
assert client.post("/api/agents", json=prefer).status_code == 422
|
||||||
|
|
||||||
updated = client.post("/api/agents", json={**body, "id": agent["id"], "enabled": False,
|
updated = client.post("/api/agents", json={**body, "id": agent["id"], "enabled": False,
|
||||||
"weights": {"fit": 1, "recency": 0,
|
"weights": {"fit": 1, "recency": 0,
|
||||||
@@ -1179,19 +1188,20 @@ def test_a_gate_on_an_unknown_field_is_refused(client: TestClient) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_an_agents_limits_are_saved_listed_and_checked(client: TestClient) -> None:
|
def test_an_agents_limits_are_saved_listed_and_checked(client: TestClient) -> None:
|
||||||
"""How deep the model stages read is the agent's own; a score outside
|
"""The cut and the depth of summarise are the agent's own; a minimum
|
||||||
0..1 is refused."""
|
outside 0..1 and a key from before the cut are refused."""
|
||||||
default = client.post("/api/agents", json={"name": "Wide"}).json()
|
default = client.post("/api/agents", json={"name": "Wide"}).json()
|
||||||
assert default["limits"] == {"extract_top": 500, "extract_min": 0.55,
|
assert default["limits"] == {"cut_fit_top": 500, "cut_fit_min": 0.6,
|
||||||
"summarise_top": 30, "summarise_min": 0.65,
|
"cut_cv_top": 150, "cut_cv_min": 0.6, "summarise_top": 50}
|
||||||
"judge_top": 150, "judge_min": 0.55, "judge_cv_top": 50}
|
narrow = {"cut_fit_top": 50, "cut_fit_min": 0.7, "cut_cv_top": 10, "cut_cv_min": 0.75,
|
||||||
narrow = {"extract_top": 50, "extract_min": 0.6, "summarise_top": 5, "summarise_min": 0.7,
|
"summarise_top": 5}
|
||||||
"judge_top": 20, "judge_min": 0.6, "judge_cv_top": 10}
|
|
||||||
saved = client.post("/api/agents", json={"name": "Narrow", "limits": narrow})
|
saved = client.post("/api/agents", json={"name": "Narrow", "limits": narrow})
|
||||||
assert saved.status_code == 200 and saved.json()["limits"] == narrow
|
assert saved.status_code == 200 and saved.json()["limits"] == narrow
|
||||||
assert [a["limits"]["extract_top"] for a in client.get("/api/agents").json()] == [50, 500]
|
assert [a["limits"]["cut_fit_top"] for a in client.get("/api/agents").json()] == [50, 500]
|
||||||
bad = client.post("/api/agents", json={"name": "Bad", "limits": {"extract_min": 2}})
|
bad = client.post("/api/agents", json={"name": "Bad", "limits": {"cut_fit_min": 2}})
|
||||||
assert bad.status_code == 422
|
assert bad.status_code == 422
|
||||||
|
old = client.post("/api/agents", json={"name": "Old", "limits": {"extract_top": 5}})
|
||||||
|
assert old.status_code == 422
|
||||||
|
|
||||||
|
|
||||||
def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
|
def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
|
||||||
|
|||||||
Reference in new issue
Block a user