fix governance reqs; allow for sandboxed jupyter notebooks for testing

This commit is contained in:
Roberto Treviño Cervantes
2026-11-13 11:52:42 -06:00
parent e6abf44bef
commit 934a793da3
14 changed files with 882 additions and 61 deletions
+46 -7
View File
@@ -2,6 +2,10 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import {
CohortBuildFile,
Experiment,
ExperimentDetail,
ExperimentRequest,
ModelLineage,
ModelVersion,
PromotionCheck,
@@ -12,7 +16,7 @@ import {
OcrRunSummary,
} from './governance.types';
/** `/governance/*`: model versions, artifacts, and the OCR review queue. */
/** `/governance/*`: model versions and their files, notebooks run on a cohort build, and the OCR review queue. */
@Injectable({ providedIn: 'root' })
export class GovernanceApi {
private readonly http = inject(HttpClient);
@@ -44,13 +48,44 @@ export class GovernanceApi {
return this.http.patch<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/reports`, reports);
}
/** Logs the file to the version's MLflow run. Browsing/downloading a
* logged artifact goes through the MLflow tracking server directly. */
uploadArtifact(domain: string, scenario: string, version: string, kind: string, file: File): Observable<ModelVersion> {
/** Where a file the version's run stored downloads from; a folder comes as a zip. */
artifactUrl(domain: string, scenario: string, version: string, path: string): string {
return `/governance/model-versions/${domain}/${scenario}/${version}/artifacts/${encodePath(path)}`;
}
/** The domain's cohort builds that have their file. */
cohortFiles(domain: string): Observable<{ builds: CohortBuildFile[] }> {
return this.http.get<{ builds: CohortBuildFile[] }>('/governance/cohort-files', { params: toParams({ domain }) });
}
listExperiments(filters: { domain?: string; scenario?: string } = {}): Observable<{ experiments: Experiment[] }> {
return this.http.get<{ experiments: Experiment[] }>('/governance/experiments', { params: toParams(filters) });
}
/** Starts the notebook on the build in the background; answers with the run while it is still `en_curso`. */
runExperiment(request: ExperimentRequest): Observable<ExperimentDetail> {
const form = new FormData();
form.append('file', file);
form.append('kind', kind);
return this.http.post<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/artifacts`, form);
form.append('file', request.file);
form.append('domain', request.domain);
form.append('scenario', request.scenario);
form.append('url', request.build.url);
form.append('source', request.build.source);
form.append('build', String(request.build.build));
if (request.version) form.append('version', request.version);
return this.http.post<ExperimentDetail>('/governance/experiments', form);
}
getExperiment(runId: string): Observable<ExperimentDetail> {
return this.http.get<ExperimentDetail>(`/governance/experiments/${runId}`);
}
/** The rendered page, served sandboxed; opened in its own tab. */
experimentPageUrl(runId: string): string {
return `/governance/experiments/${runId}/page`;
}
experimentArtifactUrl(runId: string, path: string): string {
return `/governance/experiments/${runId}/artifacts/${encodePath(path)}`;
}
listOcrJobs(): Observable<{ jobs: OcrJob[] }> {
@@ -80,6 +115,10 @@ export class GovernanceApi {
}
}
function encodePath(path: string): string {
return path.split('/').map(encodeURIComponent).join('/');
}
function toParams(filters: Record<string, string | number | boolean | undefined>): HttpParams {
let params = new HttpParams();
for (const [key, value] of Object.entries(filters)) {
+51 -4
View File
@@ -27,19 +27,66 @@ export interface PromotionCheck {
detail: string;
}
/** A logged artifact's path within the run, e.g. `ONNX_CHECKPOINT/model.onnx`
* — browsing/downloading the file itself goes through MLflow directly. */
export type ArtifactPath = string;
/** A file a run stored, by its path within the run (`rutinas/MUESTREO.json`, `model/MLmodel`). */
export interface ArtifactFile {
path: string;
size: number | null;
}
/** The routines training records as it runs (ML-01a), each under its kind. */
export type RoutineKind = 'MUESTREO' | 'DATOS_FALTANTES' | 'METODO_ANALITICO' | 'BALANCE_CLASES' | 'CONFIANZA_SALIDA';
export interface ModelLineage {
model_version: ModelVersion;
cohorte_armado: CohorteArmado | null;
cohorte_exclusiones: CohorteExclusion[];
artifacts: ArtifactPath[];
artifacts: ArtifactFile[];
/** What each routine did, as its run recorded it; a kind is missing when the run didn't record it. */
routines: Partial<Record<RoutineKind, Record<string, unknown>>>;
predictions: number;
checks: PromotionCheck[];
}
/** A cohort build that has its file, the data a notebook can run on. */
export interface CohortBuildFile {
url: string;
source: 'kit' | 'dbt';
build: number;
datos_as_of: string | null;
n_members: string | null;
}
export type ExperimentStatus = 'en_curso' | 'terminado' | 'fallido' | 'interrumpido';
/** A notebook run on a cohort build, kept as an MLflow run. */
export interface Experiment {
run_id: string;
notebook: string;
domain: Domain;
scenario: string;
version: string | null;
cohort: { url: string; source: string; build: string };
notebook_sha256: string;
/** Where it ran: `contenedor` (isolated: no network, no server files) or `local` (in the API's own process). */
sandbox: 'contenedor' | 'local' | null;
status: ExperimentStatus;
started_at: string | null;
ended_at: string | null;
}
export interface ExperimentDetail extends Experiment {
artifacts: ArtifactFile[];
error: string | null;
}
export interface ExperimentRequest {
file: File;
domain: Domain;
scenario: string;
build: CohortBuildFile;
version?: string | null;
}
/** The indicator kit's cohort build the version was trained on. */
export interface CohorteArmado {
armado_id: number;