Merge branch 'wp-g-enrich'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
38a80d5b55
10 files changed
+956
-219
No files matched your search
@@ -1503,6 +1503,46 @@ class Store:
|
||||
return None
|
||||
return self.role(uid)
|
||||
|
||||
# --------------------------------------------------------------- enrich
|
||||
|
||||
def enrich_waiting(self, top: int, floor: float,
|
||||
uids: Sequence[str] | None = None) -> list[dict[str, Any]]:
|
||||
"""Open `ats` roles without text that an enabled agent with a prompt
|
||||
ranks ungated among its best `top` and at `floor` or above, best
|
||||
first by the highest such score, as `{uid, source_id,
|
||||
subscription_id, title, url, published_at, raw, score}`. The ranking
|
||||
is `_top_scope`'s, with the bar given rather than the agent's own.
|
||||
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, "
|
||||
"r.published_at, r.raw")
|
||||
waiting = ("r.closed_at IS NULL AND r.dup_of IS NULL AND r.source = 'ats' "
|
||||
"AND r.subscription_id IS NOT NULL AND r.description = '' "
|
||||
"AND r.article_text = ''")
|
||||
if uids is not None:
|
||||
rows = self._rows(
|
||||
f"SELECT {fields}, NULL AS score FROM roles r WHERE {waiting} "
|
||||
"AND r.uid IN (SELECT value FROM json_each(?))", (json.dumps(list(uids)),))
|
||||
else:
|
||||
rows = self._rows(
|
||||
f"""SELECT {fields}, MAX(ranked.score) AS score FROM (
|
||||
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
|
||||
AND EXISTS (SELECT 1 FROM agent_prompts p
|
||||
WHERE p.agent_id = a.id
|
||||
AND TRIM(p.text, ' ' || char(9, 10, 13)) <> '')
|
||||
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]
|
||||
|
||||
# -------------------------------------------------------------- vectors
|
||||
|
||||
def roles_to_embed(self, model: str, limit: int) -> list[Role]:
|
||||
|
||||
Reference in new issue
Block a user