integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
CohortExclusionsResponse,
|
||||
CohortScenario,
|
||||
CohortVersion,
|
||||
ModelLineage,
|
||||
ModelVersion,
|
||||
PromotionCheck,
|
||||
ReportField,
|
||||
OcrJob,
|
||||
OcrRowStatus,
|
||||
OcrRowsResponse,
|
||||
OcrRunSummary,
|
||||
} from './governance.types';
|
||||
|
||||
/** `/governance/*`: model and cohort versions, artifacts, and the OCR review queue. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GovernanceApi {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
/** `scenario` needs `domain`; `domain` alone matches every scenario of it;
|
||||
* neither matches everything. */
|
||||
listModelVersions(filters: { domain?: string; scenario?: string } = {}): Observable<{ model_versions: ModelVersion[] }> {
|
||||
return this.http.get<{ model_versions: ModelVersion[] }>('/governance/model-versions', { params: toParams(filters) });
|
||||
}
|
||||
|
||||
/** 409 with `checks` when the version doesn't meet the promotion requirements. */
|
||||
promoteModelVersion(domain: string, scenario: string, version: string): Observable<ModelVersion> {
|
||||
return this.http.post<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/promote`, {});
|
||||
}
|
||||
|
||||
retireModelVersion(domain: string, scenario: string, version: string): Observable<ModelVersion> {
|
||||
return this.http.post<ModelVersion>(`/governance/model-versions/${domain}/${scenario}/${version}/retire`, {});
|
||||
}
|
||||
|
||||
lineage(domain: string, scenario: string, version: string): Observable<ModelLineage> {
|
||||
return this.http.get<ModelLineage>(`/governance/model-versions/${domain}/${scenario}/${version}/lineage`);
|
||||
}
|
||||
|
||||
checks(domain: string, scenario: string, version: string): Observable<{ ready: boolean; checks: PromotionCheck[] }> {
|
||||
return this.http.get<{ ready: boolean; checks: PromotionCheck[] }>(`/governance/model-versions/${domain}/${scenario}/${version}/checks`);
|
||||
}
|
||||
|
||||
attachReports(domain: string, scenario: string, version: string, reports: Partial<Record<ReportField, string | null>>): Observable<ModelVersion> {
|
||||
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> {
|
||||
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);
|
||||
}
|
||||
|
||||
listCohortScenarios(): Observable<{ scenarios: CohortScenario[] }> {
|
||||
return this.http.get<{ scenarios: CohortScenario[] }>('/governance/cohort-scenarios');
|
||||
}
|
||||
|
||||
buildCohortVersion(domain: string, scenario: string, description?: string): Observable<CohortVersion> {
|
||||
return this.http.post<CohortVersion>('/governance/cohort-versions', { domain, scenario, ...(description ? { description } : {}) });
|
||||
}
|
||||
|
||||
listCohortVersions(filters: { domain?: string; scenario?: string } = {}): Observable<{ cohort_versions: CohortVersion[] }> {
|
||||
return this.http.get<{ cohort_versions: CohortVersion[] }>('/governance/cohort-versions', { params: toParams(filters) });
|
||||
}
|
||||
|
||||
getCohortExclusions(cohortVersionId: number): Observable<CohortExclusionsResponse> {
|
||||
return this.http.get<CohortExclusionsResponse>(`/governance/cohort-versions/${cohortVersionId}/exclusions`);
|
||||
}
|
||||
|
||||
listOcrJobs(): Observable<{ jobs: OcrJob[] }> {
|
||||
return this.http.get<{ jobs: OcrJob[] }>('/governance/ocr/jobs');
|
||||
}
|
||||
|
||||
listOcrRows(domain: string, entity: string, status: OcrRowStatus, limit = 100, offset = 0): Observable<OcrRowsResponse> {
|
||||
return this.http.get<OcrRowsResponse>(`/governance/ocr/${domain}/${entity}/rows`, {
|
||||
params: toParams({ status, limit, offset }),
|
||||
});
|
||||
}
|
||||
|
||||
runOcr(domain: string, entity: string): Observable<OcrRunSummary> {
|
||||
return this.http.post<OcrRunSummary>('/governance/ocr/run', { domain, entity });
|
||||
}
|
||||
|
||||
/** The stored PDF, wrapped by the caller in a `File` for the page viewer. */
|
||||
getOcrBlob(domain: string, entity: string, id: number): Observable<Blob> {
|
||||
return this.http.get(`/governance/ocr/${domain}/${entity}/${id}/blob`, { responseType: 'blob' });
|
||||
}
|
||||
|
||||
correctOcrRow(domain: string, entity: string, id: number, values: Record<string, string>, confianza?: number): Observable<Record<string, unknown>> {
|
||||
return this.http.post<Record<string, unknown>>(`/governance/ocr/${domain}/${entity}/${id}/correct`, {
|
||||
values,
|
||||
...(confianza !== undefined ? { confianza } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function toParams(filters: Record<string, string | number | boolean | undefined>): HttpParams {
|
||||
let params = new HttpParams();
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
if (value !== undefined && value !== null && value !== '') params = params.set(key, String(value));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
Reference in New Issue
Block a user