Skip to content

Commit d78fbc7

Browse files
[Automatic Import] Use InferenceChatModel (#233365)
## Summary Use `InferenceChatModel` as default ChatModel. ## Testing - Run Automatic Import flow with Bedrock , OpenAI , Gemini Connectors and verify the flow goes through. - Verify in Langsmith Traces that InferenceChatModel is used. <img width="353" height="184" alt="image" src="https://github.com/user-attachments/assets/181c7bf2-4125-4d4d-9f8c-6d53252f9706" /> <img width="379" height="147" alt="image" src="https://github.com/user-attachments/assets/35c6137c-e64f-498c-bbbc-67b8cd07c684" /> <img width="361" height="187" alt="image" src="https://github.com/user-attachments/assets/e380837a-bc54-41dc-8290-013fa00a0fae" /> <img width="386" height="197" alt="image" src="https://github.com/user-attachments/assets/cf7b3301-b706-44a7-a0b8-eaca26b2ef06" /> <img width="274" height="186" alt="image" src="https://github.com/user-attachments/assets/9c543dad-5ae5-4b63-836c-9e03f3badc7d" /> <img width="333" height="140" alt="image" src="https://github.com/user-attachments/assets/b4ce3d09-7b5b-4e43-b0c8-562393e528a2" /> --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 20d0fb2 commit d78fbc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+443
-546
lines changed

x-pack/platform/plugins/shared/automatic_import/kibana.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"triggersActionsUi",
2020
"actions",
2121
"stackConnectors",
22+
"inference",
2223
],
2324
"requiredBundles": [
2425
"kibanaUtils"

x-pack/platform/plugins/shared/automatic_import/scripts/draw_graphs_script.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
*/
77

88
import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
9-
import type {
10-
ActionsClientChatOpenAI,
11-
ActionsClientSimpleChatModel,
12-
} from '@kbn/langchain/server/language_models';
139
import { ToolingLog } from '@kbn/tooling-log';
1410
import type { Graph as RunnableGraph } from '@langchain/core/runnables/graph';
1511
import { FakeLLM } from '@langchain/core/utils/testing';
1612
import fs from 'fs/promises';
1713
import path from 'path';
14+
import type { InferenceChatModel } from '@kbn/inference-langchain';
1815
import { getCategorizationGraph } from '../server/graphs/categorization/graph';
1916
import { getEcsGraph, getEcsSubGraph } from '../server/graphs/ecs/graph';
2017
import { getLogFormatDetectionGraph } from '../server/graphs/log_type_detection/graph';
@@ -27,7 +24,7 @@ import { getApiAnalysisGraph } from '../server/graphs/api_analysis';
2724
// Some mock elements just to get the graph to compile
2825
const model = new FakeLLM({
2926
response: JSON.stringify({}, null, 2),
30-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
27+
}) as unknown as InferenceChatModel;
3128
const client = 'test' as unknown as IScopedClusterClient;
3229

3330
const logger = new ToolingLog({

x-pack/platform/plugins/shared/automatic_import/server/__mocks__/request_context.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
* 2.0.
66
*/
77
import { coreMock } from '@kbn/core/server/mocks';
8-
import type { PluginStartContract as ActionsPluginStart } from '@kbn/actions-plugin/server';
98
import { loggerMock } from '@kbn/logging-mocks';
109
import { FakeLLM } from '@langchain/core/utils/testing';
11-
import type {
12-
ActionsClientChatOpenAI,
13-
ActionsClientSimpleChatModel,
14-
} from '@kbn/langchain/server/language_models';
10+
import type { InferenceChatModel } from '@kbn/inference-langchain';
1511

1612
export const createMockClients = () => {
1713
const core = coreMock.createRequestHandlerContext();
@@ -31,32 +27,7 @@ const convertRequestContextMock = <T extends Record<string, unknown>>(context: T
3127

3228
const mockLlm = new FakeLLM({
3329
response: JSON.stringify({}, null, 2),
34-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
35-
36-
jest.mock('@kbn/langchain/server/language_models', () => {
37-
return {
38-
ActionsClientSimpleChatModel: jest.fn().mockImplementation(() => {
39-
return mockLlm;
40-
}),
41-
ActionsClientChatOpenAI: jest.fn().mockImplementation(() => {
42-
return mockLlm;
43-
}),
44-
};
45-
});
46-
47-
const actions = {
48-
getActionsClientWithRequest: jest.fn().mockResolvedValue({
49-
get: jest.fn().mockResolvedValue({
50-
mockLlm,
51-
}),
52-
execute: jest.fn().mockResolvedValue({
53-
status: 'ok',
54-
data: {
55-
message: '{"Answer": "testAction"}',
56-
},
57-
}),
58-
}),
59-
} as unknown as ActionsPluginStart;
30+
}) as unknown as InferenceChatModel;
6031

6132
const coreSetupMock = coreMock.createSetup();
6233
const createRequestContextMock = (clients: MockClients = createMockClients()) => {
@@ -67,7 +38,11 @@ const createRequestContextMock = (clients: MockClients = createMockClients()) =>
6738
return [
6839
{},
6940
{
70-
actions,
41+
inference: {
42+
getChatModel: jest.fn().mockResolvedValue({
43+
mockLlm,
44+
}),
45+
},
7146
},
7247
];
7348
}

x-pack/platform/plugins/shared/automatic_import/server/graphs/api_analysis/graph.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import {
1010
apiAnalysisPathSuggestionsMockedResponse,
1111
apiAnalysisExpectedResults,
1212
} from '../../../__jest__/fixtures/api_analysis';
13-
import type {
14-
ActionsClientChatOpenAI,
15-
ActionsClientSimpleChatModel,
16-
} from '@kbn/langchain/server/language_models';
1713
import { mockedApiAnalysisRequest } from '../../../__jest__/fixtures';
1814
import { handleGetSuggestedPaths } from './paths';
15+
import type { InferenceChatModel } from '@kbn/inference-langchain';
1916

2017
const model = new FakeLLM({
2118
response: "I'll callback later.",
22-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
19+
}) as unknown as InferenceChatModel;
2320

2421
jest.mock('./paths');
2522

x-pack/platform/plugins/shared/automatic_import/server/graphs/api_analysis/paths.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import type {
8-
ActionsClientChatOpenAI,
9-
ActionsClientSimpleChatModel,
10-
} from '@kbn/langchain/server/language_models';
117
import { FakeLLM } from '@langchain/core/utils/testing';
128
import { apiAnalysisTestState } from '../../../__jest__/fixtures/api_analysis';
139
import type { ApiAnalysisState } from '../../types';
1410
import { handleGetSuggestedPaths } from './paths';
11+
import type { InferenceChatModel } from '@kbn/inference-langchain';
1512

1613
const model = new FakeLLM({
1714
response: '[ "/path1", "/path2" ]',
18-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
15+
}) as unknown as InferenceChatModel;
1916

2017
const state: ApiAnalysisState = apiAnalysisTestState;
2118

x-pack/platform/plugins/shared/automatic_import/server/graphs/categorization/categorization.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ import {
1313
categorizationMockProcessors,
1414
categorizationExpectedHandlerResponse,
1515
} from '../../../__jest__/fixtures/categorization';
16-
import type {
17-
ActionsClientChatOpenAI,
18-
ActionsClientSimpleChatModel,
19-
} from '@kbn/langchain/server/language_models';
16+
import type { InferenceChatModel } from '@kbn/inference-langchain';
2017

2118
const model = new FakeLLM({
2219
response: JSON.stringify(categorizationMockProcessors, null, 2),
23-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
20+
}) as unknown as InferenceChatModel;
2421

2522
const state: CategorizationState = categorizationTestState;
2623

x-pack/platform/plugins/shared/automatic_import/server/graphs/categorization/errors.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ import {
1313
categorizationMockProcessors,
1414
categorizationExpectedHandlerResponse,
1515
} from '../../../__jest__/fixtures/categorization';
16-
import type {
17-
ActionsClientChatOpenAI,
18-
ActionsClientSimpleChatModel,
19-
} from '@kbn/langchain/server/language_models';
16+
import type { InferenceChatModel } from '@kbn/inference-langchain';
2017

2118
const model = new FakeLLM({
2219
response: JSON.stringify(categorizationMockProcessors, null, 2),
23-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
20+
}) as unknown as InferenceChatModel;
2421

2522
const state: CategorizationState = categorizationTestState;
2623

x-pack/platform/plugins/shared/automatic_import/server/graphs/categorization/graph.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ import { handleErrors } from './errors';
2727
import { handleInvalidCategorization } from './invalid';
2828
import { handleUpdateStableSamples } from './stable';
2929
import { testPipeline, combineProcessors } from '../../util';
30-
import type {
31-
ActionsClientChatOpenAI,
32-
ActionsClientSimpleChatModel,
33-
} from '@kbn/langchain/server/language_models';
3430
import { handleValidatePipeline } from '../../util/graph';
31+
import type { InferenceChatModel } from '@kbn/inference-langchain';
3532

3633
const model = new FakeLLM({
3734
response: "I'll callback later.",
38-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
35+
}) as unknown as InferenceChatModel;
3936

4037
jest.mock('./errors');
4138
jest.mock('./review');

x-pack/platform/plugins/shared/automatic_import/server/graphs/categorization/invalid.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ import {
1313
categorizationMockProcessors,
1414
categorizationExpectedHandlerResponse,
1515
} from '../../../__jest__/fixtures/categorization';
16-
import type {
17-
ActionsClientChatOpenAI,
18-
ActionsClientSimpleChatModel,
19-
} from '@kbn/langchain/server/language_models';
16+
import type { InferenceChatModel } from '@kbn/inference-langchain';
2017

2118
const model = new FakeLLM({
2219
response: JSON.stringify(categorizationMockProcessors, null, 2),
23-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
20+
}) as unknown as InferenceChatModel;
2421

2522
const state: CategorizationState = categorizationTestState;
2623

x-pack/platform/plugins/shared/automatic_import/server/graphs/categorization/review.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ import {
1313
categorizationMockProcessors,
1414
categorizationExpectedHandlerResponse,
1515
} from '../../../__jest__/fixtures/categorization';
16-
import type {
17-
ActionsClientChatOpenAI,
18-
ActionsClientSimpleChatModel,
19-
} from '@kbn/langchain/server/language_models';
16+
import type { InferenceChatModel } from '@kbn/inference-langchain';
2017

2118
const model = new FakeLLM({
2219
response: JSON.stringify(categorizationMockProcessors, null, 2),
23-
}) as unknown as ActionsClientChatOpenAI | ActionsClientSimpleChatModel;
20+
}) as unknown as InferenceChatModel;
2421

2522
const state: CategorizationState = categorizationTestState;
2623

0 commit comments

Comments
 (0)