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

BedrockChat & GeminiChat #186809

Merged
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
65fdf44
BedrockChat
patrykkopycinski Jun 24, 2024
538b846
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 24, 2024
34ff58b
test
patrykkopycinski Jun 25, 2024
a3aac87
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
patrykkopycinski Jun 25, 2024
7cc74e7
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jun 25, 2024
19155f0
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jun 29, 2024
b87106f
cleanup
patrykkopycinski Jun 29, 2024
e1434ba
add FF
patrykkopycinski Jun 29, 2024
cf3d547
cleanup
patrykkopycinski Jun 29, 2024
281f98e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 29, 2024
10f5de9
fix
patrykkopycinski Jun 29, 2024
2b5332b
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
patrykkopycinski Jun 29, 2024
4cd8f7f
fix
patrykkopycinski Jun 29, 2024
1bd50b5
[CI] Auto-commit changed files from 'yarn openapi:generate'
kibanamachine Jun 30, 2024
7696942
fix
patrykkopycinski Jun 30, 2024
340097b
fix
patrykkopycinski Jun 30, 2024
2978871
cleanup
patrykkopycinski Jun 30, 2024
c414a3a
cleanup
patrykkopycinski Jun 30, 2024
931745d
basic tests
patrykkopycinski Jun 30, 2024
467cd96
cleanup package.json
patrykkopycinski Jun 30, 2024
cb8e2a4
test
patrykkopycinski Jun 30, 2024
bd64e0b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 30, 2024
6bb645f
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jul 2, 2024
a00d6b6
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
patrykkopycinski Jul 2, 2024
abbae71
bump
patrykkopycinski Jul 7, 2024
43010fb
Merge branch 'main' into feat/langchain-bedrock-chat
patrykkopycinski Jul 8, 2024
fa9c674
merge
patrykkopycinski Jul 10, 2024
e6e33d9
fix tool calling for non-graph
patrykkopycinski Jul 10, 2024
1ff60bf
graph-workflow
patrykkopycinski Jul 10, 2024
3049b78
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jul 12, 2024
cdb4283
test bedrock streaming
patrykkopycinski Jul 15, 2024
109374d
fix
patrykkopycinski Jul 15, 2024
44a8b46
Merge branch 'main' into feat/langchain-bedrock-chat
patrykkopycinski Jul 15, 2024
90943b0
test VertexChat
patrykkopycinski Jul 16, 2024
98944d8
Merge branch 'main' into feat/langchain-bedrock-chat
stephmilovic Jul 16, 2024
ab87b84
fix bedrock streaming
patrykkopycinski Jul 16, 2024
19bbc9c
fix bedrock graph streaming
patrykkopycinski Jul 16, 2024
f18e641
fix
patrykkopycinski Jul 16, 2024
b6ecc5a
switch to ActionsClientGeminiChatModel
patrykkopycinski Jul 17, 2024
a35c1b4
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jul 17, 2024
37297e3
cleanup
patrykkopycinski Jul 17, 2024
5fbced6
fix? gemini streaming
patrykkopycinski Jul 17, 2024
47fa2c7
only one final answer
stephmilovic Jul 18, 2024
1d7628c
Merge branch 'main' into feat/langchain-bedrock-chat
stephmilovic Jul 18, 2024
72658d8
WIP
patrykkopycinski Jul 18, 2024
527e5c0
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
patrykkopycinski Jul 18, 2024
f38f83c
fix double response from Gemini
stephmilovic Jul 18, 2024
5b4f377
revert log
stephmilovic Jul 18, 2024
475d7b6
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
patrykkopycinski Jul 22, 2024
06d5b79
Merge branch 'main' of github.com:elastic/kibana into feat/langchain-…
patrykkopycinski Jul 22, 2024
11e4cb6
fix deduplicates
patrykkopycinski Jul 22, 2024
c0bae8b
fixing lint and types
stephmilovic Jul 22, 2024
6d3203f
update jest
patrykkopycinski Jul 22, 2024
5479131
flip feature flagas
patrykkopycinski Jul 22, 2024
8a865f8
better err handling
stephmilovic Jul 22, 2024
da2d127
rm logs
stephmilovic Jul 22, 2024
6d18dad
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
stephmilovic Jul 22, 2024
311d922
fix prompt, readd gemini token code
stephmilovic Jul 22, 2024
8255c11
add safety settings arg
stephmilovic Jul 22, 2024
440a9c4
fix types
patrykkopycinski Jul 22, 2024
c0725df
fix stack connector types
stephmilovic Jul 22, 2024
f668eb1
Merge branch 'main' into feat/langchain-bedrock-chat
stephmilovic Jul 22, 2024
442891c
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
stephmilovic Jul 22, 2024
debf375
cleanup bedrockchat
stephmilovic Jul 22, 2024
4db15dc
clean up comments
stephmilovic Jul 22, 2024
50d73f1
fix weird type thing
stephmilovic Jul 22, 2024
91a3dfa
fix gemini subaction args
stephmilovic Jul 22, 2024
8fe746c
fix safety settings
stephmilovic Jul 22, 2024
c5cc32e
Revert "fix weird type thing"
stephmilovic Jul 22, 2024
3923074
add comment
stephmilovic Jul 22, 2024
1133f28
fix jest 1
stephmilovic Jul 22, 2024
6e30606
fix jest 2
stephmilovic Jul 22, 2024
0974e88
Merge branch 'main' into feat/langchain-bedrock-chat
spong Jul 22, 2024
6f50245
fix for error
stephmilovic Jul 23, 2024
11c7357
Merge branch 'feat/langchain-bedrock-chat' of github.com:patrykkopyci…
stephmilovic Jul 23, 2024
ffe2a37
update jest
patrykkopycinski Jul 23, 2024
a0b92df
Merge branch 'main' into feat/langchain-bedrock-chat
elasticmachine Jul 23, 2024
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
27 changes: 17 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@
"resolutions": {
"**/@bazel/typescript/protobufjs": "6.11.4",
"**/@hello-pangea/dnd": "16.6.0",
"**/@langchain/core": "0.2.3",
"**/@langchain/core": "^0.2.17",
"**/@types/node": "20.10.5",
"**/@typescript-eslint/utils": "5.62.0",
"**/chokidar": "^3.5.3",
"**/d3-scale/**/d3-color": "npm:@elastic/[email protected]",
"**/globule/minimatch": "^3.1.2",
"**/hoist-non-react-statics": "^3.3.2",
"**/isomorphic-fetch/node-fetch": "^2.6.7",
"**/langchain": "^0.2.10",
"**/react-intl/**/@types/react": "^17.0.45",
"**/remark-parse/trim": "1.0.1",
"**/sharp": "0.32.6",
Expand All @@ -96,6 +97,8 @@
},
"dependencies": {
"@appland/sql-parser": "^1.5.1",
"@aws-crypto/sha256-js": "^5.2.0",
"@aws-crypto/util": "^5.2.0",
"@babel/runtime": "^7.24.7",
"@cfworker/json-schema": "^1.12.7",
"@dnd-kit/core": "^6.1.0",
Expand Down Expand Up @@ -132,6 +135,7 @@
"@formatjs/intl-relativetimeformat": "^11.2.12",
"@formatjs/intl-utils": "^3.8.4",
"@formatjs/ts-transformer": "^3.13.14",
"@google/generative-ai": "^0.7.0",
"@grpc/grpc-js": "^1.8.22",
"@hapi/accept": "^5.0.2",
"@hapi/boom": "^9.1.4",
Expand Down Expand Up @@ -939,10 +943,11 @@
"@kbn/xstate-utils": "link:packages/kbn-xstate-utils",
"@kbn/zod": "link:packages/kbn-zod",
"@kbn/zod-helpers": "link:packages/kbn-zod-helpers",
"@langchain/community": "^0.2.4",
"@langchain/core": "0.2.3",
"@langchain/langgraph": "^0.0.23",
"@langchain/openai": "^0.0.34",
"@langchain/community": "0.2.18",
"@langchain/core": "^0.2.17",
"@langchain/google-genai": "^0.0.23",
"@langchain/langgraph": "^0.0.29",
"@langchain/openai": "^0.1.3",
"@langtrase/trace-attributes": "^3.0.8",
"@launchdarkly/node-server-sdk": "^9.4.7",
"@loaders.gl/core": "^3.4.7",
Expand All @@ -965,9 +970,11 @@
"@paralleldrive/cuid2": "^2.2.2",
"@reduxjs/toolkit": "1.9.7",
"@slack/webhook": "^7.0.1",
"@smithy/eventstream-codec": "^3.0.0",
"@smithy/eventstream-serde-node": "^3.0.0",
"@smithy/types": "^3.0.0",
"@smithy/eventstream-codec": "^3.1.1",
"@smithy/eventstream-serde-node": "^3.0.3",
"@smithy/protocol-http": "^4.0.2",
"@smithy/signature-v4": "^3.1.1",
"@smithy/types": "^3.2.0",
"@smithy/util-utf8": "^3.0.0",
"@tanstack/react-query": "^4.29.12",
"@tanstack/react-query-devtools": "^4.29.12",
Expand Down Expand Up @@ -1080,8 +1087,8 @@
"jsonwebtoken": "^9.0.2",
"jsts": "^1.6.2",
"kea": "^2.6.0",
"langchain": "0.2.3",
"langsmith": "^0.1.30",
"langchain": "^0.2.10",
"langsmith": "^0.1.37",
"launchdarkly-js-client-sdk": "^3.4.0",
"launchdarkly-node-server-sdk": "^7.0.3",
"load-json-file": "^6.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export type AssistantFeatureKey = keyof AssistantFeatures;
export const defaultAssistantFeatures = Object.freeze({
assistantKnowledgeBaseByDefault: false,
assistantModelEvaluation: false,
assistantBedrockChat: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { z } from 'zod';

export type GetCapabilitiesResponse = z.infer<typeof GetCapabilitiesResponse>;
export const GetCapabilitiesResponse = z.object({
assistantBedrockChat: z.boolean(),
assistantKnowledgeBaseByDefault: z.boolean(),
assistantModelEvaluation: z.boolean(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ paths:
schema:
type: object
properties:
assistantBedrockChat:
type: boolean
assistantKnowledgeBaseByDefault:
type: boolean
assistantModelEvaluation:
type: boolean
required:
- assistantBedrockChat
- assistantKnowledgeBaseByDefault
- assistantModelEvaluation
'400':
Expand Down
4 changes: 4 additions & 0 deletions x-pack/packages/kbn-langchain/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

import { ActionsClientBedrockChatModel } from './language_models/bedrock_chat';
import { ActionsClientChatOpenAI } from './language_models/chat_openai';
import { ActionsClientLlm } from './language_models/llm';
import { ActionsClientSimpleChatModel } from './language_models/simple_chat_model';
import { ActionsClientGeminiChatModel } from './language_models/gemini_chat';
import { parseBedrockStream } from './utils/bedrock';
import { parseGeminiResponse } from './utils/gemini';
import { getDefaultArguments } from './language_models/constants';
Expand All @@ -16,7 +18,9 @@ export {
parseBedrockStream,
parseGeminiResponse,
getDefaultArguments,
ActionsClientBedrockChatModel,
ActionsClientChatOpenAI,
ActionsClientGeminiChatModel,
ActionsClientLlm,
ActionsClientSimpleChatModel,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 { BedrockChat as _BedrockChat } from '@langchain/community/chat_models/bedrock/web';
import type { ActionsClient } from '@kbn/actions-plugin/server';
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models';
import { Logger } from '@kbn/logging';
import { Readable } from 'stream';
import { PublicMethodsOf } from '@kbn/utility-types';

export const DEFAULT_BEDROCK_MODEL = 'anthropic.claude-3-5-sonnet-20240620-v1:0';
export const DEFAULT_BEDROCK_REGION = 'us-east-1';

export interface CustomChatModelInput extends BaseChatModelParams {
actionsClient: PublicMethodsOf<ActionsClient>;
connectorId: string;
logger: Logger;
temperature?: number;
signal?: AbortSignal;
model?: string;
maxTokens?: number;
}

export class ActionsClientBedrockChatModel extends _BedrockChat {
constructor({ actionsClient, connectorId, logger, ...params }: CustomChatModelInput) {
super({
...params,
credentials: { accessKeyId: '', secretAccessKey: '' },
// only needed to force BedrockChat to use messages api for Claude v2
model: params.model ?? DEFAULT_BEDROCK_MODEL,
region: DEFAULT_BEDROCK_REGION,
fetchFn: async (url, options) => {
const inputBody = JSON.parse(options?.body as string);

if (this.streaming && !inputBody.tools?.length) {
const data = (await actionsClient.execute({
actionId: connectorId,
params: {
subAction: 'invokeStream',
subActionParams: {
messages: inputBody.messages,
temperature: params.temperature ?? inputBody.temperature,
stopSequences: inputBody.stop_sequences,
system: inputBody.system,
maxTokens: params.maxTokens ?? inputBody.max_tokens,
tools: inputBody.tools,
anthropicVersion: inputBody.anthropic_version,
},
},
})) as { data: Readable };

return {
body: Readable.toWeb(data.data),
} as unknown as Response;
}

const data = (await actionsClient.execute({
actionId: connectorId,
params: {
subAction: 'invokeAIRaw',
subActionParams: {
messages: inputBody.messages,
temperature: params.temperature ?? inputBody.temperature,
stopSequences: inputBody.stop_sequences,
system: inputBody.system,
maxTokens: params.maxTokens ?? inputBody.max_tokens,
tools: inputBody.tools,
anthropicVersion: inputBody.anthropic_version,
},
},
})) as { status: string; data: { message: string } };

return {
ok: data.status === 'ok',
json: () => data.data,
} as unknown as Response;
},
});
}
}
Loading