Skip to content
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
Expand Up @@ -22,37 +22,40 @@ module Elasticsearch
module API
module Inference
module Actions
# Configure an inference endpoint that uses the Elastic Inference Service (EIS)
# Perform inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
# @option arguments [String] :eis_inference_id The inference ID
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference endpoint's task and service settings
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/infer-service-elastic.html
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
#
def put_eis(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.put_eis' }
def inference(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.inference' }

defined_params = %i[task_type eis_inference_id].each_with_object({}) do |variable, set_variables|
defined_params = %i[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 'task_type' missing" unless arguments[:task_type]
raise ArgumentError, "Required argument 'eis_inference_id' missing" unless arguments[:eis_inference_id]
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)

_eis_inference_id = arguments.delete(:eis_inference_id)
_task_type = arguments.delete(:task_type)

method = Elasticsearch::API::HTTP_PUT
path = "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_eis_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 = {}

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

require 'spec_helper'

describe 'client#inference.put_eis' do
describe 'client#inference.inference' do
let(:expected_args) do
[
'PUT',
'POST',
'_inference/foo/bar',
{},
nil,
{},
{ defined_params: { eis_inference_id: 'bar', task_type: 'foo' },
endpoint: 'inference.put_eis' }
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
endpoint: 'inference.inference' }
]
end

it 'performs the request' do
expect(client_double.inference.put_eis(task_type: 'foo', eis_inference_id: 'bar')).to be_a Elasticsearch::API::Response
expect(client_double.inference.inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
end
end