Automático: draft endpoint, model status and end-to-end test

This commit is contained in:
Roberto Treviño
2026-12-03 10:42:17 -06:00
parent bd06a31d52
commit 70c88c54dd
2 changed files with 101 additions and 1 deletions
+37 -1
View File
@@ -10,7 +10,7 @@ from pydantic import BaseModel
from core import concept_map
from core.pipeline import ID_PATTERN, ImportPath, Pipeline, Source, redacted, restored
from core.schema import ENTITIES
from persistance import config_log, nodes
from persistance import config_log, llm, nodes
from webapi.runs import dagster
router = APIRouter(prefix="/ingest", tags=["ingest"])
@@ -140,6 +140,42 @@ def submit(client: DagsterGraphQLClient, pipeline_id: str, version: int | None =
raise HTTPException(502, detail=str(e)) from e
class LanguageModel(BaseModel):
available: bool
model: str | None
vision: bool # reads page images (scans), not only their OCR text
reason: str | None # why it is not available
@router.get("/llm")
def language_model() -> LanguageModel:
"""The site's language model (LLM_URL): whether it answers, which, and whether it
reads images. Automático needs it; extract nodes use their patterns without it."""
return LanguageModel(**llm.status())
@router.post("/pipelines/{pipeline_id}/draft")
def start_draft(
pipeline_id: PipelineId, client: DagsterGraphQLClient = Depends(dagster)
) -> dict[str, str]:
"""Automático: starts the `draft` job, which draws the whole pipeline from its saved
sources (the only nodes it may hold), saves it as a new version and runs it; follow it
at /runs/{run_id}."""
if not config_log.latest_version(pipeline_id):
raise HTTPException(404, detail=f"no pipeline {pipeline_id}")
_, saved = config_log.get(pipeline_id)
if not saved.nodes or any(n.kind != "source" for n in saved.nodes):
raise HTTPException(422, detail="Automático arma la canalización a partir de sus "
"fuentes: guárdela solo con ellas.") # fmt: skip
if not (found := llm.status())["available"]:
raise HTTPException(503, detail=f"El modelo de lenguaje no responde: {found['reason']}")
config = {"ops": {"draft_pipeline": {"config": {"pipeline": pipeline_id}}}}
try:
return {"run_id": client.submit_job_execution("draft", run_config=config)}
except DagsterGraphQLClientError as e:
raise HTTPException(502, detail=str(e)) from e
@router.get("/pipelines/{pipeline_id}/nodes/{node_id}/rows")
def node_rows(
pipeline_id: PipelineId,