Skip to content

Commit

Permalink
Remove public/ imports in common/ (#147)
Browse files Browse the repository at this point in the history
* Remove public references in common/

Signed-off-by: Tyler Ohlsen <[email protected]>

* handle NPE

Signed-off-by: Tyler Ohlsen <[email protected]>

---------

Signed-off-by: Tyler Ohlsen <[email protected]>
(cherry picked from commit 23f222c)
  • Loading branch information
ohltyler authored and github-actions[bot] committed Apr 23, 2024
1 parent ae39c2e commit ee5220f
Show file tree
Hide file tree
Showing 28 changed files with 165 additions and 186 deletions.
41 changes: 41 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,47 @@ export const NEURAL_SPARSE_TOKENIZER_TRANSFORMER = {
version: '1.0.1',
} as PretrainedSparseEncodingModel;

/**
* Various constants pertaining to the drag-and-drop UI components
*/
export enum COMPONENT_CATEGORY {
INGEST = 'Ingest',
SEARCH = 'Search',
}

export enum NODE_CATEGORY {
CUSTOM = 'custom',
INGEST_GROUP = 'ingestGroup',
SEARCH_GROUP = 'searchGroup',
}

/**
* A base set of component classes / types.
*/
export enum COMPONENT_CLASS {
// Indexer-related classes
INDEXER = 'indexer',
KNN_INDEXER = 'knn_indexer',
// Retriever-related classes
RETRIEVER = 'retriever',
// Transformer-related classes
TRANSFORMER = 'transformer',
JSON_TO_JSON_TRANSFORMER = 'json_to_json_transformer',
ML_TRANSFORMER = 'ml_transformer',
TEXT_EMBEDDING_TRANSFORMER = 'text_embedding_transformer',
SPARSE_ENCODER_TRANSFORMER = 'sparse_encoder_transformer',
RESULTS_TRANSFORMER = 'results_transformer',
NORMALIZATION_TRANSFORMER = 'normalization_transformer',
// Query-related classes
QUERY = 'query',
MATCH_QUERY = 'match_query',
NEURAL_QUERY = 'neural_query',
// Document-related classes
DOCUMENT = 'document',
// Results-related classes
RESULTS = 'results',
}

/**
* MISCELLANEOUS
*/
Expand Down
3 changes: 0 additions & 3 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
export * from './constants';
export * from './interfaces';
export * from './utils';
export * from '../public/component_types';
export * from '../public/utils';
export * from '../public/pages/workflow_detail/utils';
87 changes: 84 additions & 3 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,99 @@
*/

import { Node, Edge } from 'reactflow';
import { IComponentData } from '../public/component_types';
import { COMPONENT_CLASS } from '../public/utils';
import { FormikValues } from 'formik';
import { ObjectSchema } from 'yup';
import { COMPONENT_CLASS, COMPONENT_CATEGORY } from './constants';

export type Index = {
name: string;
health: 'green' | 'yellow' | 'red';
};

/**
********** REACTFLOW TYPES/INTERFACES **********
********** WORKSPACE TYPES/INTERFACES **********
*/

export type FieldType = 'string' | 'json' | 'select' | 'model';
export type SelectType = 'model';
export type FieldValue = string | {};
export type ComponentFormValues = FormikValues;
export type WorkspaceFormValues = {
[componentId: string]: ComponentFormValues;
};
export type WorkspaceSchemaObj = {
[componentId: string]: ObjectSchema<any, any, any>;
};
export type WorkspaceSchema = ObjectSchema<WorkspaceSchemaObj>;

/**
* Represents a single base class as an input handle for a component.
* It may accept multiples of that class.
*/
export interface IComponentInput {
id: string;
label: string;
baseClass: COMPONENT_CLASS;
acceptMultiple: boolean;
}

/**
* An input field for a component. Specifies enough configuration for the
* UI node to render it properly (help text, links, etc.)
*/
export interface IComponentField {
label: string;
type: FieldType;
id: string;
value?: FieldValue;
placeholder?: string;
helpText?: string;
helpLink?: string;
selectType?: SelectType;
}

/**
* Represents the list of base classes as a single output handle for
* a component.
*/
export interface IComponentOutput {
label: string;
baseClasses: COMPONENT_CLASS[];
}

/**
* The base interface the components will implement.
*/
export interface IComponent {
type: COMPONENT_CLASS;
label: string;
description: string;
// will be used for grouping together in the drag-and-drop component library
// and determining which flows the component can be drug into the workspace flows
categories: COMPONENT_CATEGORY[];
// determines if this component allows for new creation. this means to
// allow a "create" option on the UI component, as well as potentially
// include in the use case template construction ('provisioning' flow)
allowsCreation: boolean;
// the list of base classes that will be used in the component output
baseClasses?: COMPONENT_CLASS[];
inputs?: IComponentInput[];
fields?: IComponentField[];
// if the component supports creation, we will have a different set of input fields
// the user needs to fill out
createFields?: IComponentField[];
outputs?: IComponentOutput[];
}

/**
* We need to include some extra instance-specific data to the ReactFlow component
* to perform extra functionality, such as deleting the node from the ReactFlowInstance.
*/
export interface IComponentData extends IComponent {
id: string;
selected?: boolean;
}

export type ReactFlowComponent = Node<IComponentData>;
export type ReactFlowEdge = Edge<{}> & {
key: string;
Expand Down
5 changes: 3 additions & 2 deletions public/component_types/base_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../utils';
import {
COMPONENT_CATEGORY,
COMPONENT_CLASS,
IComponent,
IComponentField,
IComponentInput,
IComponentOutput,
} from './interfaces';
} from '../../common';

/**
* A base UI drag-and-drop component class.
Expand Down
1 change: 0 additions & 1 deletion public/component_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './interfaces';
export * from './transformer';
export * from './indexer';
export * from './other';
2 changes: 1 addition & 1 deletion public/component_types/indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../common';
import { BaseComponent } from '../base_component';

/**
Expand Down
91 changes: 0 additions & 91 deletions public/component_types/interfaces.ts

This file was deleted.

2 changes: 1 addition & 1 deletion public/component_types/other/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../common';
import { BaseComponent } from '../base_component';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/other/query/match_query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CLASS } from '../../../utils';
import { COMPONENT_CLASS } from '../../../../common';
import { Query } from './query';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/other/query/neural_query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CLASS } from '../../../utils';
import { COMPONENT_CLASS } from '../../../../common';
import { Query } from './query';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/other/query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../../common';
import { BaseComponent } from '../../base_component';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/other/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../common';
import { BaseComponent } from '../base_component';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/transformer/base_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../common';
import { BaseComponent } from '../base_component';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/transformer/ml_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CLASS } from '../../../common';
import { BaseTransformer } from './base_transformer';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../../common';
import { ResultsTransformer } from './results_transformer';

/**
Expand Down
2 changes: 1 addition & 1 deletion public/component_types/transformer/results_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CLASS } from '../../utils';
import { COMPONENT_CLASS } from '../../../common';
import { BaseTransformer } from './base_transformer';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
MODEL_STATE,
ROBERTA_SENTENCE_TRANSFORMER,
WorkspaceFormValues,
isFieldInvalid,
ModelFormValue,
MODEL_CATEGORY,
MPNET_SENTENCE_TRANSFORMER,
NEURAL_SPARSE_TRANSFORMER,
NEURAL_SPARSE_DOC_TRANSFORMER,
NEURAL_SPARSE_TOKENIZER_TRANSFORMER,
} from '../../../../../common';
import { isFieldInvalid } from '../../../../utils';
import { AppState } from '../../../../store';

interface ModelFieldProps {
Expand Down
Loading

0 comments on commit ee5220f

Please sign in to comment.