Skip to content

[ML] Migrate Alibaba Senders to SenderExecutableAction #126063

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static org.elasticsearch.xpack.inference.external.action.ActionUtils.wrapFailuresInElasticsearchException;

public class SenderExecutableAction implements ExecutableAction {
public sealed class SenderExecutableAction implements ExecutableAction permits SingleInputSenderExecutableAction {

private final Sender sender;
private final RequestManager requestManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Objects;

public class SingleInputSenderExecutableAction extends SenderExecutableAction {
public final class SingleInputSenderExecutableAction extends SenderExecutableAction {
private final String requestTypeForInputValidationError;

public SingleInputSenderExecutableAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
package org.elasticsearch.xpack.inference.services.alibabacloudsearch.action;

import org.elasticsearch.xpack.inference.external.action.ExecutableAction;
import org.elasticsearch.xpack.inference.external.action.SenderExecutableAction;
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchEmbeddingsRequestManager;
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchRerankRequestManager;
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchSparseRequestManager;
import org.elasticsearch.xpack.inference.external.http.sender.Sender;
import org.elasticsearch.xpack.inference.services.ServiceComponents;
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.AlibabaCloudSearchAccount;
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.completion.AlibabaCloudSearchCompletionModel;
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.embeddings.AlibabaCloudSearchEmbeddingsModel;
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.rerank.AlibabaCloudSearchRerankModel;
Expand All @@ -18,6 +23,8 @@
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.xpack.inference.external.action.ActionUtils.constructFailedToSendRequestMessage;

/**
* Provides a way to construct an {@link ExecutableAction} using the visitor pattern based on the alibaba cloud search model type.
*/
Expand All @@ -34,21 +41,29 @@ public AlibabaCloudSearchActionCreator(Sender sender, ServiceComponents serviceC
public ExecutableAction create(AlibabaCloudSearchEmbeddingsModel model, Map<String, Object> taskSettings) {
var overriddenModel = AlibabaCloudSearchEmbeddingsModel.of(model, taskSettings);

return new AlibabaCloudSearchEmbeddingsAction(sender, overriddenModel, serviceComponents);
var account = new AlibabaCloudSearchAccount(overriddenModel.getSecretSettings().apiKey());
var failedToSendRequestErrorMessage = constructFailedToSendRequestMessage("AlibabaCloud Search text embeddings");
var requestCreator = AlibabaCloudSearchEmbeddingsRequestManager.of(account, overriddenModel, serviceComponents.threadPool());
return new SenderExecutableAction(sender, requestCreator, failedToSendRequestErrorMessage);
}

@Override
public ExecutableAction create(AlibabaCloudSearchSparseModel model, Map<String, Object> taskSettings) {
var overriddenModel = AlibabaCloudSearchSparseModel.of(model, taskSettings);

return new AlibabaCloudSearchSparseAction(sender, overriddenModel, serviceComponents);
var account = new AlibabaCloudSearchAccount(overriddenModel.getSecretSettings().apiKey());
var failedToSendRequestErrorMessage = constructFailedToSendRequestMessage("AlibabaCloud Search sparse embeddings");
var requestCreator = AlibabaCloudSearchSparseRequestManager.of(account, overriddenModel, serviceComponents.threadPool());
return new SenderExecutableAction(sender, requestCreator, failedToSendRequestErrorMessage);
}

@Override
public ExecutableAction create(AlibabaCloudSearchRerankModel model, Map<String, Object> taskSettings) {
var overriddenModel = AlibabaCloudSearchRerankModel.of(model, taskSettings);

return new AlibabaCloudSearchRerankAction(sender, overriddenModel, serviceComponents);
var account = new AlibabaCloudSearchAccount(overriddenModel.getSecretSettings().apiKey());
var failedToSendRequestErrorMessage = constructFailedToSendRequestMessage("AlibabaCloud Search rerank");
var requestCreator = AlibabaCloudSearchRerankRequestManager.of(account, overriddenModel, serviceComponents.threadPool());
return new SenderExecutableAction(sender, requestCreator, failedToSendRequestErrorMessage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

package org.elasticsearch.xpack.inference.services.alibabacloudsearch.action;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
Expand All @@ -30,16 +28,14 @@
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.createInternalServerError;
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.wrapFailuresInElasticsearchException;

public class AlibabaCloudSearchCompletionAction implements ExecutableAction {
private static final Logger logger = LogManager.getLogger(AlibabaCloudSearchCompletionAction.class);

final class AlibabaCloudSearchCompletionAction implements ExecutableAction {
private final AlibabaCloudSearchAccount account;
private final AlibabaCloudSearchCompletionModel model;
private final String failedToSendRequestErrorMessage;
private final Sender sender;
private final AlibabaCloudSearchCompletionRequestManager requestCreator;

public AlibabaCloudSearchCompletionAction(Sender sender, AlibabaCloudSearchCompletionModel model, ServiceComponents serviceComponents) {
AlibabaCloudSearchCompletionAction(Sender sender, AlibabaCloudSearchCompletionModel model, ServiceComponents serviceComponents) {
this.model = Objects.requireNonNull(model);
this.sender = Objects.requireNonNull(sender);
this.account = new AlibabaCloudSearchAccount(this.model.getSecretSettings().apiKey());
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.