Class PutCustomRequest

java.lang.Object
co.elastic.clients.elasticsearch._types.RequestBase
co.elastic.clients.elasticsearch.inference.PutCustomRequest
All Implemented Interfaces:
JsonpSerializable

@JsonpDeserializable public class PutCustomRequest extends RequestBase implements JsonpSerializable
Create a custom inference endpoint.

The custom service gives more control over how to interact with external inference services that aren't explicitly supported through dedicated integrations. The custom service gives you the ability to define the headers, url, query parameters, request body, and secrets. 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. Templates are portions of a string that start with ${ and end with }. 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. If the definition (key) is not found for a template, an error message is returned. In case of an endpoint definition like the following:

 PUT _inference/text_embedding/test-text-embedding
 {
   "service": "custom",
   "service_settings": {
      "secret_parameters": {
           "api_key": "<some api key>"
      },
      "url": "...endpoints.huggingface.cloud/v1/embeddings",
      "headers": {
          "Authorization": "Bearer ${api_key}",
          "Content-Type": "application/json"
      },
      "request": "{\"input\": ${input}}",
      "response": {
          "json_parser": {
              "text_embeddings":"$.data[*].embedding[*]"
          }
      }
   }
 }
 
 

To replace ${api_key} the secret_parameters and task_settings are checked for a key named api_key.

info Templates should not be surrounded by quotes.

Pre-defined templates:

  • ${input} refers to the array of input strings that comes from the input field of the subsequent inference requests.
  • ${input_type} refers to the input type translation values.
  • ${query} refers to the query field used specifically for reranking tasks.
  • ${top_n} refers to the top_n field available when performing rerank requests.
  • ${return_documents} refers to the return_documents field available when performing rerank requests.
See Also:
  • Field Details

  • Method Details

    • of

    • chunkingSettings

      @Nullable public final InferenceChunkingSettings chunkingSettings()
      The chunking configuration object.

      API name: chunking_settings

    • customInferenceId

      public final String customInferenceId()
      Required - The unique identifier of the inference endpoint.

      API name: custom_inference_id

    • service

      public final CustomServiceType service()
      Required - The type of service supported for the specified task type. In this case, custom.

      API name: service

    • serviceSettings

      public final CustomServiceSettings serviceSettings()
      Required - Settings used to install the inference model. These settings are specific to the custom service.

      API name: service_settings

    • taskSettings

      @Nullable public final CustomTaskSettings taskSettings()
      Settings to configure the inference task. These settings are specific to the task type you specified.

      API name: task_settings

    • taskType

      public final CustomTaskType taskType()
      Required - The type of the inference task that the model will perform.

      API name: task_type

    • serialize

      public void serialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)
      Serialize this object to JSON.
      Specified by:
      serialize in interface JsonpSerializable
    • serializeInternal

      protected void serializeInternal(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper)
    • setupPutCustomRequestDeserializer

      protected static void setupPutCustomRequestDeserializer(ObjectDeserializer<PutCustomRequest.Builder> op)