Skip to content

[9.0][API] Adds back inference.inference endpoint #2632

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

Merged
merged 1 commit into from
Apr 11, 2025
Merged
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
@@ -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
2 changes: 1 addition & 1 deletion elasticsearch-api/lib/elasticsearch/api/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions elasticsearch-api/spec/unit/actions/inference/inference_spec.rb
Original file line number Diff line number Diff line change
@@ -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