-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[ML] Add default Elastic Inference Service chat completion endpoint #120847
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
Merged
jonathan-buttner
merged 7 commits into
elastic:main
from
jonathan-buttner:ml-eis-default-endpoint
Jan 28, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c08371d
Starting new auth class implementation
jonathan-buttner 665e700
Fixing some tests
jonathan-buttner 0025f1a
Working tests
jonathan-buttner 9a637f1
Refactoring
jonathan-buttner 748f5de
Merge branch 'main' into ml-eis-default-endpoint
jonathan-buttner 1bc2555
Addressing feedback and pull main
jonathan-buttner 3fdd4b7
Merge branch 'main' of github.com:elastic/elasticsearch into ml-eis-d…
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ts/src/javaRestTest/java/org/elasticsearch/xpack/inference/BaseMockEISAuthServerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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. | ||
| * | ||
| * this file has been contributed to by a Generative AI | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.inference; | ||
|
|
||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
| import org.elasticsearch.test.cluster.FeatureFlag; | ||
| import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.RuleChain; | ||
| import org.junit.rules.TestRule; | ||
|
|
||
| public class BaseMockEISAuthServerTest extends ESRestTestCase { | ||
|
|
||
| // The reason we're retrying is there's a race condition between the node retrieving the | ||
| // authorization response and running the test. Retrieving the authorization should be very fast since | ||
| // we're hosting a local mock server but it's possible it could respond slower. So in the even of a test failure | ||
| // we'll automatically retry after waiting a second. | ||
| @Rule | ||
| public RetryRule retry = new RetryRule(3, TimeValue.timeValueSeconds(1)); | ||
|
|
||
| private static final MockElasticInferenceServiceAuthorizationServer mockEISServer = MockElasticInferenceServiceAuthorizationServer | ||
| .enabledWithRainbowSprinklesAndElser(); | ||
|
|
||
| private static final ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||
| .distribution(DistributionType.DEFAULT) | ||
| .setting("xpack.license.self_generated.type", "trial") | ||
| .setting("xpack.security.enabled", "true") | ||
| // Adding both settings unless one feature flag is disabled in a particular environment | ||
| .setting("xpack.inference.elastic.url", mockEISServer::getUrl) | ||
| // TODO remove this once we've removed DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG and EIS_GATEWAY_URL | ||
| .setting("xpack.inference.eis.gateway.url", mockEISServer::getUrl) | ||
| // This plugin is located in the inference/qa/test-service-plugin package, look for TestInferenceServicePlugin | ||
| .plugin("inference-service-test") | ||
| .user("x_pack_rest_user", "x-pack-test-password") | ||
| .feature(FeatureFlag.INFERENCE_UNIFIED_API_ENABLED) | ||
| .build(); | ||
|
|
||
| // The reason we're doing this is to make sure the mock server is initialized first so we can get the address before communicating | ||
| // it to the cluster as a setting. | ||
| @ClassRule | ||
| public static TestRule ruleChain = RuleChain.outerRule(mockEISServer).around(cluster); | ||
|
|
||
| @Override | ||
| protected String getTestRestCluster() { | ||
| return cluster.getHttpAddresses(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings restClientSettings() { | ||
| String token = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray())); | ||
| return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...va/org/elasticsearch/xpack/inference/InferenceGetModelsWithElasticInferenceServiceIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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. | ||
| * | ||
| * this file has been contributed to by a Generative AI | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.inference; | ||
|
|
||
| import org.elasticsearch.inference.TaskType; | ||
| import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.elasticsearch.xpack.inference.InferenceBaseRestTest.getAllModels; | ||
| import static org.elasticsearch.xpack.inference.InferenceBaseRestTest.getModels; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
|
|
||
| public class InferenceGetModelsWithElasticInferenceServiceIT extends BaseMockEISAuthServerTest { | ||
|
|
||
| public void testGetDefaultEndpoints() throws IOException { | ||
| var allModels = getAllModels(); | ||
| var chatCompletionModels = getModels("_all", TaskType.CHAT_COMPLETION); | ||
|
|
||
| if ((ElasticInferenceServiceFeature.DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG.isEnabled() | ||
| || ElasticInferenceServiceFeature.ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG.isEnabled())) { | ||
| assertThat(allModels, hasSize(4)); | ||
| assertThat(chatCompletionModels, hasSize(1)); | ||
|
|
||
| for (var model : chatCompletionModels) { | ||
| assertEquals("chat_completion", model.get("task_type")); | ||
| } | ||
| } else { | ||
| assertThat(allModels, hasSize(3)); | ||
| assertThat(chatCompletionModels, hasSize(0)); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,20 +11,8 @@ | |
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.inference.TaskType; | ||
| import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
| import org.elasticsearch.test.cluster.FeatureFlag; | ||
| import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceFeature; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.RuleChain; | ||
| import org.junit.rules.TestRule; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
|
|
@@ -35,47 +23,7 @@ | |
| import static org.elasticsearch.xpack.inference.InferenceBaseRestTest.assertStatusOkOrCreated; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class InferenceGetServicesIT extends ESRestTestCase { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this to |
||
|
|
||
| // The reason we're retrying is there's a race condition between the node retrieving the | ||
| // authorization response and running the test. Retrieving the authorization should be very fast since | ||
| // we're hosting a local mock server but it's possible it could respond slower. So in the even of a test failure | ||
| // we'll automatically retry after waiting a second. | ||
| @Rule | ||
| public RetryRule retry = new RetryRule(3, TimeValue.timeValueSeconds(1)); | ||
|
|
||
| private static final MockElasticInferenceServiceAuthorizationServer mockEISServer = MockElasticInferenceServiceAuthorizationServer | ||
| .enabledWithSparseEmbeddingsAndChatCompletion(); | ||
|
|
||
| private static final ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||
| .distribution(DistributionType.DEFAULT) | ||
| .setting("xpack.license.self_generated.type", "trial") | ||
| .setting("xpack.security.enabled", "true") | ||
| // Adding both settings unless one feature flag is disabled in a particular environment | ||
| .setting("xpack.inference.elastic.url", mockEISServer::getUrl) | ||
| // TODO remove this once we've removed DEPRECATED_ELASTIC_INFERENCE_SERVICE_FEATURE_FLAG and EIS_GATEWAY_URL | ||
| .setting("xpack.inference.eis.gateway.url", mockEISServer::getUrl) | ||
| // This plugin is located in the inference/qa/test-service-plugin package, look for TestInferenceServicePlugin | ||
| .plugin("inference-service-test") | ||
| .user("x_pack_rest_user", "x-pack-test-password") | ||
| .feature(FeatureFlag.INFERENCE_UNIFIED_API_ENABLED) | ||
| .build(); | ||
|
|
||
| // The reason we're doing this is to make sure the mock server is initialized first so we can get the address before communicating | ||
| // it to the cluster as a setting. | ||
| @ClassRule | ||
| public static TestRule ruleChain = RuleChain.outerRule(mockEISServer).around(cluster); | ||
|
|
||
| @Override | ||
| protected String getTestRestCluster() { | ||
| return cluster.getHttpAddresses(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings restClientSettings() { | ||
| String token = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray())); | ||
| return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); | ||
| } | ||
| public class InferenceGetServicesIT extends BaseMockEISAuthServerTest { | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public void testGetServicesWithoutTaskType() throws IOException { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is gone now. @vidok ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's being removed in this PR: #120842