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,19 +22,18 @@ module Elasticsearch
module API
module Inference
module Actions
# Perform inference using the Unified Schema
# Perform chat completion inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/unified-inference-api.html
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/chat-completion-inference.html
#
def unified_inference(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.unified_inference' }
def chat_completion_unified(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.chat_completion_unified' }

defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
defined_params = [:inference_id].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?
Expand All @@ -48,14 +47,8 @@ def unified_inference(arguments = {})

_inference_id = arguments.delete(:inference_id)

_task_type = arguments.delete(:task_type)

method = Elasticsearch::API::HTTP_POST
path = if _task_type && _inference_id
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_unified"
else
"_inference/#{Utils.__listify(_inference_id)}/_unified"
end
path = "_inference/chat_completion/#{Utils.__listify(_inference_id)}/_stream"
params = {}

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,18 @@ module Elasticsearch
module API
module Inference
module Actions
# Perform inference
# This functionality is Experimental and may be changed or removed
# completely in a future release. Elastic will take a best effort approach
# to fix any issues, but experimental features are not subject to the
# support SLA of official GA features.
# Perform completion inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
#
def inference(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.inference' }
def completion(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.completion' }

defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
defined_params = [:inference_id].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?
Expand All @@ -52,14 +47,8 @@ def inference(arguments = {})

_inference_id = arguments.delete(:inference_id)

_task_type = arguments.delete(:task_type)

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
path = "_inference/completion/#{Utils.__listify(_inference_id)}"
params = {}

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ module API
module Inference
module Actions
# Delete an inference endpoint
# This functionality is Experimental and may be changed or removed
# completely in a future release. Elastic will take a best effort approach
# to fix any issues, but experimental features are not subject to the
# support SLA of official GA features.
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ module API
module Inference
module Actions
# Get an inference endpoint
# This functionality is Experimental and may be changed or removed
# completely in a future release. Elastic will take a best effort approach
# to fix any issues, but experimental features are not subject to the
# support SLA of official GA features.
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ module API
module Inference
module Actions
# Configure an inference endpoint for use in the Inference API
# This functionality is Experimental and may be changed or removed
# completely in a future release. Elastic will take a best effort approach
# to fix any issues, but experimental features are not subject to the
# support SLA of official GA features.
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
#
module Elasticsearch
module API
module Inference
module Actions
# Perform reranking inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
#
def rerank(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.rerank' }

defined_params = [:inference_id].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)

_inference_id = arguments.delete(:inference_id)

method = Elasticsearch::API::HTTP_POST
path = "_inference/rerank/#{Utils.__listify(_inference_id)}"
params = {}

Elasticsearch::API::Response.new(
perform_request(method, path, params, body, headers, request_opts)
)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
#
module Elasticsearch
module API
module Inference
module Actions
# Perform sparse embedding inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
#
def sparse_embedding(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.sparse_embedding' }

defined_params = [:inference_id].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)

_inference_id = arguments.delete(:inference_id)

method = Elasticsearch::API::HTTP_POST
path = "_inference/sparse_embedding/#{Utils.__listify(_inference_id)}"
params = {}

Elasticsearch::API::Response.new(
perform_request(method, path, params, body, headers, request_opts)
)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,18 @@ module Elasticsearch
module API
module Inference
module Actions
# Perform streaming inference
# This functionality is Experimental and may be changed or removed
# completely in a future release. Elastic will take a best effort approach
# to fix any issues, but experimental features are not subject to the
# support SLA of official GA features.
# Perform streaming completion inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [String] :task_type The task type
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-stream-inference-api.html
#
def stream_inference(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_inference' }
def stream_completion(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_completion' }

defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
defined_params = [:inference_id].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?
Expand All @@ -52,14 +47,8 @@ def stream_inference(arguments = {})

_inference_id = arguments.delete(:inference_id)

_task_type = arguments.delete(:task_type)

method = Elasticsearch::API::HTTP_POST
path = if _task_type && _inference_id
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_stream"
else
"_inference/#{Utils.__listify(_inference_id)}/_stream"
end
path = "_inference/completion/#{Utils.__listify(_inference_id)}/_stream"
params = {}

Elasticsearch::API::Response.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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.
#
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
#
module Elasticsearch
module API
module Inference
module Actions
# Perform text embedding inference
#
# @option arguments [String] :inference_id The inference Id
# @option arguments [Hash] :headers Custom HTTP headers
# @option arguments [Hash] :body The inference payload
#
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
#
def text_embedding(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'inference.text_embedding' }

defined_params = [:inference_id].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)

_inference_id = arguments.delete(:inference_id)

method = Elasticsearch::API::HTTP_POST
path = "_inference/text_embedding/#{Utils.__listify(_inference_id)}"
params = {}

Elasticsearch::API::Response.new(
perform_request(method, path, params, body, headers, request_opts)
)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

require 'spec_helper'

describe 'client#inference.unified_inference' do
describe 'client#inference.chat_completion_unified' do
let(:expected_args) do
[
'POST',
'_inference/foo/bar/_unified',
'_inference/chat_completion/bar/_stream',
{},
nil,
{},
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
endpoint: 'inference.unified_inference' }
{ defined_params: { inference_id: 'bar' },
endpoint: 'inference.chat_completion_unified' }
]
end

it 'performs the request' do
expect(client_double.inference.unified_inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
expect(client_double.inference.chat_completion_unified(inference_id: 'bar')).to be_a Elasticsearch::API::Response
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

require 'spec_helper'

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

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