|
| 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 custom inference endpoint. |
| 26 | + # The custom service gives more control over how to interact with external inference services that aren't explicitly supported through dedicated integrations. |
| 27 | + # The custom service gives you the ability to define the headers, url, query parameters, request body, and secrets. |
| 28 | + # The custom service supports the template replacement functionality, which enables you to define a template that can be replaced with the value associated with that key. |
| 29 | + # Templates are portions of a string that start with `${` and end with `}`. |
| 30 | + # The parameters `secret_parameters` and `task_settings` are checked for keys for template replacement. Template replacement is supported in the `request`, `headers`, `url`, and `query_parameters`. |
| 31 | + # If the definition (key) is not found for a template, an error message is returned. |
| 32 | + # In case of an endpoint definition like the following: |
| 33 | + # |
| 34 | + # ``` |
| 35 | + # PUT _inference/text_embedding/test-text-embedding |
| 36 | + # { |
| 37 | + # "service": "custom", |
| 38 | + # "service_settings": { |
| 39 | + # "secret_parameters": { |
| 40 | + # "api_key": "<some api key>" |
| 41 | + # }, |
| 42 | + # "url": "...endpoints.huggingface.cloud/v1/embeddings", |
| 43 | + # "headers": { |
| 44 | + # "Authorization": "Bearer ${api_key}", |
| 45 | + # "Content-Type": "application/json" |
| 46 | + # }, |
| 47 | + # "request": "{\"input\": ${input}}", |
| 48 | + # "response": { |
| 49 | + # "json_parser": { |
| 50 | + # "text_embeddings":"$.data[*].embedding[*]" |
| 51 | + # } |
| 52 | + # } |
| 53 | + # } |
| 54 | + # } |
| 55 | + # ``` |
| 56 | + # |
| 57 | + # To replace `${api_key}` the `secret_parameters` and `task_settings` are checked for a key named `api_key`. |
| 58 | + # |
| 59 | + # @option arguments [String] :task_type The type of the inference task that the model will perform. (*Required*) |
| 60 | + # @option arguments [String] :custom_inference_id The unique identifier of the inference endpoint. (*Required*) |
| 61 | + # @option arguments [Boolean] :error_trace When set to `true` Elasticsearch will include the full stack trace of errors |
| 62 | + # when they occur. |
| 63 | + # @option arguments [String, Array<String>] :filter_path Comma-separated list of filters in dot notation which reduce the response |
| 64 | + # returned by Elasticsearch. |
| 65 | + # @option arguments [Boolean] :human When set to `true` will return statistics in a format suitable for humans. |
| 66 | + # For example `"exists_time": "1h"` for humans and |
| 67 | + # `"exists_time_in_millis": 3600000` for computers. When disabled the human |
| 68 | + # readable values will be omitted. This makes sense for responses being consumed |
| 69 | + # only by machines. |
| 70 | + # @option arguments [Boolean] :pretty If set to `true` the returned JSON will be "pretty-formatted". Only use |
| 71 | + # this option for debugging only. |
| 72 | + # @option arguments [Hash] :headers Custom HTTP headers |
| 73 | + # @option arguments [Hash] :body request body |
| 74 | + # |
| 75 | + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-custom |
| 76 | + # |
| 77 | + def put_custom(arguments = {}) |
| 78 | + request_opts = { endpoint: arguments[:endpoint] || 'inference.put_custom' } |
| 79 | + |
| 80 | + defined_params = [:task_type, :custom_inference_id].each_with_object({}) do |variable, set_variables| |
| 81 | + set_variables[variable] = arguments[variable] if arguments.key?(variable) |
| 82 | + end |
| 83 | + request_opts[:defined_params] = defined_params unless defined_params.empty? |
| 84 | + |
| 85 | + raise ArgumentError, "Required argument 'task_type' missing" unless arguments[:task_type] |
| 86 | + |
| 87 | + unless arguments[:custom_inference_id] |
| 88 | + raise ArgumentError, |
| 89 | + "Required argument 'custom_inference_id' missing" |
| 90 | + end |
| 91 | + |
| 92 | + arguments = arguments.clone |
| 93 | + headers = arguments.delete(:headers) || {} |
| 94 | + |
| 95 | + body = arguments.delete(:body) |
| 96 | + |
| 97 | + _task_type = arguments.delete(:task_type) |
| 98 | + |
| 99 | + _custom_inference_id = arguments.delete(:custom_inference_id) |
| 100 | + |
| 101 | + method = Elasticsearch::API::HTTP_PUT |
| 102 | + path = "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_custom_inference_id)}" |
| 103 | + params = Utils.process_params(arguments) |
| 104 | + |
| 105 | + Elasticsearch::API::Response.new( |
| 106 | + perform_request(method, path, params, body, headers, request_opts) |
| 107 | + ) |
| 108 | + end |
| 109 | + end |
| 110 | + end |
| 111 | + end |
| 112 | +end |
0 commit comments