Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Nov 6, 2024
1 parent 80a6c0b commit 2935ff5
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { INTERNAL_BASE_STACK_CONNECTORS_API_PATH } from '../../../../common';
import { InferenceProvider } from '../../../../common/inference/types';

export const getProviders = async (http: HttpSetup): Promise<InferenceProvider[]> => {
return await http.get(`${INTERNAL_BASE_STACK_CONNECTORS_API_PATH}/_email_config`);
return await http.get(`${INTERNAL_BASE_STACK_CONNECTORS_API_PATH}/_inference/_services`);
};

export const useProviders = (http: HttpSetup, toasts: ToastsStart) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,122 @@

import { httpServiceMock, httpServerMock } from '@kbn/core/server/mocks';
import { getInferenceServicesRoute } from './get_inference_services';
import { DisplayType, FieldType } from '../../common/dynamic_config/types';

describe('getInferenceServicesRoute', () => {
it('returns config for well known email service', async () => {
it('returns available service providers', async () => {
const router = httpServiceMock.createRouter();

getInferenceServicesRoute(router);

const [config, handler] = router.get.mock.calls[0];
expect(config.path).toMatchInlineSnapshot(
`"/internal/stack_connectors/_email_config/{service}"`
);
expect(config.path).toMatchInlineSnapshot('/internal/stack_connectors/_inference/_services');

const mockResponse = httpServerMock.createResponseFactory();
const mockRequest = httpServerMock.createKibanaRequest({
params: { service: 'gmail' },
});
await handler({}, mockRequest, mockResponse);

expect(mockResponse.ok).toHaveBeenCalledWith({
body: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
},
});
});

it('returns config for elastic cloud email service', async () => {
const router = httpServiceMock.createRouter();

getInferenceServicesRoute(router);

const [config, handler] = router.get.mock.calls[0];
expect(config.path).toMatchInlineSnapshot(
`"/internal/stack_connectors/_email_config/{service}"`
);

const mockResponse = httpServerMock.createResponseFactory();
const mockRequest = httpServerMock.createKibanaRequest({
params: { service: 'elastic_cloud' },
});

await handler({}, mockRequest, mockResponse);

expect(mockResponse.ok).toHaveBeenCalledWith({
body: {
host: 'dockerhost',
port: 10025,
secure: false,
},
});
});

it('returns empty for unknown service', async () => {
const router = httpServiceMock.createRouter();

getInferenceServicesRoute(router);

const [config, handler] = router.get.mock.calls[0];
expect(config.path).toMatchInlineSnapshot(
`"/internal/stack_connectors/_email_config/{service}"`
);

const mockResponse = httpServerMock.createResponseFactory();
const mockRequest = httpServerMock.createKibanaRequest({
params: { service: 'foo' },
});
const mockRequest = httpServerMock.createKibanaRequest();
await handler({}, mockRequest, mockResponse);

expect(mockResponse.ok).toHaveBeenCalledWith({
body: {},
body: [
{
provider: 'openai',
task_types: [
{
task_type: 'completion',
configuration: {
user: {
display: DisplayType.TEXTBOX,
label: 'User',
order: 1,
required: false,
sensitive: false,
tooltip: 'Specifies the user issuing the request.',
type: FieldType.STRING,
validations: [],
value: '',
ui_restrictions: [],
default_value: null,
depends_on: [],
},
},
},
],
configuration: {
api_key: {
display: DisplayType.TEXTBOX,
label: 'API Key',
order: 3,
required: true,
sensitive: true,
tooltip: `The OpenAI API authentication key. For more details about generating OpenAI API keys, refer to the https://platform.openai.com/account/api-keys.`,
type: FieldType.STRING,
validations: [],
value: null,
ui_restrictions: [],
default_value: null,
depends_on: [],
},
model_id: {
display: DisplayType.TEXTBOX,
label: 'Model ID',
order: 2,
required: true,
sensitive: false,
tooltip: 'The name of the model to use for the inference task.',
type: FieldType.STRING,
validations: [],
value: null,
ui_restrictions: [],
default_value: null,
depends_on: [],
},
organization_id: {
display: DisplayType.TEXTBOX,
label: 'Organization ID',
order: 4,
required: false,
sensitive: false,
tooltip: 'The unique identifier of your organization.',
type: FieldType.STRING,
validations: [],
value: null,
ui_restrictions: [],
default_value: null,
depends_on: [],
},
url: {
display: DisplayType.TEXTBOX,
label: 'URL',
order: 1,
required: true,
sensitive: false,
tooltip:
'The OpenAI API endpoint URL. For more information on the URL, refer to the https://platform.openai.com/docs/api-reference.',
type: FieldType.STRING,
validations: [],
value: null,
ui_restrictions: [],
default_value: 'https://api.openai.com/v1/chat/completions',
depends_on: [],
},
'rate_limit.requests_per_minute': {
display: DisplayType.NUMERIC,
label: 'Rate limit',
order: 5,
required: false,
sensitive: false,
tooltip:
'Default number of requests allowed per minute. For text_embedding is 3000. For completion is 500.',
type: FieldType.INTEGER,
validations: [],
value: null,
ui_restrictions: [],
default_value: null,
depends_on: [],
},
},
},
],
});
});
});

0 comments on commit 2935ff5

Please sign in to comment.