Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0] [Inference] Replace transport request calls with `inference.get` (#210396) #210445

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
import { addBasePath } from '..';
import { RouteDependencies } from '../../../types';

Expand All @@ -25,13 +24,9 @@ export function registerGetAllRoute({ router, lib: { handleEsError } }: RouteDep
async (context, request, response) => {
const { client } = (await context.core).elasticsearch;

// TODO: Use the client's built-in function rather than the transport when it's available
try {
const { endpoints } = await client.asCurrentUser.transport.request<{
endpoints: InferenceAPIConfigResponse[];
}>({
method: 'GET',
path: `/_inference/_all`,
const { endpoints } = await client.asCurrentUser.inference.get({
inference_id: '_all',
});

return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
InferenceInferenceEndpoint,
InferenceTaskType,
} from '@elastic/elasticsearch/lib/api/types';
import type { InferenceAPIConfigResponse } from '@kbn/ml-trained-models-utils';
import type { RouteInitialization } from '../types';
import { createInferenceSchema } from './schemas/inference_schema';
import { modelsProvider } from '../models/model_management';
Expand Down Expand Up @@ -85,15 +84,12 @@ export function inferenceModelRoutes(
.addVersion(
{
version: '1',
validate: {},
validate: false,
},
routeGuard.fullLicenseAPIGuard(async ({ client, response }) => {
try {
const body = await client.asCurrentUser.transport.request<{
models: InferenceAPIConfigResponse[];
}>({
method: 'GET',
path: `/_inference/_all`,
const body = await client.asCurrentUser.inference.get({
inference_id: '_all',
});
return response.ok({
body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ describe('fetch indices', () => {

const mockClient = {
asCurrentUser: {
transport: {
request: jest.fn(),
inference: {
get: jest.fn(),
},
},
};

it('returns all inference endpoints', async () => {
mockClient.asCurrentUser.transport.request.mockImplementationOnce(() => {
mockClient.asCurrentUser.inference.get.mockImplementationOnce(() => {
return Promise.resolve({ endpoints: mockInferenceEndpointsResponse });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ export const fetchInferenceEndpoints = async (
): Promise<{
inferenceEndpoints: InferenceAPIConfigResponse[];
}> => {
const { endpoints } = await client.transport.request<{
endpoints: any;
}>({
method: 'GET',
path: `/_inference/_all`,
const { endpoints } = await client.inference.get({
inference_id: '_all',
});

return {
inferenceEndpoints: endpoints,
inferenceEndpoints: endpoints as InferenceAPIConfigResponse[],
};
};