[Search] Adding tech preview for sprinkles model (#211519)

## Summary

Adding `Tech Preview` for `rainbow sprinkles` model


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Samiul Monir 2025-02-18 09:21:09 -05:00 committed by GitHub
parent e6709dd78f
commit 169230eb44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 20 deletions

View file

@ -80,6 +80,14 @@ const inferenceEndpoints = [
return_documents: true,
},
},
{
inference_id: '.sparkles',
task_type: 'chat_completion',
service: 'elastic',
service_settings: {
model_id: 'rainbow-sprinkles',
},
},
] as InferenceAPIConfigResponse[];
jest.mock('../../hooks/use_delete_endpoint', () => ({
@ -95,10 +103,11 @@ describe('When the tabular page is loaded', () => {
const rows = screen.getAllByRole('row');
expect(rows[1]).toHaveTextContent('.elser-2-elasticsearch');
expect(rows[2]).toHaveTextContent('.multilingual-e5-small-elasticsearch');
expect(rows[3]).toHaveTextContent('elastic-rerank');
expect(rows[4]).toHaveTextContent('local-model');
expect(rows[5]).toHaveTextContent('my-elser-model-05');
expect(rows[6]).toHaveTextContent('third-party-model');
expect(rows[3]).toHaveTextContent('.sparkles');
expect(rows[4]).toHaveTextContent('elastic-rerank');
expect(rows[5]).toHaveTextContent('local-model');
expect(rows[6]).toHaveTextContent('my-elser-model-05');
expect(rows[7]).toHaveTextContent('third-party-model');
});
it('should display all service and model ids in the table', () => {
@ -111,17 +120,20 @@ describe('When the tabular page is loaded', () => {
expect(rows[2]).toHaveTextContent('Elasticsearch');
expect(rows[2]).toHaveTextContent('.multilingual-e5-small');
expect(rows[3]).toHaveTextContent('Elasticsearch');
expect(rows[3]).toHaveTextContent('.rerank-v1');
expect(rows[3]).toHaveTextContent('Elastic');
expect(rows[3]).toHaveTextContent('rainbow-sprinkles');
expect(rows[4]).toHaveTextContent('Elasticsearch');
expect(rows[4]).toHaveTextContent('.own_model');
expect(rows[4]).toHaveTextContent('.rerank-v1');
expect(rows[5]).toHaveTextContent('Elasticsearch');
expect(rows[5]).toHaveTextContent('.elser_model_2');
expect(rows[5]).toHaveTextContent('.own_model');
expect(rows[6]).toHaveTextContent('OpenAI');
expect(rows[6]).toHaveTextContent('.own_model');
expect(rows[6]).toHaveTextContent('Elasticsearch');
expect(rows[6]).toHaveTextContent('.elser_model_2');
expect(rows[7]).toHaveTextContent('OpenAI');
expect(rows[7]).toHaveTextContent('.own_model');
});
it('should only disable delete action for preconfigured endpoints', () => {
@ -152,9 +164,10 @@ describe('When the tabular page is loaded', () => {
const rows = screen.getAllByRole('row');
expect(rows[1]).toHaveTextContent(preconfigured);
expect(rows[2]).toHaveTextContent(preconfigured);
expect(rows[3]).not.toHaveTextContent(preconfigured);
expect(rows[3]).toHaveTextContent(preconfigured);
expect(rows[4]).not.toHaveTextContent(preconfigured);
expect(rows[5]).not.toHaveTextContent(preconfigured);
expect(rows[6]).not.toHaveTextContent(preconfigured);
});
it('should show tech preview badge only for reranker-v1 model', () => {
@ -166,8 +179,9 @@ describe('When the tabular page is loaded', () => {
expect(rows[1]).not.toHaveTextContent(techPreview);
expect(rows[2]).not.toHaveTextContent(techPreview);
expect(rows[3]).toHaveTextContent(techPreview);
expect(rows[4]).not.toHaveTextContent(techPreview);
expect(rows[4]).toHaveTextContent(techPreview);
expect(rows[5]).not.toHaveTextContent(techPreview);
expect(rows[6]).not.toHaveTextContent(techPreview);
expect(rows[7]).not.toHaveTextContent(techPreview);
});
});

View file

@ -26,6 +26,20 @@ describe('Reranker Tech preview badge', () => {
expect(isProviderTechPreview(mockProvider)).toEqual(true);
});
it('return true for rainbow-sprinkles', () => {
const elasticProviderServiceSettings = {
...mockProvider.service_settings,
model_id: 'rainbow-sprinkles',
};
const elasticProvider = {
...mockProvider,
task_type: 'chat_completion',
service: 'elastic',
service_settings: elasticProviderServiceSettings,
} as any;
expect(isProviderTechPreview(elasticProvider)).toEqual(true);
});
it('return false for other provider', () => {
const otherProviderServiceSettings = {
...mockProvider.service_settings,

View file

@ -7,15 +7,21 @@
import { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
export const isProviderTechPreview = (provider: InferenceAPIConfigResponse) => {
if (hasModelId(provider)) {
return provider.task_type === 'rerank' && provider.service_settings?.model_id?.startsWith('.');
const { service_settings: serviceSettings, task_type: taskType } = provider;
const modelId = serviceSettings?.model_id;
// If there's no model ID in service settings, it's not a tech preview
if (!modelId) {
return false;
}
/*
For rerank task type, model ID starting with '.' indicates tech preview
Special case for 'rainbow-sprinkles' model
*/
if ((taskType === 'rerank' && modelId.startsWith('.')) || modelId === 'rainbow-sprinkles') {
return true;
}
return false;
};
function hasModelId(
service: InferenceAPIConfigResponse
): service is Extract<InferenceAPIConfigResponse, { service_settings: { model_id: string } }> {
return 'model_id' in service.service_settings;
}