-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Inference API] Add special case to inference API #116962
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
Changes from all commits
8d8c5fc
7df7d89
69da049
1c2a48b
df09f02
0624001
f25fdf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 116962 | ||
summary: "Add special case for elastic reranker in inference API" | ||
area: Machine Learning | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.elasticsearch; | ||
|
||
import org.elasticsearch.ResourceNotFoundException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.inference.ChunkingSettings; | ||
import org.elasticsearch.inference.Model; | ||
import org.elasticsearch.inference.TaskType; | ||
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction; | ||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; | ||
|
||
public class ElasticRerankerModel extends ElasticsearchInternalModel { | ||
|
||
public ElasticRerankerModel( | ||
String inferenceEntityId, | ||
TaskType taskType, | ||
String service, | ||
ElasticRerankerServiceSettings serviceSettings, | ||
ChunkingSettings chunkingSettings | ||
) { | ||
super(inferenceEntityId, taskType, service, serviceSettings, chunkingSettings); | ||
} | ||
|
||
@Override | ||
public ElasticRerankerServiceSettings getServiceSettings() { | ||
return (ElasticRerankerServiceSettings) super.getServiceSettings(); | ||
} | ||
|
||
@Override | ||
public ActionListener<CreateTrainedModelAssignmentAction.Response> getCreateTrainedModelAssignmentActionListener( | ||
Model model, | ||
ActionListener<Boolean> listener | ||
) { | ||
|
||
return new ActionListener<>() { | ||
@Override | ||
public void onResponse(CreateTrainedModelAssignmentAction.Response response) { | ||
listener.onResponse(Boolean.TRUE); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
if (ExceptionsHelper.unwrapCause(e) instanceof ResourceNotFoundException) { | ||
listener.onFailure( | ||
new ResourceNotFoundException("Could not start the Elastic Reranker Endpoint due to [{}]", e, e.getMessage()) | ||
); | ||
return; | ||
} | ||
listener.onFailure(e); | ||
} | ||
}; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.elasticsearch; | ||
|
||
import org.elasticsearch.common.ValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.xpack.core.ml.inference.assignment.AdaptiveAllocationsSettings; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class ElasticRerankerServiceSettings extends ElasticsearchInternalServiceSettings { | ||
|
||
public static final String NAME = "elastic_reranker_service_settings"; | ||
|
||
public ElasticRerankerServiceSettings(ElasticsearchInternalServiceSettings other) { | ||
super(other); | ||
} | ||
|
||
public ElasticRerankerServiceSettings( | ||
Integer numAllocations, | ||
int numThreads, | ||
String modelId, | ||
AdaptiveAllocationsSettings adaptiveAllocationsSettings | ||
) { | ||
super(numAllocations, numThreads, modelId, adaptiveAllocationsSettings); | ||
} | ||
|
||
public ElasticRerankerServiceSettings(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
/** | ||
* Parse the ElasticRerankerServiceSettings from map and validate the setting values. | ||
* | ||
* If required setting are missing or the values are invalid an | ||
* {@link ValidationException} is thrown. | ||
* | ||
* @param map Source map containing the config | ||
* @return The builder | ||
*/ | ||
public static Builder fromRequestMap(Map<String, Object> map) { | ||
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. nit: I'm fine with keep it since it's the pattern we have, but I don't believe we use this method yet right? 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. good point, we could remove this. I'm ambiguous about it. We could remove some of the constructors as well. I'm leaning towards just leaving them in. |
||
ValidationException validationException = new ValidationException(); | ||
var baseSettings = ElasticsearchInternalServiceSettings.fromMap(map, validationException); | ||
|
||
if (validationException.validationErrors().isEmpty() == false) { | ||
throw validationException; | ||
} | ||
|
||
return baseSettings; | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return ElasticRerankerServiceSettings.NAME; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.