|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | import moment from 'moment';
|
7 |
| -import { MarkerType } from 'reactflow'; |
8 |
| -import { |
9 |
| - WorkspaceFlowState, |
10 |
| - ReactFlowComponent, |
11 |
| - initComponentData, |
12 |
| - TextEmbeddingTransformer, |
13 |
| - KnnIndexer, |
14 |
| - generateId, |
15 |
| - ReactFlowEdge, |
16 |
| - TemplateFlows, |
17 |
| - WorkflowTemplate, |
18 |
| - DATE_FORMAT_PATTERN, |
19 |
| - COMPONENT_CATEGORY, |
20 |
| - NODE_CATEGORY, |
21 |
| - WorkspaceFormValues, |
22 |
| -} from './'; |
23 |
| - |
24 |
| -// TODO: implement this and remove hardcoded return values |
25 |
| -/** |
26 |
| - * Given a ReactFlow workspace flow and the set of current form values within such flow, |
27 |
| - * generate a backend-compatible set of sub-workflows. |
28 |
| - * |
29 |
| - */ |
30 |
| -export function toTemplateFlows( |
31 |
| - workspaceFlow: WorkspaceFlowState, |
32 |
| - formValues: WorkspaceFormValues |
33 |
| -): TemplateFlows { |
34 |
| - const textEmbeddingTransformerNodeId = Object.keys(formValues).find((key) => |
35 |
| - key.includes('text_embedding') |
36 |
| - ) as string; |
37 |
| - const knnIndexerNodeId = Object.keys(formValues).find((key) => |
38 |
| - key.includes('knn') |
39 |
| - ) as string; |
40 |
| - const textEmbeddingFields = formValues[textEmbeddingTransformerNodeId]; |
41 |
| - const knnIndexerFields = formValues[knnIndexerNodeId]; |
42 |
| - |
43 |
| - return { |
44 |
| - provision: { |
45 |
| - nodes: [ |
46 |
| - { |
47 |
| - id: 'create_ingest_pipeline', |
48 |
| - type: 'create_ingest_pipeline', |
49 |
| - user_inputs: { |
50 |
| - pipeline_id: 'test-pipeline', |
51 |
| - model_id: textEmbeddingFields['modelId'], |
52 |
| - input_field: textEmbeddingFields['inputField'], |
53 |
| - output_field: textEmbeddingFields['vectorField'], |
54 |
| - configurations: { |
55 |
| - description: 'A text embedding ingest pipeline', |
56 |
| - processors: [ |
57 |
| - { |
58 |
| - text_embedding: { |
59 |
| - model_id: textEmbeddingFields['modelId'], |
60 |
| - field_map: { |
61 |
| - [textEmbeddingFields['inputField']]: |
62 |
| - textEmbeddingFields['vectorField'], |
63 |
| - }, |
64 |
| - }, |
65 |
| - }, |
66 |
| - ], |
67 |
| - }, |
68 |
| - }, |
69 |
| - }, |
70 |
| - { |
71 |
| - id: 'create_index', |
72 |
| - type: 'create_index', |
73 |
| - previous_node_inputs: { |
74 |
| - create_ingest_pipeline: 'pipeline_id', |
75 |
| - }, |
76 |
| - user_inputs: { |
77 |
| - index_name: knnIndexerFields['indexName'], |
78 |
| - configurations: { |
79 |
| - settings: { |
80 |
| - default_pipeline: '${{create_ingest_pipeline.pipeline_id}}', |
81 |
| - }, |
82 |
| - mappings: { |
83 |
| - properties: { |
84 |
| - [textEmbeddingFields['vectorField']]: { |
85 |
| - type: 'knn_vector', |
86 |
| - dimension: 768, |
87 |
| - method: { |
88 |
| - engine: 'lucene', |
89 |
| - space_type: 'l2', |
90 |
| - name: 'hnsw', |
91 |
| - parameters: {}, |
92 |
| - }, |
93 |
| - }, |
94 |
| - [textEmbeddingFields['inputField']]: { |
95 |
| - type: 'text', |
96 |
| - }, |
97 |
| - }, |
98 |
| - }, |
99 |
| - }, |
100 |
| - }, |
101 |
| - }, |
102 |
| - ], |
103 |
| - }, |
104 |
| - }; |
105 |
| -} |
106 |
| - |
107 |
| -// TODO: implement this and remove hardcoded return values |
108 |
| -/** |
109 |
| - * Converts a backend set of provision/ingest/search sub-workflows into a UI-compatible set of |
110 |
| - * ReactFlow nodes and edges |
111 |
| - */ |
112 |
| -export function toWorkspaceFlow( |
113 |
| - templateFlows: TemplateFlows |
114 |
| -): WorkspaceFlowState { |
115 |
| - const ingestId1 = generateId('text_embedding_processor'); |
116 |
| - const ingestId2 = generateId('knn_index'); |
117 |
| - const ingestGroupId = generateId(COMPONENT_CATEGORY.INGEST); |
118 |
| - const searchGroupId = generateId(COMPONENT_CATEGORY.SEARCH); |
119 |
| - const edgeId = generateId('edge'); |
120 |
| - |
121 |
| - const ingestNodes = [ |
122 |
| - { |
123 |
| - id: ingestGroupId, |
124 |
| - position: { x: 400, y: 400 }, |
125 |
| - type: NODE_CATEGORY.INGEST_GROUP, |
126 |
| - data: { label: COMPONENT_CATEGORY.INGEST }, |
127 |
| - style: { |
128 |
| - width: 900, |
129 |
| - height: 400, |
130 |
| - }, |
131 |
| - className: 'reactflow__group-node__ingest', |
132 |
| - selectable: true, |
133 |
| - deletable: false, |
134 |
| - }, |
135 |
| - { |
136 |
| - id: ingestId1, |
137 |
| - position: { x: 100, y: 70 }, |
138 |
| - data: initComponentData( |
139 |
| - new TextEmbeddingTransformer().toObj(), |
140 |
| - ingestId1 |
141 |
| - ), |
142 |
| - type: NODE_CATEGORY.CUSTOM, |
143 |
| - parentNode: ingestGroupId, |
144 |
| - extent: 'parent', |
145 |
| - draggable: true, |
146 |
| - deletable: false, |
147 |
| - }, |
148 |
| - { |
149 |
| - id: ingestId2, |
150 |
| - position: { x: 500, y: 70 }, |
151 |
| - data: initComponentData(new KnnIndexer().toObj(), ingestId2), |
152 |
| - type: NODE_CATEGORY.CUSTOM, |
153 |
| - parentNode: ingestGroupId, |
154 |
| - extent: 'parent', |
155 |
| - draggable: true, |
156 |
| - deletable: false, |
157 |
| - }, |
158 |
| - ] as ReactFlowComponent[]; |
159 |
| - |
160 |
| - const searchNodes = [ |
161 |
| - { |
162 |
| - id: searchGroupId, |
163 |
| - position: { x: 400, y: 1000 }, |
164 |
| - type: NODE_CATEGORY.SEARCH_GROUP, |
165 |
| - data: { label: COMPONENT_CATEGORY.SEARCH }, |
166 |
| - style: { |
167 |
| - width: 900, |
168 |
| - height: 400, |
169 |
| - }, |
170 |
| - className: 'reactflow__group-node__search', |
171 |
| - selectable: true, |
172 |
| - deletable: false, |
173 |
| - }, |
174 |
| - ] as ReactFlowComponent[]; |
175 |
| - |
176 |
| - return { |
177 |
| - nodes: [...ingestNodes, ...searchNodes], |
178 |
| - edges: [ |
179 |
| - { |
180 |
| - id: edgeId, |
181 |
| - key: edgeId, |
182 |
| - source: ingestId1, |
183 |
| - target: ingestId2, |
184 |
| - markerEnd: { |
185 |
| - type: MarkerType.ArrowClosed, |
186 |
| - width: 20, |
187 |
| - height: 20, |
188 |
| - }, |
189 |
| - zIndex: 2, |
190 |
| - deletable: false, |
191 |
| - }, |
192 |
| - ] as ReactFlowEdge[], |
193 |
| - }; |
194 |
| -} |
195 |
| - |
196 |
| -// TODO: implement this |
197 |
| -/** |
198 |
| - * Validates the UI workflow state. |
199 |
| - * Note we don't have to validate connections since that is done via input/output handlers. |
200 |
| - * But we need to validate there are no open connections |
201 |
| - */ |
202 |
| -export function validateWorkspaceFlow( |
203 |
| - workspaceFlow: WorkspaceFlowState |
204 |
| -): boolean { |
205 |
| - return true; |
206 |
| -} |
207 |
| - |
208 |
| -// TODO: implement this |
209 |
| -/** |
210 |
| - * Validates the backend template. May be used when parsing persisted templates on server-side, |
211 |
| - * or when importing/exporting on the UI. |
212 |
| - */ |
213 |
| -export function validateWorkflowTemplate( |
214 |
| - workflowTemplate: WorkflowTemplate |
215 |
| -): boolean { |
216 |
| - return true; |
217 |
| -} |
| 7 | +import { DATE_FORMAT_PATTERN } from './'; |
218 | 8 |
|
219 | 9 | export function toFormattedDate(timestampMillis: number): String {
|
220 | 10 | return moment(new Date(timestampMillis)).format(DATE_FORMAT_PATTERN);
|
|
0 commit comments