Skip to content

Commit

Permalink
Complete conversions between config <-> form <-> template (#156)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed May 16, 2024
1 parent dcef748 commit 0d73288
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 303 deletions.
13 changes: 13 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ export const NEURAL_SPARSE_TOKENIZER_TRANSFORMER = {
version: '1.0.1',
} as PretrainedSparseEncodingModel;

/**
* Various constants pertaining to Workflow configs
*/

export enum PROCESSOR_TYPE {
MODEL = 'model_processor',
}

export enum MODEL_TYPE {
TEXT_EMBEDDING = 'text_embedding',
SPARSE_ENCODER = 'sparse_encoder',
}

/**
* Various constants pertaining to the drag-and-drop UI components
*/
Expand Down
21 changes: 17 additions & 4 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import { Node, Edge } from 'reactflow';
import { FormikValues } from 'formik';
import { ObjectSchema } from 'yup';
import { COMPONENT_CLASS, COMPONENT_CATEGORY } from './constants';
import {
COMPONENT_CLASS,
COMPONENT_CATEGORY,
PROCESSOR_TYPE,
MODEL_TYPE,
} from './constants';

export type Index = {
name: string;
Expand Down Expand Up @@ -42,8 +47,16 @@ export interface IConfig {
metadata?: IConfigMetadata;
}

export interface IProcessorConfig extends IConfig {
type: PROCESSOR_TYPE;
}

export interface IModelProcessorConfig extends IProcessorConfig {
modelType: MODEL_TYPE;
}

export type EnrichConfig = {
processors: IConfig[];
processors: IProcessorConfig[];
};

export type IndexConfig = {
Expand All @@ -63,8 +76,8 @@ export type SearchConfig = {
};

export type WorkflowConfig = {
ingest?: IngestConfig;
search?: SearchConfig;
ingest: IngestConfig;
search: SearchConfig;
};

export type WorkflowFormValues = {
Expand Down
2 changes: 0 additions & 2 deletions public/configs/ingest_processors/base_ingest_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { BaseConfig } from '../base_config';
*/
export abstract class BaseIngestProcessor extends BaseConfig {
name: string;
type: string;
constructor() {
super();
this.name = '';
this.type = '';
}
}
17 changes: 17 additions & 0 deletions public/configs/ingest_processors/model_processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MODEL_TYPE } from '../../../common';
import { BaseIngestProcessor } from './base_ingest_processor';

/**
* A base model processor config
*/
export abstract class ModelProcessor extends BaseIngestProcessor {
type: MODEL_TYPE;
constructor() {
super();
}
}
7 changes: 4 additions & 3 deletions public/configs/ingest_processors/text_embedding_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { MODEL_TYPE } from '../../../common';
import { generateId } from '../../utils';
import { BaseIngestProcessor } from './base_ingest_processor';
import { ModelProcessor } from './model_processor';

/**
* A specialized text embedding processor config
*/
export class TextEmbeddingProcessor extends BaseIngestProcessor {
export class TextEmbeddingProcessor extends ModelProcessor {
constructor() {
super();
this.id = generateId('text_embedding_processor');
this.name = 'Text embedding processor';
this.type = 'text_embedding';
this.type = MODEL_TYPE.TEXT_EMBEDDING;
this.fields = [
{
label: 'Text Embedding Model',
Expand Down
6 changes: 5 additions & 1 deletion public/pages/workflow_detail/resizable_workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ReactFlowEdge,
WorkflowFormValues,
WorkflowSchema,
WorkflowConfig,
} from '../../../common';
import {
APP_PATH,
Expand Down Expand Up @@ -222,7 +223,10 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
setIsSaving(false);
} else {
setFormValidOnSubmit(true);
const updatedConfig = formikToUiConfig(formikProps.values);
const updatedConfig = formikToUiConfig(
formikProps.values,
workflow?.ui_metadata?.config as WorkflowConfig
);
const updatedWorkflow = {
...workflow,
ui_metadata: {
Expand Down
Loading

0 comments on commit 0d73288

Please sign in to comment.