diff --git a/openapi.json b/openapi.json index 07d6fef..b51d389 100644 --- a/openapi.json +++ b/openapi.json @@ -979,6 +979,48 @@ "title": "Join", "type": "object" }, + "LanguageModel": { + "properties": { + "available": { + "title": "Available", + "type": "boolean" + }, + "model": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Model" + }, + "reason": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Reason" + }, + "vision": { + "title": "Vision", + "type": "boolean" + } + }, + "required": [ + "available", + "model", + "vision", + "reason" + ], + "title": "LanguageModel", + "type": "object" + }, "Link": { "additionalProperties": false, "description": "Identity rows from every input, grouped into persons (Splink).\n\nTwo records are the same person when any rule holds (Splink's SQL rule syntax, `l.`\nand `r.` for the two records); persons are the connected groups. A person whose\nrecords disagree on birth date or sex is held for review as a whole. Pairs Splink\nscores above `review` that ended up apart are queued as possible matches.", @@ -2967,6 +3009,28 @@ ] } }, + "/ingest/llm": { + "get": { + "description": "The site's language model (LLM_URL): whether it answers, which, and whether it\nreads images. Autom\u00e1tico needs it; extract nodes use their patterns without it.", + "operationId": "language_model", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageModel" + } + } + }, + "description": "Successful Response" + } + }, + "summary": "Language Model", + "tags": [ + "ingest" + ] + } + }, "/ingest/pipelines": { "get": { "operationId": "pipelines", @@ -3111,6 +3175,55 @@ ] } }, + "/ingest/pipelines/{pipeline_id}/draft": { + "post": { + "description": "Autom\u00e1tico: starts the `draft` job, which draws the whole pipeline from its saved\nsources (the only nodes it may hold), saves it as a new version and runs it; follow it\nat /runs/{run_id}.", + "operationId": "start_draft", + "parameters": [ + { + "in": "path", + "name": "pipeline_id", + "required": true, + "schema": { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "title": "Pipeline Id", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": { + "type": "string" + }, + "title": "Response Start Draft", + "type": "object" + } + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Start Draft", + "tags": [ + "ingest" + ] + } + }, "/ingest/pipelines/{pipeline_id}/nodes/{node_id}/rows": { "get": { "description": "What a node produced in the last run (empty if it produced nothing yet).", diff --git a/src/app/api/fn/ingest/language-model.ts b/src/app/api/fn/ingest/language-model.ts new file mode 100644 index 0000000..0755d84 --- /dev/null +++ b/src/app/api/fn/ingest/language-model.ts @@ -0,0 +1,30 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + +import { LanguageModel } from '../../models/language-model'; + +export interface LanguageModel$Params { +} + +export function languageModel(http: HttpClient, rootUrl: string, params?: LanguageModel$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, languageModel.PATH, 'get'); + if (params) { + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse; + }) + ); +} + +languageModel.PATH = '/ingest/llm'; diff --git a/src/app/api/fn/ingest/start-draft.ts b/src/app/api/fn/ingest/start-draft.ts new file mode 100644 index 0000000..798437b --- /dev/null +++ b/src/app/api/fn/ingest/start-draft.ts @@ -0,0 +1,35 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + + +export interface StartDraft$Params { + pipeline_id: string; +} + +export function startDraft(http: HttpClient, rootUrl: string, params: StartDraft$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, startDraft.PATH, 'post'); + if (params) { + rb.path('pipeline_id', params.pipeline_id, {}); + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse<{ + [key: string]: string; + }>; + }) + ); +} + +startDraft.PATH = '/ingest/pipelines/{pipeline_id}/draft'; diff --git a/src/app/api/functions.ts b/src/app/api/functions.ts index 422bdb6..bbb8c19 100644 --- a/src/app/api/functions.ts +++ b/src/app/api/functions.ts @@ -15,12 +15,16 @@ export type { GetConceptMap$Params as GetConceptMap$Params } from './fn/ingest/g export { getConceptMap as getConceptMap } from './fn/ingest/get-concept-map'; export type { SaveConceptMap$Params as SaveConceptMap$Params } from './fn/ingest/save-concept-map'; export { saveConceptMap as saveConceptMap } from './fn/ingest/save-concept-map'; +export type { LanguageModel$Params as LanguageModel$Params } from './fn/ingest/language-model'; +export { languageModel as languageModel } from './fn/ingest/language-model'; export type { Pipelines$Params as Pipelines$Params } from './fn/ingest/pipelines'; export { pipelines as pipelines } from './fn/ingest/pipelines'; export type { Pipeline$Params as Pipeline$Params } from './fn/ingest/pipeline'; export { pipeline as pipeline } from './fn/ingest/pipeline'; export type { SavePipeline$Params as SavePipeline$Params } from './fn/ingest/save-pipeline'; export { savePipeline as savePipeline } from './fn/ingest/save-pipeline'; +export type { StartDraft$Params as StartDraft$Params } from './fn/ingest/start-draft'; +export { startDraft as startDraft } from './fn/ingest/start-draft'; export type { NodeRows$Params as NodeRows$Params } from './fn/ingest/node-rows'; export { nodeRows as nodeRows } from './fn/ingest/node-rows'; export type { StartRun$Params as StartRun$Params } from './fn/ingest/start-run'; diff --git a/src/app/api/models.ts b/src/app/api/models.ts index c0d0dac..f69fd16 100644 --- a/src/app/api/models.ts +++ b/src/app/api/models.ts @@ -19,6 +19,7 @@ export type { Group } from './models/group'; export type { Guided } from './models/guided'; export type { HttpValidationError } from './models/http-validation-error'; export type { Join } from './models/join'; +export type { LanguageModel } from './models/language-model'; export type { Link } from './models/link'; export type { Listing } from './models/listing'; export type { Login } from './models/login'; diff --git a/src/app/api/models/language-model.ts b/src/app/api/models/language-model.ts new file mode 100644 index 0000000..1095830 --- /dev/null +++ b/src/app/api/models/language-model.ts @@ -0,0 +1,9 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +export interface LanguageModel { + available: boolean; + model: (string | null); + reason: (string | null); + vision: boolean; +} diff --git a/src/app/conectar/conectar.html b/src/app/conectar/conectar.html index a7fec54..53b7bbe 100644 --- a/src/app/conectar/conectar.html +++ b/src/app/conectar/conectar.html @@ -36,6 +36,24 @@ + @if (onlySources()) { + + + + } } @if (message()) { diff --git a/src/app/conectar/conectar.ts b/src/app/conectar/conectar.ts index d63e95f..997b3cc 100644 --- a/src/app/conectar/conectar.ts +++ b/src/app/conectar/conectar.ts @@ -23,12 +23,14 @@ import { FormlyJsonschema } from '@ngx-formly/core/json-schema'; import { withFormlyMaterial } from '@ngx-formly/material'; import { Connection, NodeChange, Vflow } from 'ngx-vflow'; import { Api } from '../api/api'; +import { languageModel } from '../api/fn/ingest/language-model'; import { nodeRows } from '../api/fn/ingest/node-rows'; import { pipeline as getPipeline } from '../api/fn/ingest/pipeline'; import { pipelines } from '../api/fn/ingest/pipelines'; import { savePipeline } from '../api/fn/ingest/save-pipeline'; import { schema } from '../api/fn/ingest/schema'; import { sourcePreview } from '../api/fn/ingest/source-preview'; +import { startDraft } from '../api/fn/ingest/start-draft'; import { startRun } from '../api/fn/ingest/start-run'; import { runStatus } from '../api/fn/runs/run-status'; import type { Pipeline } from '../api/models/pipeline'; @@ -120,6 +122,8 @@ export class Conectar { protected readonly rawError = signal(''); protected readonly list = resource({ loader: () => this.api.invoke(pipelines) }); + /** The site's language model: Automático needs it. */ + protected readonly llm = resource({ loader: () => this.api.invoke(languageModel) }); private readonly schema = resource({ loader: () => this.api.invoke(schema) }); protected readonly pipelineId = signal(undefined); @@ -136,6 +140,10 @@ export class Conectar { protected readonly doc = computed(() => this.docs().find((d) => d.id === this.selected())); protected readonly message = signal(''); protected readonly run = signal<{ id: string; status: string } | undefined>(undefined); + /** Automático drafts a pipeline that holds its sources only. */ + protected readonly onlySources = computed( + () => this.docs().length > 0 && this.docs().every((d) => d.kind === 'source'), + ); protected readonly running = computed(() => { const run = this.run(); return !!run && !['SUCCESS', 'FAILURE', 'CANCELED'].includes(run.status); @@ -395,20 +403,44 @@ export class Conectar { const id = this.pipelineId(); if (!id || !(await this.save())) return; try { - const { run_id } = await this.api.invoke(startRun, { pipeline_id: id, body: {} }); - this.run.set({ id: run_id, status: 'STARTING' }); - while (this.running()) { - await new Promise((r) => setTimeout(r, 2000)); - this.run.set({ - id: run_id, - status: (await this.api.invoke(runStatus, { run_id }))['status'], - }); + await this.follow((await this.api.invoke(startRun, { pipeline_id: id, body: {} }))['run_id']); + } catch (e) { + this.message.set(problem(e)); + } + } + + /** "Armar automáticamente": saves the sources, starts the `draft` job (the site's model + * draws the whole pipeline, saves it as a new version and runs it) and, once it ends, + * shows the version drawn. */ + protected async automatic(): Promise { + const id = this.pipelineId(); + if (!id || !(await this.save())) return; + try { + this.message.set('Armando la canalización: se leen los documentos y el modelo los revisa.'); + await this.follow((await this.api.invoke(startDraft, { pipeline_id: id }))['run_id']); + if (this.run()?.status === 'SUCCESS') { + await this.open(id); + this.message.set( + `Versión ${this.version()} armada y ejecutada. Revise lo que queda en Revisión.`, + ); + this.list.reload(); } } catch (e) { this.message.set(problem(e)); } } + private async follow(run_id: string): Promise { + this.run.set({ id: run_id, status: 'STARTING' }); + while (this.running()) { + await new Promise((r) => setTimeout(r, 2000)); + this.run.set({ + id: run_id, + status: (await this.api.invoke(runStatus, { run_id }))['status'], + }); + } + } + /** What the node gives: a source's first rows, or what any other node gave in the last run. */ protected async show(): Promise { const doc = this.doc(); diff --git a/src/app/revision/revision.html b/src/app/revision/revision.html index 312d50c..6097899 100644 --- a/src/app/revision/revision.html +++ b/src/app/revision/revision.html @@ -219,8 +219,20 @@ @if (c['probability'] !== null) { · p = {{ $any(c['probability']) | number: '1.2-2' }} } - + + @if ($any(c['suggestion']); as s) { + Sugerencia del modelo: + {{ + s.same === true + ? 'misma paciente' + : s.same === false + ? 'distintas' + : 'no se puede saber' + }}. {{ s.reason }} + } +