Extract gate columns from posting text with a Haiku ModelTask
roledesk job extract reads open, unanswered roles 20 to a call and fills place, country, remote, seniority, salary, currency, function, permit and languages, only into columns the board left empty. Schema v2 adds roles.permit, roles.languages and roles.extract_tries. Off by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b44f78ca7e
commit
4dfb8831aa
12 files changed
+578
-14
No files matched your search
+46
-2
@@ -10,11 +10,14 @@ title at two companies is two jobs, and the same ad on two boards is one.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import unicodedata
|
||||
from typing import Literal, get_args
|
||||
from typing import Annotated, Any, Literal, get_args
|
||||
|
||||
from desk.models import JsonDict, Model
|
||||
from pydantic import BeforeValidator
|
||||
|
||||
from desk.models import JsonDict, Model, ModelTaskResult
|
||||
|
||||
# ------------------------------------------------------------------- keys
|
||||
|
||||
@@ -66,6 +69,14 @@ def company_key(company: str) -> str:
|
||||
Remote = Literal["", "remote", "hybrid", "onsite"]
|
||||
REMOTE: tuple[str, ...] = get_args(Remote)
|
||||
|
||||
Seniority = Literal["", "intern", "junior", "mid", "senior", "staff", "lead", "manager",
|
||||
"director", "exec"]
|
||||
SENIORITIES: tuple[str, ...] = get_args(Seniority)
|
||||
|
||||
#: Whether a posting says it sponsors a work permit. '' is "it does not say".
|
||||
Permit = Literal["", "sponsors", "no_sponsorship"]
|
||||
PERMITS: tuple[str, ...] = get_args(Permit)
|
||||
|
||||
Status = Literal["saved", "applied", "screen", "technical", "onsite", "offer",
|
||||
"rejected", "withdrawn"]
|
||||
STATUSES: tuple[str, ...] = get_args(Status)
|
||||
@@ -74,6 +85,22 @@ STATUSES: tuple[str, ...] = get_args(Status)
|
||||
AFFINITY = range(-1, 3)
|
||||
|
||||
|
||||
def _json(value: Any, empty: str) -> Any:
|
||||
"""A JSON text column as the Python value, tolerant like `JsonDict`: a
|
||||
value that is already parsed passes, and one that does not parse is the
|
||||
empty value rather than a 500."""
|
||||
if not isinstance(value, str):
|
||||
return value
|
||||
try:
|
||||
return json.loads(value or empty)
|
||||
except ValueError:
|
||||
return json.loads(empty)
|
||||
|
||||
|
||||
#: A column holding a JSON array of strings, such as `roles.languages`.
|
||||
JsonStrings = Annotated[list[str], BeforeValidator(lambda v: _json(v, "[]"))]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ models
|
||||
|
||||
class Role(Model):
|
||||
@@ -96,6 +123,9 @@ class Role(Model):
|
||||
currency: str = ""
|
||||
seniority: str = ""
|
||||
function: str = ""
|
||||
permit: Permit = ""
|
||||
#: ISO 639-1 codes the posting says are required, lowercase.
|
||||
languages: JsonStrings = []
|
||||
description: str = ""
|
||||
feed_text: str = ""
|
||||
original_url: str = ""
|
||||
@@ -108,6 +138,20 @@ class Role(Model):
|
||||
created_at: str
|
||||
|
||||
|
||||
class ExtractResult(ModelTaskResult):
|
||||
"""What one run of `extract` did. See roledesk/jobs/extract.py."""
|
||||
|
||||
#: Roles the model answered for, whether or not it found anything to fill.
|
||||
extracted: int = 0
|
||||
#: Columns written, across those roles. A role answered with nothing the
|
||||
#: posting states adds to `extracted` and not to this.
|
||||
filled: int = 0
|
||||
|
||||
@property
|
||||
def done(self) -> int:
|
||||
return self.extracted
|
||||
|
||||
|
||||
class Company(Model):
|
||||
key: str
|
||||
name: str
|
||||
|
||||
Reference in new issue
Block a user