Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Complete conversions between config <-> form <-> template #157

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
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
Loading