Skip to content

Commit

Permalink
Merge branch '8.18' into backport/8.18/pr-209973
Browse files Browse the repository at this point in the history
  • Loading branch information
jcger authored Feb 12, 2025
2 parents c2ff2ff + c2d3c70 commit 52eab9e
Show file tree
Hide file tree
Showing 52 changed files with 1,530 additions and 345 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@
"rxjs": "^7.8.1",
"safe-squel": "^5.12.5",
"seedrandom": "^3.0.5",
"semver": "^7.7.0",
"semver": "^7.7.1",
"set-value": "^4.1.0",
"snakecase-keys": "^8.0.0",
"source-map-support": "^0.5.19",
Expand Down
20 changes: 0 additions & 20 deletions packages/kbn-babel-preset/styled_components_files.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { ConfigurationFormItems } from './configuration_form_items';
import { render, screen } from '@testing-library/react';
import { FieldType } from '../../types/dynamic_config/types';

describe('ConfigurationFormItems', () => {
const mockItems = [
{
key: 'model_id',
isValid: true,
label: 'Model ID',
description: 'Enter model ID',
validationErrors: [],
required: true,
sensitive: false,
value: '',
default_value: '',
updatable: false,
type: FieldType.STRING,
supported_task_types: ['text_embedding'],
},
];

const defaultProps = {
isLoading: false,
items: mockItems,
setConfigEntry: jest.fn(),
};

it('renders link when isInternalProvider is true and key is model_id', () => {
render(<ConfigurationFormItems {...defaultProps} isInternalProvider={true} />);

const link = screen.getByRole('link', { name: /looking for elasticsearch model ids/i });
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute(
'href',
'https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html#default-enpoints'
);

expect(screen.getByTestId('model_id-input')).toBeInTheDocument();
});

it('does not renders link when isInternalProvider is true and key is model_id', () => {
const numAllocations = [
{
key: 'num_allocations',
isValid: true,
label: 'Number Allocations',
description:
'The total number of allocations this model is assigned across machine learning nodes.',
validationErrors: [],
required: true,
sensitive: false,
value: '',
default_value: 1,
updatable: true,
type: FieldType.INTEGER,
supported_task_types: ['text_embedding'],
},
];

const props = {
isLoading: false,
items: numAllocations,
setConfigEntry: jest.fn(),
};

render(<ConfigurationFormItems {...props} isInternalProvider={true} />);

const link = screen.queryByRole('link', { name: /looking for elasticsearch model ids/i });
expect(link).not.toBeInTheDocument();
});

it('does not renders link when isInternalProvider is false and key is model_id', () => {
render(<ConfigurationFormItems {...defaultProps} isInternalProvider={false} />);

const link = screen.queryByRole('link', { name: /looking for elasticsearch model ids/i });
expect(link).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiFormRow,
EuiLink,
EuiSpacer,
EuiText,
} from '@elastic/eui';
Expand All @@ -27,6 +28,7 @@ interface ConfigurationFormItemsProps {
direction?: 'column' | 'row' | 'rowReverse' | 'columnReverse' | undefined;
isEdit?: boolean;
isPreconfigured?: boolean;
isInternalProvider?: boolean;
}

export const ConfigurationFormItems: React.FC<ConfigurationFormItemsProps> = ({
Expand All @@ -36,6 +38,7 @@ export const ConfigurationFormItems: React.FC<ConfigurationFormItemsProps> = ({
direction,
isEdit,
isPreconfigured,
isInternalProvider,
}) => {
return (
<EuiFlexGroup direction={direction} data-test-subj="configuration-fields">
Expand All @@ -54,6 +57,22 @@ export const ConfigurationFormItems: React.FC<ConfigurationFormItemsProps> = ({
<p>{label}</p>
);

const helpText =
isInternalProvider && key === 'model_id' && !isPreconfigured ? (
<>
{description}{' '}
<EuiLink
href="https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html#default-enpoints"
external
target="_blank"
>
{LABELS.ES_MODELS_LINK_TEXT}
</EuiLink>
</>
) : (
description
);

const optionalLabel = !required ? (
<EuiText color="subdued" size="xs">
{LABELS.OPTIONALTEXT}
Expand All @@ -65,7 +84,7 @@ export const ConfigurationFormItems: React.FC<ConfigurationFormItemsProps> = ({
<EuiFormRow
label={rowLabel}
fullWidth
helpText={description}
helpText={helpText}
error={validationErrors}
isInvalid={!isValid}
labelAppend={optionalLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ export const InferenceServiceFormFields: React.FC<InferenceServicesProps> = ({
setRequiredProviderFormFields(existingConfiguration.filter((p) => p.required || p.sensitive));
}, [config?.providerConfig, providerSchema, secrets, selectedTaskType]);

const isInternalProvider = config?.provider === 'elasticsearch'; // To display link for model_ids for Elasticsearch provider

return !isLoading ? (
<>
<UseField
Expand Down Expand Up @@ -415,6 +417,7 @@ export const InferenceServiceFormFields: React.FC<InferenceServicesProps> = ({
setConfigEntry={onSetProviderConfigEntry}
isEdit={isEdit}
isPreconfigured={isPreconfigured}
isInternalProvider={isInternalProvider}
/>
<EuiSpacer size="m" />
<AdditionalOptionsFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ export const OPTIONALTEXT = i18n.translate(
}
);

export const ES_MODELS_LINK_TEXT = i18n.translate(
'xpack.inferenceEndpointUICommon.components.esModelsLinkText',
{
defaultMessage: 'Looking for Elasticsearch model Ids',
}
);

export const RE_ENTER_SECRETS = (label: string) => {
return i18n.translate('xpack.inferenceEndpointUICommon.components.requiredGenericTextField', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,13 @@ describe('isNativeFunctionCallingSupported', () => {
});
expect(isNativeFunctionCallingSupported(connector)).toBe(false);
});

it('returns true if the config is not exposed', () => {
const connector = createConnector({
type: InferenceConnectorType.OpenAI,
config: {},
});
expect(isNativeFunctionCallingSupported(connector)).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { OpenAiProviderType } from '../adapters/openai/types';
export const isNativeFunctionCallingSupported = (connector: InferenceConnector): boolean => {
switch (connector.type) {
case InferenceConnectorType.OpenAI:
const apiProvider =
(connector.config.apiProvider as OpenAiProviderType) ?? OpenAiProviderType.Other;
return apiProvider !== OpenAiProviderType.Other;
const apiProvider = (connector.config.apiProvider as OpenAiProviderType) ?? undefined;
// defaulting to `true` when the config is not accessible
return apiProvider ? apiProvider !== OpenAiProviderType.Other : true;
case InferenceConnectorType.Inference:
// note: later we might need to check the provider type, for now let's assume support
// will be handled by ES and that all providers will support native FC.
Expand Down
Loading

0 comments on commit 52eab9e

Please sign in to comment.