Skip to content

Commit 6bcff71

Browse files
committed
[API] Adds inference.put_ai21 and inference.put_llama
1 parent 8304c3d commit 6bcff71

File tree

5 files changed

+234
-4
lines changed

5 files changed

+234
-4
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@ module Actions
2727
# For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.
2828
# However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.
2929
# The following integrations are available through the inference API. You can find the available task types next to the integration name:
30+
# * AI21 (`chat_completion`, `completion`)
3031
# * AlibabaCloud AI Search (`completion`, `rerank`, `sparse_embedding`, `text_embedding`)
3132
# * Amazon Bedrock (`completion`, `text_embedding`)
3233
# * Amazon SageMaker (`chat_completion`, `completion`, `rerank`, `sparse_embedding`, `text_embedding`)
3334
# * Anthropic (`completion`)
3435
# * Azure AI Studio (`completion`, 'rerank', `text_embedding`)
3536
# * Azure OpenAI (`completion`, `text_embedding`)
3637
# * Cohere (`completion`, `rerank`, `text_embedding`)
37-
# * DeepSeek (`completion`, `chat_completion`)
38+
# * DeepSeek (`chat_completion`, `completion`)
3839
# * Elasticsearch (`rerank`, `sparse_embedding`, `text_embedding` - this service is for built-in models and models uploaded through Eland)
3940
# * ELSER (`sparse_embedding`)
4041
# * Google AI Studio (`completion`, `text_embedding`)
41-
# * Google Vertex AI (`rerank`, `text_embedding`)
42+
# * Google Vertex AI (`chat_completion`, `completion`, `rerank`, `text_embedding`)
4243
# * Hugging Face (`chat_completion`, `completion`, `rerank`, `text_embedding`)
44+
# * JinaAI (`rerank`, `text_embedding`)
45+
# * Llama (`chat_completion`, `completion`, `text_embedding`)
4346
# * Mistral (`chat_completion`, `completion`, `text_embedding`)
4447
# * OpenAI (`chat_completion`, `completion`, `text_embedding`)
45-
# * VoyageAI (`text_embedding`, `rerank`)
48+
# * VoyageAI (`rerank`, `text_embedding`)
4649
# * Watsonx inference integration (`text_embedding`)
47-
# * JinaAI (`text_embedding`, `rerank`)
4850
#
4951
# @option arguments [String] :task_type The task type. Refer to the integration list in the API description for the available task types.
5052
# @option arguments [String] :inference_id The inference Id (*Required*)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
# This code was automatically generated from the Elasticsearch Specification
19+
# See https://github.com/elastic/elasticsearch-specification
20+
# See Elasticsearch::ES_SPECIFICATION_COMMIT for commit hash.
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Create a AI21 inference endpoint.
26+
# Create an inference endpoint to perform an inference task with the `ai21` service.
27+
#
28+
# @option arguments [String] :task_type The type of the inference task that the model will perform. (*Required*)
29+
# @option arguments [String] :ai21_inference_id The unique identifier of the inference endpoint. (*Required*)
30+
# @option arguments [Time] :timeout Specifies the amount of time to wait for the inference endpoint to be created. Server default: 30s.
31+
# @option arguments [Boolean] :error_trace When set to `true` Elasticsearch will include the full stack trace of errors
32+
# when they occur.
33+
# @option arguments [String, Array<String>] :filter_path Comma-separated list of filters in dot notation which reduce the response
34+
# returned by Elasticsearch.
35+
# @option arguments [Boolean] :human When set to `true` will return statistics in a format suitable for humans.
36+
# For example `"exists_time": "1h"` for humans and
37+
# `"exists_time_in_millis": 3600000` for computers. When disabled the human
38+
# readable values will be omitted. This makes sense for responses being consumed
39+
# only by machines.
40+
# @option arguments [Boolean] :pretty If set to `true` the returned JSON will be "pretty-formatted". Only use
41+
# this option for debugging only.
42+
# @option arguments [Hash] :headers Custom HTTP headers
43+
# @option arguments [Hash] :body request body
44+
#
45+
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-ai21
46+
#
47+
def put_ai21(arguments = {})
48+
request_opts = { endpoint: arguments[:endpoint] || 'inference.put_ai21' }
49+
50+
defined_params = [:task_type, :ai21_inference_id].each_with_object({}) do |variable, set_variables|
51+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
52+
end
53+
request_opts[:defined_params] = defined_params unless defined_params.empty?
54+
55+
raise ArgumentError, "Required argument 'task_type' missing" unless arguments[:task_type]
56+
raise ArgumentError, "Required argument 'ai21_inference_id' missing" unless arguments[:ai21_inference_id]
57+
58+
arguments = arguments.clone
59+
headers = arguments.delete(:headers) || {}
60+
61+
body = arguments.delete(:body)
62+
63+
_task_type = arguments.delete(:task_type)
64+
65+
_ai21_inference_id = arguments.delete(:ai21_inference_id)
66+
67+
method = Elasticsearch::API::HTTP_PUT
68+
path = "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_ai21_inference_id)}"
69+
params = Utils.process_params(arguments)
70+
71+
Elasticsearch::API::Response.new(
72+
perform_request(method, path, params, body, headers, request_opts)
73+
)
74+
end
75+
end
76+
end
77+
end
78+
end
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
# This code was automatically generated from the Elasticsearch Specification
19+
# See https://github.com/elastic/elasticsearch-specification
20+
# See Elasticsearch::ES_SPECIFICATION_COMMIT for commit hash.
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Create a Llama inference endpoint.
26+
# Create an inference endpoint to perform an inference task with the `llama` service.
27+
#
28+
# @option arguments [String] :task_type The type of the inference task that the model will perform. (*Required*)
29+
# @option arguments [String] :llama_inference_id The unique identifier of the inference endpoint. (*Required*)
30+
# @option arguments [Time] :timeout Specifies the amount of time to wait for the inference endpoint to be created. Server default: 30s.
31+
# @option arguments [Boolean] :error_trace When set to `true` Elasticsearch will include the full stack trace of errors
32+
# when they occur.
33+
# @option arguments [String, Array<String>] :filter_path Comma-separated list of filters in dot notation which reduce the response
34+
# returned by Elasticsearch.
35+
# @option arguments [Boolean] :human When set to `true` will return statistics in a format suitable for humans.
36+
# For example `"exists_time": "1h"` for humans and
37+
# `"exists_time_in_millis": 3600000` for computers. When disabled the human
38+
# readable values will be omitted. This makes sense for responses being consumed
39+
# only by machines.
40+
# @option arguments [Boolean] :pretty If set to `true` the returned JSON will be "pretty-formatted". Only use
41+
# this option for debugging only.
42+
# @option arguments [Hash] :headers Custom HTTP headers
43+
# @option arguments [Hash] :body request body
44+
#
45+
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-llama
46+
#
47+
def put_llama(arguments = {})
48+
request_opts = { endpoint: arguments[:endpoint] || 'inference.put_llama' }
49+
50+
defined_params = [:task_type, :llama_inference_id].each_with_object({}) do |variable, set_variables|
51+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
52+
end
53+
request_opts[:defined_params] = defined_params unless defined_params.empty?
54+
55+
raise ArgumentError, "Required argument 'task_type' missing" unless arguments[:task_type]
56+
raise ArgumentError, "Required argument 'llama_inference_id' missing" unless arguments[:llama_inference_id]
57+
58+
arguments = arguments.clone
59+
headers = arguments.delete(:headers) || {}
60+
61+
body = arguments.delete(:body)
62+
63+
_task_type = arguments.delete(:task_type)
64+
65+
_llama_inference_id = arguments.delete(:llama_inference_id)
66+
67+
method = Elasticsearch::API::HTTP_PUT
68+
path = "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_llama_inference_id)}"
69+
params = Utils.process_params(arguments)
70+
71+
Elasticsearch::API::Response.new(
72+
perform_request(method, path, params, body, headers, request_opts)
73+
)
74+
end
75+
end
76+
end
77+
end
78+
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.put_ai21' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
'_inference/foo/bar',
25+
{},
26+
nil,
27+
{},
28+
{ defined_params: { ai21_inference_id: 'bar', task_type: 'foo' },
29+
endpoint: 'inference.put_ai21' }
30+
]
31+
end
32+
33+
it 'performs the request' do
34+
expect(client_double.inference.put_ai21(task_type: 'foo', ai21_inference_id: 'bar')).to be_a Elasticsearch::API::Response
35+
end
36+
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.put_llama' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
'_inference/foo/bar',
25+
{},
26+
nil,
27+
{},
28+
{ defined_params: { llama_inference_id: 'bar', task_type: 'foo' },
29+
endpoint: 'inference.put_llama' }
30+
]
31+
end
32+
33+
it 'performs the request' do
34+
expect(client_double.inference.put_llama(task_type: 'foo', llama_inference_id: 'bar')).to be_a Elasticsearch::API::Response
35+
end
36+
end

0 commit comments

Comments
 (0)