Skip to content

Conversation

@jonathan-buttner
Copy link
Contributor

This PR refactors some logic that currently requires TaskType.ANY to be returned in the supportedStreamingTasks call. If the task type is not included in the request action in the REST API call then the task type is set to ANY.

We perform validation on the request and backing model to ensure that in the request task type is the same as the backing model or the request task type is ANY, indicating that it wasn't included.

This means that the request task type must match the model (aside from being ANY). So we can pass in the backing model task type instead when determining if the service can support streaming.

There were a number of classes that relied on the field:

this.canHandleStreamingResponses

I moved this into the response handle's base class.

@jonathan-buttner jonathan-buttner added >refactoring :ml Machine learning Team:ML Meta label for the ML team v9.0.1 labels Jan 31, 2025

private void inferOnService(Model model, Request request, InferenceService service, ActionListener<InferenceServiceResults> listener) {
if (request.isStreaming() == false || service.canStream(request.getTaskType())) {
if (request.isStreaming() == false || service.canStream(model.getTaskType())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the model's task type to determine streaming (can never be any).


@Override
public boolean canHandleStreamingResponses() {
return canHandleStreamingResponses;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved here to the base class.

public abstract class AmazonBedrockResponseHandler implements ResponseHandler {

@Override
public boolean canHandleStreamingResponses() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit unfortunate. This response handler is a workaround and isn't really used because this service uses its own client. AmazonBedrock does support streaming the responses but its handled in a separate place.

Copy link
Member

Choose a reason for hiding this comment

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

Eh we need to separate Bedrock from everything after Sender anyway, since it has its own internal threadpool and all the stuff we wrap around the http client

}
}

@Override
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this class to the test directory since that's the only place it's referenced.

@jonathan-buttner jonathan-buttner marked this pull request as ready for review February 3, 2025 13:19
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Copy link
Member

@prwhelan prwhelan left a comment

Choose a reason for hiding this comment

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

Thanks! TaskType.ANY was a holdover from a quick fix during release. This is a good refactor.

public abstract class AmazonBedrockResponseHandler implements ResponseHandler {

@Override
public boolean canHandleStreamingResponses() {
Copy link
Member

Choose a reason for hiding this comment

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

Eh we need to separate Bedrock from everything after Sender anyway, since it has its own internal threadpool and all the stuff we wrap around the http client

@jonathan-buttner jonathan-buttner merged commit 7f284d3 into elastic:main Feb 4, 2025
17 checks passed
@jonathan-buttner jonathan-buttner deleted the ml-remove-stream-any branch February 4, 2025 14:45
fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Feb 4, 2025
* Refactoring supported streaming functionality

* Moving always retrying handler to the tests

* Fixing comment
jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request Mar 3, 2025
* Refactoring supported streaming functionality

* Moving always retrying handler to the tests

* Fixing comment

(cherry picked from commit 7f284d3)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/openai/OpenAiResponseHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java
@jonathan-buttner
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Mar 4, 2025
…#123927)

* [ML] Remove tasktype any from supportedStreamingTasks (#121460)

* Refactoring supported streaming functionality

* Moving always retrying handler to the tests

* Fixing comment

(cherry picked from commit 7f284d3)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/openai/OpenAiResponseHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java

* Fixing test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:ml Machine learning >refactoring Team:ML Meta label for the ML team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants