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

Introduce the InferenceChatModel for langchain #206429

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jan 13, 2025

Summary

Part of #206710

This PR introduces the InferenceChatModel class, which is a langchain chatModel utilizing the inference APIs (chatComplete) under the hood.

Creating instances of InferenceChatModel can either be done by manually importing the class from the new @kbn/inference-langchain package, or by using the new createChatModel API exposes from the inference plugin's start contract.

The main upside of using this chatModel is that the unification and normalization layers are already being taken care of by the inference plugin, making sure that the underlying models are being used with the exact same capabilities. More details on the upsides and reasoning in the associated issue.

Usage

Usage is very straightforward

const chatModel = await inferenceStart.getChatModel({
  request,
  connectorId: myInferenceConnectorId,
  chatModelOptions: {
    temperature: 0.2,
  },
});

// just use it as another langchain chatModel, e.g.
const response = await chatModel.stream('What is Kibana?');
for await (const chunk of response) {
     // do something with the chunk
}

Important

This PR is only adding the implementation, and not wiring it anywhere or using it in any existing code. This is meant to be done in a later stage. Merging that implementation first will allow to have distinct PRs for the integration with search (playground) and security (assistant + other workflows), with proper testing

@pgayvallet pgayvallet added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 backport:version Backport to applied version labels v8.18.0 labels Jan 13, 2025
@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

2 similar comments
@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet pgayvallet force-pushed the kbn-xxx-inference-langchain branch from 04575f1 to f2a2df5 Compare January 15, 2025 07:15
@pgayvallet
Copy link
Contributor Author

/ci

1 similar comment
@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet pgayvallet added the Team:AI Infra AppEx AI Infrastructure Team label Jan 29, 2025
@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
inference 28 34 +6
observabilityAIAssistantApp 508 514 +6
observabilityAiAssistantManagement 385 391 +6
searchAssistant 265 271 +6
searchPlayground 285 291 +6
total +30

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/inference-common 54 59 +5
@kbn/inference-langchain - 47 +47
inference 28 29 +1
total +53

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
inference 5 6 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
inference 7.5KB 7.6KB +85.0B
Unknown metric groups

API count

id before after diff
@kbn/inference-common 166 174 +8
@kbn/inference-langchain - 48 +48
inference 40 42 +2
total +58

ESLint disabled line counts

id before after diff
@kbn/router-to-openapispec 3 2 -1

Total ESLint disabled count

id before after diff
@kbn/router-to-openapispec 3 2 -1

History

@pgayvallet pgayvallet marked this pull request as ready for review January 30, 2025 08:58
@pgayvallet pgayvallet requested review from a team as code owners January 30, 2025 08:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-ai-infra (Team:AI Infra)

Copy link
Contributor

@gsoldevila gsoldevila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core changes LGTM (review only): Removing an eslint exception is usually good news!

Copy link
Member

@KDKHD KDKHD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from GenAi side. Just one comment but it is a nit pick.

Comment on lines +11 to +13
// https://github.com/elastic/kibana/blob/49df29609e10429809f3710d6b8b1d5efbc833a7/x-pack/platform/plugins/shared/actions/server/sub_action_framework/sub_action_connector.ts#L200-L202
// Status code: 400. Message: API Error: model_error - The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry.
// status_exception - Received an authentication error status code for request from inference entity id [openai-chat_completion-uuid] status [401]. Error message: [Incorrect API key provided]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these extra comments? Or can you clarify why the same text is repeated below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch thanks, yeah those were copy pasted to create the consts in the test file, will remove the comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:AI Infra AppEx AI Infrastructure Team v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants