|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import { PROCESSOR_TYPE, WORKFLOW_TYPE } from '../common/constants'; |
| 6 | +import { WORKFLOW_TYPE } from '../common/constants'; |
| 7 | +import { UIState, Workflow } from '../common/interfaces'; |
7 | 8 | import {
|
8 |
| - IProcessorConfig, |
9 |
| - ProcessorsConfig, |
10 |
| - Workflow, |
11 |
| -} from '../common/interfaces'; |
| 9 | + fetchEmptyMetadata, |
| 10 | + fetchHybridSearchMetadata, |
| 11 | + fetchMultimodalSearchMetadata, |
| 12 | + fetchSemanticSearchMetadata, |
| 13 | +} from '../public/pages/workflows/new_workflow/utils'; |
12 | 14 |
|
13 | 15 | export function mockStore(
|
14 | 16 | workflowId: string,
|
@@ -49,222 +51,30 @@ function generateWorkflow(
|
49 | 51 | id: workflowId,
|
50 | 52 | name: workflowName,
|
51 | 53 | version: { template: '1.0.0', compatibility: ['2.17.0', '3.0.0'] },
|
52 |
| - ui_metadata: { |
53 |
| - type: workflowType, |
54 |
| - config: { |
55 |
| - search: { |
56 |
| - pipelineName: { |
57 |
| - id: 'pipelineName', |
58 |
| - type: 'string', |
59 |
| - value: 'search_pipeline', |
60 |
| - }, |
61 |
| - request: { |
62 |
| - id: 'request', |
63 |
| - type: 'json', |
64 |
| - value: '{\n "query": {\n "match_all": {}\n },\n "size": 1000\n}', |
65 |
| - }, |
66 |
| - index: { name: { id: 'indexName', type: 'string' } }, |
67 |
| - enrichRequest: getRequestProcessor(workflowType), |
68 |
| - enrichResponse: getResponseProcessor(workflowType), |
69 |
| - }, |
70 |
| - ingest: { |
71 |
| - pipelineName: { |
72 |
| - id: 'pipelineName', |
73 |
| - type: 'string', |
74 |
| - value: 'ingest_pipeline', |
75 |
| - }, |
76 |
| - enrich: getRequestProcessor(workflowType), |
77 |
| - index: { |
78 |
| - settings: { id: 'indexSettings', type: 'json' }, |
79 |
| - mappings: { |
80 |
| - id: 'indexMappings', |
81 |
| - type: 'json', |
82 |
| - value: '{\n "properties": {}\n}', |
83 |
| - }, |
84 |
| - name: { |
85 |
| - id: 'indexName', |
86 |
| - type: 'string', |
87 |
| - value: 'my-new-index', |
88 |
| - }, |
89 |
| - }, |
90 |
| - enabled: { id: 'enabled', type: 'boolean', value: true }, |
91 |
| - }, |
92 |
| - }, |
93 |
| - }, |
| 54 | + ui_metadata: getConfig(workflowType), |
94 | 55 | };
|
95 | 56 | }
|
96 |
| - |
97 |
| -function getRequestProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig { |
98 |
| - if ( |
99 |
| - workflowType === WORKFLOW_TYPE.HYBRID_SEARCH || |
100 |
| - workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH |
101 |
| - ) { |
102 |
| - // TODO: In the code below, only the ml_inference processor has been added. Other processors still need to be included. |
103 |
| - const mlInferenceProcessor: IProcessorConfig = { |
104 |
| - name: 'ML Inference Processor', |
105 |
| - id: 'ml_processor_ingest', |
106 |
| - fields: [ |
107 |
| - { |
108 |
| - id: 'model', |
109 |
| - type: 'model', |
110 |
| - value: { |
111 |
| - id: 'dfMPE5EB8_-RPNi-S0gD', |
112 |
| - }, |
113 |
| - }, |
114 |
| - { |
115 |
| - id: 'input_map', |
116 |
| - type: 'mapArray', |
117 |
| - value: [ |
118 |
| - [ |
119 |
| - { |
120 |
| - value: 'my_text', |
121 |
| - key: '', |
122 |
| - }, |
123 |
| - ], |
124 |
| - ], |
125 |
| - }, |
126 |
| - { |
127 |
| - id: 'output_map', |
128 |
| - type: 'mapArray', |
129 |
| - value: [ |
130 |
| - [ |
131 |
| - { |
132 |
| - value: '', |
133 |
| - key: 'my_embedding', |
134 |
| - }, |
135 |
| - ], |
136 |
| - ], |
137 |
| - }, |
138 |
| - ], |
139 |
| - type: PROCESSOR_TYPE.ML, |
140 |
| - optionalFields: [ |
141 |
| - { |
142 |
| - id: 'query_template', |
143 |
| - type: 'jsonString', |
144 |
| - value: getQueryTemplate(workflowType), |
145 |
| - }, |
146 |
| - { |
147 |
| - id: 'description', |
148 |
| - type: 'string', |
149 |
| - }, |
150 |
| - { |
151 |
| - id: 'model_config', |
152 |
| - type: 'json', |
153 |
| - }, |
154 |
| - { |
155 |
| - id: 'full_response_path', |
156 |
| - type: 'boolean', |
157 |
| - value: false, |
158 |
| - }, |
159 |
| - { |
160 |
| - id: 'ignore_missing', |
161 |
| - type: 'boolean', |
162 |
| - value: false, |
163 |
| - }, |
164 |
| - { |
165 |
| - id: 'ignore_failure', |
166 |
| - type: 'boolean', |
167 |
| - value: false, |
168 |
| - }, |
169 |
| - { |
170 |
| - id: 'max_prediction_tasks', |
171 |
| - type: 'number', |
172 |
| - value: 10, |
173 |
| - }, |
174 |
| - { |
175 |
| - id: 'tag', |
176 |
| - type: 'string', |
177 |
| - }, |
178 |
| - ], |
179 |
| - }; |
180 |
| - return { |
181 |
| - processors: [mlInferenceProcessor], |
182 |
| - }; |
183 |
| - } |
184 |
| - |
185 |
| - return { processors: [] }; |
186 |
| -} |
187 |
| - |
188 |
| -// Function to get the query template based on workflow type |
189 |
| -function getQueryTemplate(workflowType: WORKFLOW_TYPE) { |
190 |
| - if (workflowType === WORKFLOW_TYPE.HYBRID_SEARCH) { |
191 |
| - return `{ |
192 |
| - "_source": { |
193 |
| - "excludes": ["my_embedding"] |
194 |
| - }, |
195 |
| - "query": { |
196 |
| - "hybrid": { |
197 |
| - "queries": [ |
198 |
| - { |
199 |
| - "match": { |
200 |
| - "my_text": { |
201 |
| - "query": "{{query_text}}" |
202 |
| - } |
203 |
| - } |
204 |
| - }, |
205 |
| - { |
206 |
| - "knn": { |
207 |
| - "my_embedding": { |
208 |
| - "vector": jest.fn(), |
209 |
| - "k": 10 |
210 |
| - } |
211 |
| - } |
212 |
| - } |
213 |
| - ] |
214 |
| - } |
215 |
| - } |
216 |
| - }`; |
217 |
| - } |
218 |
| - |
219 |
| - if (workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH) { |
220 |
| - return `{ |
221 |
| - "_source": { |
222 |
| - "excludes": ["my_embedding"] |
223 |
| - }, |
224 |
| - "query": { |
225 |
| - "knn": { |
226 |
| - "my_embedding": { |
227 |
| - "vector": jest.fn(), |
228 |
| - "k": 10 |
229 |
| - } |
230 |
| - } |
231 |
| - } |
232 |
| - }`; |
| 57 | +function getConfig(workflowType: WORKFLOW_TYPE) { |
| 58 | + let uiMetadata = {} as UIState; |
| 59 | + switch (workflowType) { |
| 60 | + case WORKFLOW_TYPE.SEMANTIC_SEARCH: { |
| 61 | + uiMetadata = fetchSemanticSearchMetadata(); |
| 62 | + break; |
| 63 | + } |
| 64 | + case WORKFLOW_TYPE.MULTIMODAL_SEARCH: { |
| 65 | + uiMetadata = fetchMultimodalSearchMetadata(); |
| 66 | + break; |
| 67 | + } |
| 68 | + case WORKFLOW_TYPE.HYBRID_SEARCH: { |
| 69 | + uiMetadata = fetchHybridSearchMetadata(); |
| 70 | + break; |
| 71 | + } |
| 72 | + default: { |
| 73 | + uiMetadata = fetchEmptyMetadata(); |
| 74 | + break; |
| 75 | + } |
233 | 76 | }
|
234 |
| -} |
235 |
| - |
236 |
| -function getResponseProcessor(workflowType: WORKFLOW_TYPE): ProcessorsConfig { |
237 |
| - return workflowType === WORKFLOW_TYPE.HYBRID_SEARCH |
238 |
| - ? { |
239 |
| - processors: [ |
240 |
| - { |
241 |
| - id: 'normalization_processor', |
242 |
| - name: 'Normalization Processor', |
243 |
| - type: PROCESSOR_TYPE.NORMALIZATION, |
244 |
| - fields: [], |
245 |
| - optionalFields: [ |
246 |
| - { id: 'weights', type: 'string', value: '0.5, 0.5' }, |
247 |
| - { |
248 |
| - id: 'normalization_technique', |
249 |
| - type: 'select', |
250 |
| - selectOptions: ['min_max', 'l2'], |
251 |
| - }, |
252 |
| - { |
253 |
| - id: 'combination_technique', |
254 |
| - type: 'select', |
255 |
| - selectOptions: [ |
256 |
| - 'arithmetic_mean', |
257 |
| - 'geometric_mean', |
258 |
| - 'harmonic_mean', |
259 |
| - ], |
260 |
| - }, |
261 |
| - { id: 'description', type: 'string' }, |
262 |
| - { id: 'tag', type: 'string' }, |
263 |
| - ], |
264 |
| - }, |
265 |
| - ], |
266 |
| - } |
267 |
| - : { processors: [] }; |
| 77 | + return uiMetadata; |
268 | 78 | }
|
269 | 79 |
|
270 | 80 | export const resizeObserverMock = jest.fn().mockImplementation(() => ({
|
|
0 commit comments