-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Inference] Implementing the completion task type on EIS. #137677
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
Draft
afoucret
wants to merge
9
commits into
elastic:main
Choose a base branch
from
afoucret:inference-eis-completion-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1802d60
[Inference] Implementing the completion task type on EIS.
afoucret 14c0be5
[CI] Auto commit changes from spotless
f8a0ec0
Lint
afoucret 1682d03
Update docs/changelog/137677.yaml
afoucret a22bbd9
Fix changelog
afoucret e2ed11c
Apply code review suggestions.
afoucret 1b70962
Apply feedback from code review.
afoucret 9832fde
Fix tests error.
afoucret e761192
Merge branch 'main' into inference-eis-completion-support
afoucret 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 137677 | ||
| summary: "[Inference] Implementing the completion task type on EIS" | ||
| area: "Machine Learning, Inference" | ||
| type: enhancement | ||
| issues: [] |
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
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
124 changes: 124 additions & 0 deletions
124
...ack/inference/services/elastic/completion/ElasticInferenceServiceChatCompletionModel.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,124 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.inference.services.elastic.completion; | ||
|
|
||
| import org.elasticsearch.ElasticsearchStatusException; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.inference.EmptySecretSettings; | ||
| import org.elasticsearch.inference.EmptyTaskSettings; | ||
| import org.elasticsearch.inference.ModelConfigurations; | ||
| import org.elasticsearch.inference.ModelSecrets; | ||
| import org.elasticsearch.inference.SecretSettings; | ||
| import org.elasticsearch.inference.TaskSettings; | ||
| import org.elasticsearch.inference.TaskType; | ||
| import org.elasticsearch.inference.UnifiedCompletionRequest; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.xpack.inference.services.ConfigurationParseContext; | ||
| import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceComponents; | ||
| import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceModel; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| public class ElasticInferenceServiceChatCompletionModel extends ElasticInferenceServiceModel { | ||
|
|
||
| public static ElasticInferenceServiceChatCompletionModel of( | ||
|
||
| ElasticInferenceServiceChatCompletionModel model, | ||
| UnifiedCompletionRequest request | ||
| ) { | ||
| var originalModelServiceSettings = model.getServiceSettings(); | ||
| var overriddenServiceSettings = new ElasticInferenceServiceCompletionServiceSettings( | ||
| Objects.requireNonNullElse(request.model(), originalModelServiceSettings.modelId()) | ||
| ); | ||
|
|
||
| return new ElasticInferenceServiceChatCompletionModel(model, overriddenServiceSettings); | ||
| } | ||
|
|
||
| private final URI uri; | ||
|
|
||
| public ElasticInferenceServiceChatCompletionModel( | ||
| String inferenceEntityId, | ||
| TaskType taskType, | ||
| String service, | ||
| Map<String, Object> serviceSettings, | ||
| Map<String, Object> taskSettings, | ||
| Map<String, Object> secrets, | ||
| ElasticInferenceServiceComponents elasticInferenceServiceComponents, | ||
| ConfigurationParseContext context | ||
| ) { | ||
| this( | ||
| inferenceEntityId, | ||
| taskType, | ||
| service, | ||
| ElasticInferenceServiceCompletionServiceSettings.fromMap(serviceSettings, context), | ||
| EmptyTaskSettings.INSTANCE, | ||
| EmptySecretSettings.INSTANCE, | ||
| elasticInferenceServiceComponents | ||
| ); | ||
| } | ||
|
|
||
| public ElasticInferenceServiceChatCompletionModel( | ||
| ElasticInferenceServiceChatCompletionModel model, | ||
| ElasticInferenceServiceCompletionServiceSettings serviceSettings | ||
| ) { | ||
| super(model, serviceSettings); | ||
| this.uri = createUri(); | ||
|
|
||
| } | ||
|
|
||
| public ElasticInferenceServiceChatCompletionModel( | ||
| String inferenceEntityId, | ||
| TaskType taskType, | ||
| String service, | ||
| ElasticInferenceServiceCompletionServiceSettings serviceSettings, | ||
| @Nullable TaskSettings taskSettings, | ||
| @Nullable SecretSettings secretSettings, | ||
| ElasticInferenceServiceComponents elasticInferenceServiceComponents | ||
| ) { | ||
| super( | ||
| new ModelConfigurations(inferenceEntityId, taskType, service, serviceSettings, taskSettings), | ||
| new ModelSecrets(secretSettings), | ||
| serviceSettings, | ||
| elasticInferenceServiceComponents | ||
| ); | ||
|
|
||
| this.uri = createUri(); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public ElasticInferenceServiceCompletionServiceSettings getServiceSettings() { | ||
| return (ElasticInferenceServiceCompletionServiceSettings) super.getServiceSettings(); | ||
| } | ||
|
|
||
| public URI uri() { | ||
| return uri; | ||
| } | ||
|
|
||
| private URI createUri() throws ElasticsearchStatusException { | ||
| try { | ||
| // TODO, consider transforming the base URL into a URI for better error handling. | ||
| return new URI(elasticInferenceServiceComponents().elasticInferenceServiceUrl() + "/api/v1/chat"); | ||
| } catch (URISyntaxException e) { | ||
| throw new ElasticsearchStatusException( | ||
| "Failed to create URI for service [" | ||
| + this.getConfigurations().getService() | ||
| + "] with taskType [" | ||
| + this.getTaskType() | ||
| + "]: " | ||
| + e.getMessage(), | ||
| RestStatus.BAD_REQUEST, | ||
| e | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // TODO create/refactor the Configuration class to be extensible for different task types (i.e completion, sparse embeddings). | ||
| } | ||
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.
Once we switch to using a single model class we should be able to follow what OpenAI does here: and have
case CHAT_COMPLETION, COMPLETION -> ...