diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb new file mode 100644 index 0000000000..5d0c86c617 --- /dev/null +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb @@ -0,0 +1,72 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# This code was automatically generated from the Elasticsearch Specification +# See https://github.com/elastic/elasticsearch-specification +# See Elasticsearch::ES_SPECIFICATION_COMMIT for commit hash. +module Elasticsearch + module API + module Inference + module Actions + # Perform inference on the service. + # This API enables you to use machine learning models to perform specific tasks on data that you provide as an input. + # It returns a response with the results of the tasks. + # The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API. + # + # @option arguments [String] :task_type The type of inference task that the model performs. + # @option arguments [String] :inference_id The unique identifier for the inference endpoint. (*Required*) + # @option arguments [Time] :timeout The amount of time to wait for the inference request to complete. Server default: 30s. + # @option arguments [Hash] :headers Custom HTTP headers + # @option arguments [Hash] :body request body + # + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference + # + def inference(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.inference' } + + defined_params = [:inference_id, :task_type].each_with_object({}) do |variable, set_variables| + set_variables[variable] = arguments[variable] if arguments.key?(variable) + end + request_opts[:defined_params] = defined_params unless defined_params.empty? + + raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + body = arguments.delete(:body) + + _task_type = arguments.delete(:task_type) + + _inference_id = arguments.delete(:inference_id) + + method = Elasticsearch::API::HTTP_POST + path = if _task_type && _inference_id + "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_inference_id)}" + else + "_inference/#{Utils.listify(_inference_id)}" + end + params = Utils.process_params(arguments) + + Elasticsearch::API::Response.new( + perform_request(method, path, params, body, headers, request_opts) + ) + end + end + end + end +end diff --git a/elasticsearch-api/lib/elasticsearch/api/version.rb b/elasticsearch-api/lib/elasticsearch/api/version.rb index 4aba4e6dbe..ea92083ae0 100644 --- a/elasticsearch-api/lib/elasticsearch/api/version.rb +++ b/elasticsearch-api/lib/elasticsearch/api/version.rb @@ -18,6 +18,6 @@ module Elasticsearch module API VERSION = '9.0.0'.freeze - ES_SPECIFICATION_COMMIT = '60a81659be928bfe6cec53708c7f7613555a5eaf'.freeze + ES_SPECIFICATION_COMMIT = 'f2651fcb540f55100a80629192c021fd2e7a019c'.freeze end end diff --git a/elasticsearch-api/spec/unit/actions/inference/inference_spec.rb b/elasticsearch-api/spec/unit/actions/inference/inference_spec.rb new file mode 100644 index 0000000000..dfa2a51890 --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/inference/inference_spec.rb @@ -0,0 +1,36 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'spec_helper' + +describe 'client#inference.inference' do + let(:expected_args) do + [ + 'POST', + '_inference/bar', + {}, + nil, + {}, + { defined_params: { inference_id: 'bar' }, + endpoint: 'inference.inference' } + ] + end + + it 'performs the request' do + expect(client_double.inference.inference(inference_id: 'bar')).to be_a Elasticsearch::API::Response + end +end