Skip to content

Commit 32e2531

Browse files
committed
[API] Adds unified_inference
1 parent 6dcae4f commit 32e2531

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Perform inference using the Unified Schema
26+
#
27+
# @option arguments [String] :inference_id The inference Id
28+
# @option arguments [String] :task_type The task type
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
# @option arguments [Hash] :body The inference payload
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/unified-inference-api.html
33+
#
34+
def unified_inference(arguments = {})
35+
request_opts = { endpoint: arguments[:endpoint] || 'inference.unified_inference' }
36+
37+
defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
38+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
39+
end
40+
request_opts[:defined_params] = defined_params unless defined_params.empty?
41+
42+
raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id]
43+
44+
arguments = arguments.clone
45+
headers = arguments.delete(:headers) || {}
46+
47+
body = arguments.delete(:body)
48+
49+
_inference_id = arguments.delete(:inference_id)
50+
51+
_task_type = arguments.delete(:task_type)
52+
53+
method = Elasticsearch::API::HTTP_POST
54+
path = if _task_type && _inference_id
55+
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_unified"
56+
else
57+
"_inference/#{Utils.__listify(_inference_id)}/_unified"
58+
end
59+
params = {}
60+
61+
Elasticsearch::API::Response.new(
62+
perform_request(method, path, params, body, headers, request_opts)
63+
)
64+
end
65+
end
66+
end
67+
end
68+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client#inference.unified_inference' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_inference/foo/bar/_unified',
25+
{},
26+
nil,
27+
{},
28+
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
29+
endpoint: 'inference.unified_inference' }
30+
]
31+
end
32+
33+
it 'performs the request' do
34+
expect(client_double.inference.unified_inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
35+
end
36+
end

0 commit comments

Comments
 (0)