-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from theablefew/esmarkowski/add-machinelearnin…
…g-models Add MachineLearning Models
- Loading branch information
Showing
41 changed files
with
1,623 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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 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
33 changes: 33 additions & 0 deletions
33
lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb
This file contains 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,33 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Returns a model. | ||
# | ||
# @option arguments [String] :id The model id | ||
# @option arguments [Hash] :headers Custom HTTP headers | ||
# | ||
# Example | ||
# delete_model(id: 109sdj0asl092) | ||
# | ||
# DELETE /_plugins/_ml/models/<model_id> | ||
def delete_model(arguments = {}) | ||
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] | ||
headers = arguments.delete(:headers) || {} | ||
|
||
_id = arguments.delete(:id) | ||
|
||
method = Elasticsearch::API::HTTP_DELETE | ||
path = "_plugins/_ml/models/#{Utils.__listify(_id)}" | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
body = nil | ||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/elasticsearch/api/actions/machine_learning/models/deploy.rb
This file contains 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,31 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Register a model. | ||
# | ||
# @option arguments [String] :id The model id | ||
# @option arguments [Hash] :body The deploy options | ||
# | ||
# | ||
# POST /_plugins/_ml/models/<model_id>/_deploy | ||
def deploy(arguments = {}) | ||
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] | ||
_id = arguments.delete(:id) | ||
arguments = arguments.clone | ||
headers = arguments.delete(:headers) || {} | ||
|
||
method = Elasticsearch::API::HTTP_POST | ||
path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_deploy" | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
body = arguments[:body] | ||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
lib/elasticsearch/api/actions/machine_learning/models/get_model.rb
This file contains 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,43 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Returns a model. | ||
# | ||
# @option arguments [String] :id The model id | ||
# | ||
# Example | ||
# get_model(id: 109sdj0asl092) | ||
# | ||
# Example | ||
# # Get all models | ||
# get_model | ||
# | ||
# GET /_plugins/_ml/models/<model_id> | ||
def get_model(arguments = {}) | ||
_id = arguments.delete(:id) | ||
headers = arguments.delete(:headers) || {} | ||
method = Elasticsearch::API::HTTP_GET | ||
path = if _id | ||
body = nil | ||
"_ml/trained_models/#{Utils.__listify(_id)}" | ||
else | ||
body = { | ||
"query": { | ||
"match_all": {} | ||
}, | ||
"size": 1000 | ||
} | ||
'_ml/trained_models' | ||
end | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/elasticsearch/api/actions/machine_learning/models/get_status.rb
This file contains 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,31 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Register a model. | ||
# | ||
# @option arguments [String] :id The model id | ||
# @option arguments [Hash] :body The deploy options | ||
# | ||
# | ||
# GET /_plugins/_ml/tasks/<task_id> | ||
def get_status(arguments = {}) | ||
raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id] | ||
_id = arguments.delete(:task_id) | ||
arguments = arguments.clone | ||
headers = arguments.delete(:headers) || {} | ||
|
||
method = Elasticsearch::API::HTTP_GET | ||
path = "_plugins/_ml/tasks/#{Utils.__listify(_id)}" | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
body = nil | ||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb
This file contains 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,45 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
module ParamsRegistry | ||
extend self | ||
|
||
# A Mapping of all the actions to their list of valid params. | ||
# | ||
# @since 6.1.1 | ||
PARAMS = {} | ||
|
||
# Register an action with its list of valid params. | ||
# | ||
# @example Register the action. | ||
# ParamsRegistry.register(:benchmark, [ :verbose ]) | ||
# | ||
# @param [ Symbol ] action The action to register. | ||
# @param [ Array[Symbol] ] valid_params The list of valid params. | ||
# | ||
# @since 6.1.1 | ||
def register(action, valid_params) | ||
PARAMS[action.to_sym] = valid_params | ||
end | ||
|
||
# Get the list of valid params for a given action. | ||
# | ||
# @example Get the list of valid params. | ||
# ParamsRegistry.get(:benchmark) | ||
# | ||
# @param [ Symbol ] action The action. | ||
# | ||
# @return [ Array<Symbol> ] The list of valid params for the action. | ||
# | ||
# @since 6.1.1 | ||
def get(action) | ||
PARAMS.fetch(action, []) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
lib/elasticsearch/api/actions/machine_learning/models/register.rb
This file contains 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,45 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Register a model. | ||
# | ||
# @option arguments [Hash] :body The model definition **Required** | ||
# @option arguments [Boolean] :deploy Whether to deploy the model after registering it. The deploy operation is performed by calling the [Deploy Model API](https://opensearch.org/docs/latest/ml-commons-plugin/api/model-apis/deploy-model/). Default is `false` | ||
# | ||
# Example | ||
# client.machine_learing_model.register(body: { | ||
# "name": "huggingface/sentence-transformers/msmarco-distilbert-base-tas-b", | ||
# "version": "1.0.1", | ||
# "model_group_id": "Z1eQf4oB5Vm0Tdw8EIP2", | ||
# "model_format": "TORCH_SCRIPT" | ||
# }, | ||
# deploy: true | ||
# | ||
# POST /_plugins/_ml/models/_register | ||
def register(arguments = {}) | ||
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] | ||
|
||
arguments = arguments.clone | ||
headers = arguments.delete(:headers) || {} | ||
|
||
method = Elasticsearch::API::HTTP_POST | ||
path = "_plugins/_ml/models/_register" | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
body = arguments[:body] | ||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
# Register this action with its valid params when the module is loaded. | ||
# | ||
# @since 6.2.0 | ||
ParamsRegistry.register(:put_pipeline, %i[ | ||
deploy | ||
].freeze) | ||
end | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb
This file contains 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,32 @@ | ||
module Elasticsearch | ||
module API | ||
module MachineLearning | ||
module Models | ||
module Actions | ||
# Register a model. | ||
# | ||
# @option arguments [String] :id The model id | ||
# @option arguments [Hash] :body The deploy options | ||
# | ||
# | ||
# POST /_plugins/_ml/models/<model_id>/_undeploy | ||
def undeploy(arguments = {}) | ||
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] | ||
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] | ||
_id = arguments.delete(:id) | ||
arguments = arguments.clone | ||
headers = arguments.delete(:headers) || {} | ||
|
||
method = Elasticsearch::API::HTTP_POST | ||
path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_undeploy" | ||
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) | ||
|
||
body = arguments[:body] | ||
perform_request(method, path, params, body, headers).body | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.