Display only text_embedding and sparse_embedding related inference endpoints (#189455)

This PR resolves https://github.com/elastic/search-team/issues/7989

In the semantic_text UI, we should display the inference endpoints
related to text_embedding and sparse_embedding only.

### Before
![Screenshot 2024-07-29 at 6 07
24 PM](https://github.com/user-attachments/assets/92ec40a0-3faf-4c5e-a155-84c09805a9a4)


### After
![Screenshot 2024-07-29 at 6 05
59 PM](https://github.com/user-attachments/assets/1ec15a7b-f388-435d-93f4-41a6284fba6f)
This commit is contained in:
Saikat Sarkar 2024-07-30 08:00:18 -06:00 committed by GitHub
parent 3a19c3501c
commit 39bde9d4eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import {
SelectInferenceIdProps,
} from '../../../public/application/components/mappings_editor/components/document_fields/field_parameters/select_inference_id';
import React from 'react';
import { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
const createInferenceEndpointMock = jest.fn();
const mockDispatch = jest.fn();
@ -60,6 +61,18 @@ jest.mock('../../../public/application/components/mappings_editor/mappings_state
useDispatch: () => mockDispatch,
}));
jest.mock('../../../public/application/services/api', () => ({
useLoadInferenceEndpoints: jest.fn().mockReturnValue({
data: [
{ model_id: 'endpoint-1', task_type: 'text_embedding' },
{ model_id: 'endpoint-2', task_type: 'sparse_embedding' },
{ model_id: 'endpoint-3', task_type: 'completion' },
] as InferenceAPIConfigResponse[],
isLoading: false,
error: null,
}),
}));
function getTestForm(Component: React.FC<SelectInferenceIdProps>) {
return (defaultProps: SelectInferenceIdProps) => {
const { form } = useForm();
@ -107,5 +120,8 @@ describe('SelectInferenceId', () => {
find('inferenceIdButton').simulate('click');
expect(find('data-inference-endpoint-list').contains('e5')).toBe(true);
expect(find('data-inference-endpoint-list').contains('elser_model_2')).toBe(true);
expect(find('data-inference-endpoint-list').contains('endpoint-1')).toBe(true);
expect(find('data-inference-endpoint-list').contains('endpoint-2')).toBe(true);
expect(find('data-inference-endpoint-list').contains('endpoint-3')).toBe(false);
});
});

View file

@ -133,11 +133,16 @@ const SelectInferenceIdContent: React.FC<SelectInferenceIdContentProps> = ({
const { isLoading, data: endpoints, resendRequest } = useLoadInferenceEndpoints();
const options: EuiSelectableOption[] = useMemo(() => {
const filteredEndpoints = endpoints?.filter(
(endpoint) =>
endpoint.task_type === 'text_embedding' || endpoint.task_type === 'sparse_embedding'
);
const missingDefaultEndpoints = defaultEndpoints.filter(
(endpoint) => !(endpoints || []).find((e) => e.model_id === endpoint.model_id)
(endpoint) => !(filteredEndpoints || []).find((e) => e.model_id === endpoint.model_id)
);
const newOptions: EuiSelectableOption[] = [
...(endpoints || []),
...(filteredEndpoints || []),
...missingDefaultEndpoints,
].map((endpoint) => ({
label: endpoint.model_id,