From 5c3f5dbbcbd188898236d9f0737d56f251bbdffd Mon Sep 17 00:00:00 2001 From: Lisa Cawley Date: Wed, 15 Jan 2025 00:55:41 -0800 Subject: [PATCH] Add inference.stream_inference and inference.update (#3399) * Add inference.stream_inference * Add inference.update * Add array of strings to stream inference input * update inference response with streamresult type * fix overlay * fix wrong rebase * fix overlay wrong indent --------- Co-authored-by: Laura Trotta --- compiler/src/model/utils.ts | 2 +- .../elasticsearch-openapi-overlays.yaml | 14 +- output/openapi/elasticsearch-openapi.json | 207 ++++++++++++++ output/schema/schema-serverless.json | 15 ++ output/schema/schema.json | 254 +++++++++++++++++- output/schema/validation-errors.json | 6 - output/typescript/types.ts | 20 ++ specification/_doc_ids/table.csv | 2 + .../_json_spec/inference.update.json | 45 ++++ specification/_types/Binary.ts | 3 + .../StreamInferenceRequest.ts | 57 ++++ .../StreamInferenceResponse.ts | 24 ++ .../StreamInferenceRequestExample1.yaml | 6 + .../update/UpdateInferenceRequest.ts | 51 ++++ .../update/UpdateInferenceResponse.ts | 24 ++ 15 files changed, 717 insertions(+), 13 deletions(-) create mode 100644 specification/_json_spec/inference.update.json create mode 100644 specification/inference/stream_inference/StreamInferenceRequest.ts create mode 100644 specification/inference/stream_inference/StreamInferenceResponse.ts create mode 100644 specification/inference/stream_inference/examples/request/StreamInferenceRequestExample1.yaml create mode 100644 specification/inference/update/UpdateInferenceRequest.ts create mode 100644 specification/inference/update/UpdateInferenceResponse.ts diff --git a/compiler/src/model/utils.ts b/compiler/src/model/utils.ts index 06ddabe650..f3452accca 100644 --- a/compiler/src/model/utils.ts +++ b/compiler/src/model/utils.ts @@ -670,7 +670,7 @@ export function hoistRequestAnnotations ( 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_inference', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_search_application', 'manage_search_query_rules', 'manage_search_synonyms', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', - 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', + 'manage_watcher', 'monitor', 'monitor_inference', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_security', 'read_slm', 'transport_client' ] const values = parseCommaSeparated(value) diff --git a/docs/overlays/elasticsearch-openapi-overlays.yaml b/docs/overlays/elasticsearch-openapi-overlays.yaml index 629a2a8cb0..e3cdc1410b 100644 --- a/docs/overlays/elasticsearch-openapi-overlays.yaml +++ b/docs/overlays/elasticsearch-openapi-overlays.yaml @@ -566,4 +566,16 @@ actions: examples: updateWatcherSettingsRequestExample1: $ref: "../../specification/watcher/get_settings/examples/200_response/WatcherGetSettingsResponseExample1.yaml" - \ No newline at end of file +<<<<<<< HEAD + +======= +## Examples for inference + - target: "$.components['requestBodies']['inference.stream_inference']" + description: "Add example for inference stream request" + update: + content: + application/json: + examples: + streamInferenceRequestExample1: + $ref: "../../specification/inference/stream_inference/examples/request/StreamInferenceRequestExample1.yaml" +>>>>>>> cf1f2c9ae (Add inference.stream_inference and inference.update (#3399)) diff --git a/output/openapi/elasticsearch-openapi.json b/output/openapi/elasticsearch-openapi.json index a47b0075a3..a97326cbb1 100644 --- a/output/openapi/elasticsearch-openapi.json +++ b/output/openapi/elasticsearch-openapi.json @@ -15777,6 +15777,108 @@ "x-state": "Added in 8.11.0" } }, + "/_inference/{inference_id}/_stream": { + "post": { + "tags": [ + "inference" + ], + "summary": "Perform streaming inference", + "description": "Get real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation.\nThis API works only with the completion task type.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. 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.\n\nThis API requires the `monitor_inference` cluster privilege (the built-in `inference_admin` and `inference_user` roles grant this privilege). You must use a client that supports streaming.", + "operationId": "inference-stream-inference", + "parameters": [ + { + "$ref": "#/components/parameters/inference.stream_inference#inference_id" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/inference.stream_inference" + }, + "responses": { + "200": { + "$ref": "#/components/responses/inference.stream_inference#200" + } + }, + "x-state": "Added in 8.16.0" + } + }, + "/_inference/{task_type}/{inference_id}/_stream": { + "post": { + "tags": [ + "inference" + ], + "summary": "Perform streaming inference", + "description": "Get real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation.\nThis API works only with the completion task type.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. 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.\n\nThis API requires the `monitor_inference` cluster privilege (the built-in `inference_admin` and `inference_user` roles grant this privilege). You must use a client that supports streaming.", + "operationId": "inference-stream-inference-1", + "parameters": [ + { + "$ref": "#/components/parameters/inference.stream_inference#task_type" + }, + { + "$ref": "#/components/parameters/inference.stream_inference#inference_id" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/inference.stream_inference" + }, + "responses": { + "200": { + "$ref": "#/components/responses/inference.stream_inference#200" + } + }, + "x-state": "Added in 8.16.0" + } + }, + "/_inference/{inference_id}/_update": { + "post": { + "tags": [ + "inference" + ], + "summary": "Update an inference endpoint", + "description": "Modify `task_settings`, secrets (within `service_settings`), or `num_allocations` for an inference endpoint, depending on the specific endpoint service and `task_type`.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face.\nFor built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.\nHowever, 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.", + "operationId": "inference-update", + "parameters": [ + { + "$ref": "#/components/parameters/inference.update#inference_id" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/inference.update" + }, + "responses": { + "200": { + "$ref": "#/components/responses/inference.update#200" + } + }, + "x-state": "Added in 8.17.0" + } + }, + "/_inference/{task_type}/{inference_id}/_update": { + "post": { + "tags": [ + "inference" + ], + "summary": "Update an inference endpoint", + "description": "Modify `task_settings`, secrets (within `service_settings`), or `num_allocations` for an inference endpoint, depending on the specific endpoint service and `task_type`.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face.\nFor built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.\nHowever, 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.", + "operationId": "inference-update-1", + "parameters": [ + { + "$ref": "#/components/parameters/inference.update#task_type" + }, + { + "$ref": "#/components/parameters/inference.update#inference_id" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/inference.update" + }, + "responses": { + "200": { + "$ref": "#/components/responses/inference.update#200" + } + }, + "x-state": "Added in 8.17.0" + } + }, "/": { "get": { "tags": [ @@ -72245,6 +72347,9 @@ "score" ] }, + "_types:StreamResult": { + "type": "object" + }, "_types:ElasticsearchVersionInfo": { "type": "object", "properties": { @@ -93485,6 +93590,26 @@ } } }, + "inference.stream_inference#200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/_types:StreamResult" + } + } + } + }, + "inference.update#200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/inference._types:InferenceEndpointInfo" + } + } + } + }, "ingest.get_geoip_database#200": { "description": "", "content": { @@ -100912,6 +101037,50 @@ }, "style": "simple" }, + "inference.stream_inference#inference_id": { + "in": "path", + "name": "inference_id", + "description": "The unique identifier for the inference endpoint.", + "required": true, + "deprecated": false, + "schema": { + "$ref": "#/components/schemas/_types:Id" + }, + "style": "simple" + }, + "inference.stream_inference#task_type": { + "in": "path", + "name": "task_type", + "description": "The type of task that the model performs.", + "required": true, + "deprecated": false, + "schema": { + "$ref": "#/components/schemas/inference._types:TaskType" + }, + "style": "simple" + }, + "inference.update#inference_id": { + "in": "path", + "name": "inference_id", + "description": "The unique identifier of the inference endpoint.", + "required": true, + "deprecated": false, + "schema": { + "$ref": "#/components/schemas/_types:Id" + }, + "style": "simple" + }, + "inference.update#task_type": { + "in": "path", + "name": "task_type", + "description": "The type of inference task that the model performs.", + "required": true, + "deprecated": false, + "schema": { + "$ref": "#/components/schemas/inference._types:TaskType" + }, + "style": "simple" + }, "ingest.get_geoip_database#id": { "in": "path", "name": "id", @@ -106493,6 +106662,44 @@ }, "required": true }, + "inference.stream_inference": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "input": { + "description": "The text on which you want to perform the inference task.\nIt can be a single string or an array.\n\nNOTE: Inference endpoints for the completion task type currently only support a single string as input.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "input" + ] + } + } + } + }, + "inference.update": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/inference._types:InferenceEndpoint" + } + } + }, + "required": true + }, "ingest.simulate": { "content": { "application/json": { diff --git a/output/schema/schema-serverless.json b/output/schema/schema-serverless.json index e9fb616987..f8d98da933 100644 --- a/output/schema/schema-serverless.json +++ b/output/schema/schema-serverless.json @@ -78047,6 +78047,21 @@ }, "specLocation": "_types/common.ts#L372-L380" }, + { + "kind": "type_alias", + "name": { + "name": "StreamResult", + "namespace": "_types" + }, + "specLocation": "_types/Binary.ts#L27-L27", + "type": { + "kind": "instance_of", + "type": { + "name": "binary", + "namespace": "_builtins" + } + } + }, { "kind": "type_alias", "name": { diff --git a/output/schema/schema.json b/output/schema/schema.json index c367af4dbb..107dec7d40 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -8821,19 +8821,32 @@ { "availability": { "stack": { - "stability": "experimental", + "since": "8.16.0", + "stability": "stable", "visibility": "public" } }, - "description": "Perform streaming inference", - "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/master/post-stream-inference-api.html", + "description": "Perform streaming inference.\nGet real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation.\nThis API works only with the completion task type.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. 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.\n\nThis API requires the `monitor_inference` cluster privilege (the built-in `inference_admin` and `inference_user` roles grant this privilege). You must use a client that supports streaming.", + "docId": "inference-api-stream", + "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/stream-inference-api.html", "name": "inference.stream_inference", - "request": null, + "privileges": { + "cluster": [ + "monitor_inference" + ] + }, + "request": { + "name": "Request", + "namespace": "inference.stream_inference" + }, "requestBodyRequired": false, "requestMediaType": [ "application/json" ], - "response": null, + "response": { + "name": "Response", + "namespace": "inference.stream_inference" + }, "responseMediaType": [ "text/event-stream" ], @@ -8852,6 +8865,53 @@ } ] }, + { + "availability": { + "stack": { + "since": "8.17.0", + "stability": "stable", + "visibility": "public" + } + }, + "description": "Update an inference endpoint.\n\nModify `task_settings`, secrets (within `service_settings`), or `num_allocations` for an inference endpoint, depending on the specific endpoint service and `task_type`.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face.\nFor built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.\nHowever, 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.", + "docId": "inference-api-update", + "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/update-inference-api.html", + "name": "inference.update", + "privileges": { + "cluster": [ + "manage_inference" + ] + }, + "request": { + "name": "Request", + "namespace": "inference.update" + }, + "requestBodyRequired": true, + "requestMediaType": [ + "application/json" + ], + "response": { + "name": "Response", + "namespace": "inference.update" + }, + "responseMediaType": [ + "application/json" + ], + "urls": [ + { + "methods": [ + "POST" + ], + "path": "/_inference/{inference_id}/_update" + }, + { + "methods": [ + "POST" + ], + "path": "/_inference/{task_type}/{inference_id}/_update" + } + ] + }, { "availability": { "serverless": { @@ -51062,6 +51122,21 @@ ], "specLocation": "_types/Scripting.ts#L47-L57" }, + { + "kind": "type_alias", + "name": { + "name": "StreamResult", + "namespace": "_types" + }, + "specLocation": "_types/Binary.ts#L27-L27", + "type": { + "kind": "instance_of", + "type": { + "name": "binary", + "namespace": "_builtins" + } + } + }, { "kind": "enum", "members": [ @@ -143545,6 +143620,175 @@ }, "specLocation": "inference/put/PutResponse.ts#L22-L24" }, + { + "kind": "request", + "attachedBehaviors": [ + "CommonQueryParameters" + ], + "body": { + "kind": "properties", + "properties": [ + { + "description": "The text on which you want to perform the inference task.\nIt can be a single string or an array.\n\nNOTE: Inference endpoints for the completion task type currently only support a single string as input.", + "name": "input", + "required": true, + "type": { + "kind": "union_of", + "items": [ + { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + }, + { + "kind": "array_of", + "value": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + } + ] + } + } + ] + }, + "description": "Perform streaming inference.\nGet real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation.\nThis API works only with the completion task type.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. 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.\n\nThis API requires the `monitor_inference` cluster privilege (the built-in `inference_admin` and `inference_user` roles grant this privilege). You must use a client that supports streaming.", + "inherits": { + "type": { + "name": "RequestBase", + "namespace": "_types" + } + }, + "name": { + "name": "Request", + "namespace": "inference.stream_inference" + }, + "path": [ + { + "description": "The unique identifier for the inference endpoint.", + "name": "inference_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + }, + { + "description": "The type of task that the model performs.", + "name": "task_type", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "TaskType", + "namespace": "inference._types" + } + } + } + ], + "query": [], + "specLocation": "inference/stream_inference/StreamInferenceRequest.ts#L24-L57" + }, + { + "kind": "response", + "body": { + "kind": "value", + "value": { + "kind": "instance_of", + "type": { + "name": "StreamResult", + "namespace": "_types" + } + } + }, + "name": { + "name": "Response", + "namespace": "inference.stream_inference" + }, + "specLocation": "inference/stream_inference/StreamInferenceResponse.ts#L22-L24" + }, + { + "kind": "request", + "attachedBehaviors": [ + "CommonQueryParameters" + ], + "body": { + "kind": "value", + "codegenName": "inference_config", + "value": { + "kind": "instance_of", + "type": { + "name": "InferenceEndpoint", + "namespace": "inference._types" + } + } + }, + "description": "Update an inference endpoint.\n\nModify `task_settings`, secrets (within `service_settings`), or `num_allocations` for an inference endpoint, depending on the specific endpoint service and `task_type`.\n\nIMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face.\nFor built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.\nHowever, 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.", + "inherits": { + "type": { + "name": "RequestBase", + "namespace": "_types" + } + }, + "name": { + "name": "Request", + "namespace": "inference.update" + }, + "path": [ + { + "description": "The unique identifier of the inference endpoint.", + "name": "inference_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + }, + { + "description": "The type of inference task that the model performs.", + "name": "task_type", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "TaskType", + "namespace": "inference._types" + } + } + } + ], + "query": [], + "specLocation": "inference/update/UpdateInferenceRequest.ts#L25-L51" + }, + { + "kind": "response", + "body": { + "kind": "value", + "value": { + "kind": "instance_of", + "type": { + "name": "InferenceEndpointInfo", + "namespace": "inference._types" + } + } + }, + "name": { + "name": "Response", + "namespace": "inference.update" + }, + "specLocation": "inference/update/UpdateInferenceResponse.ts#L22-L24" + }, { "kind": "interface", "inherits": { diff --git a/output/schema/validation-errors.json b/output/schema/validation-errors.json index 029b140996..4ced1c91b0 100644 --- a/output/schema/validation-errors.json +++ b/output/schema/validation-errors.json @@ -699,12 +699,6 @@ ], "response": [] }, - "inference.stream_inference": { - "request": [ - "Missing request & response" - ], - "response": [] - }, "ingest.get_geoip_database": { "request": [ "Request: query parameter 'master_timeout' does not exist in the json spec" diff --git a/output/typescript/types.ts b/output/typescript/types.ts index 8dcba44bb3..f0133c0aee 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -2898,6 +2898,8 @@ export interface StoredScript { source: string } +export type StreamResult = ArrayBuffer + export type SuggestMode = 'missing' | 'popular' | 'always' export type SuggestionName = string @@ -12893,6 +12895,24 @@ export interface InferencePutRequest extends RequestBase { export type InferencePutResponse = InferenceInferenceEndpointInfo +export interface InferenceStreamInferenceRequest extends RequestBase { + inference_id: Id + task_type?: InferenceTaskType + body?: { + input: string | string[] + } +} + +export type InferenceStreamInferenceResponse = StreamResult + +export interface InferenceUpdateRequest extends RequestBase { + inference_id: Id + task_type?: InferenceTaskType + body?: InferenceInferenceEndpoint +} + +export type InferenceUpdateResponse = InferenceInferenceEndpointInfo + export interface IngestAppendProcessor extends IngestProcessorBase { field: Field value: any | any[] diff --git a/specification/_doc_ids/table.csv b/specification/_doc_ids/table.csv index aeaac31eb3..85b01c2b8c 100644 --- a/specification/_doc_ids/table.csv +++ b/specification/_doc_ids/table.csv @@ -271,6 +271,8 @@ indices-template-exists-v1,https://www.elastic.co/guide/en/elasticsearch/referen indices-templates,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/indices-templates.html indices-update-settings,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/indices-update-settings.html infer-trained-model-deployment,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/infer-trained-model-deployment.html +inference-api-stream,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/stream-inference-api.html +inference-api-update,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/update-inference-api.html inference-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/inference-processor.html info-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/info-api.html ingest,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/ingest.html diff --git a/specification/_json_spec/inference.update.json b/specification/_json_spec/inference.update.json new file mode 100644 index 0000000000..6c458ce080 --- /dev/null +++ b/specification/_json_spec/inference.update.json @@ -0,0 +1,45 @@ +{ + "inference.update": { + "documentation": { + "url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/update-inference-api.html", + "description": "Update inference" + }, + "stability": "stable", + "visibility": "public", + "headers": { + "accept": ["application/json"], + "content_type": ["application/json"] + }, + "url": { + "paths": [ + { + "path": "/_inference/{inference_id}/_update", + "methods": ["POST"], + "parts": { + "inference_id": { + "type": "string", + "description": "The inference Id" + } + } + }, + { + "path": "/_inference/{task_type}/{inference_id}/_update", + "methods": ["POST"], + "parts": { + "task_type": { + "type": "string", + "description": "The task type" + }, + "inference_id": { + "type": "string", + "description": "The inference Id" + } + } + } + ] + }, + "body": { + "description": "The inference endpoint's task and service settings" + } + } +} diff --git a/specification/_types/Binary.ts b/specification/_types/Binary.ts index 56b792ea38..f00d8ddcd4 100644 --- a/specification/_types/Binary.ts +++ b/specification/_types/Binary.ts @@ -22,3 +22,6 @@ export type MapboxVectorTiles = ArrayBuffer // ES|QL columns export type EsqlColumns = ArrayBuffer + +// Streaming endpoints response +export type StreamResult = ArrayBuffer diff --git a/specification/inference/stream_inference/StreamInferenceRequest.ts b/specification/inference/stream_inference/StreamInferenceRequest.ts new file mode 100644 index 0000000000..92d26e5b96 --- /dev/null +++ b/specification/inference/stream_inference/StreamInferenceRequest.ts @@ -0,0 +1,57 @@ +/* + * 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. + */ + +import { TaskType } from '@inference/_types/TaskType' +import { RequestBase } from '@_types/Base' +import { Id } from '@_types/common' + +/** + * Perform streaming inference. + * Get real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation. + * This API works only with the completion task type. + * + * IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. 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. + * + * This API requires the `monitor_inference` cluster privilege (the built-in `inference_admin` and `inference_user` roles grant this privilege). You must use a client that supports streaming. + * @rest_spec_name inference.stream_inference + * @availability stack since=8.16.0 stability=stable visibility=public + * @cluster_privileges monitor_inference + * @doc_id inference-api-stream + */ +export interface Request extends RequestBase { + path_parts: { + /** + * The unique identifier for the inference endpoint. + */ + inference_id: Id + /** + * The type of task that the model performs. + */ + task_type?: TaskType + } + body: { + /** + * The text on which you want to perform the inference task. + * It can be a single string or an array. + * + * NOTE: Inference endpoints for the completion task type currently only support a single string as input. + */ + input: string | string[] + } +} diff --git a/specification/inference/stream_inference/StreamInferenceResponse.ts b/specification/inference/stream_inference/StreamInferenceResponse.ts new file mode 100644 index 0000000000..74b823bf40 --- /dev/null +++ b/specification/inference/stream_inference/StreamInferenceResponse.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +import { StreamResult } from '@_types/Binary' + +export class Response { + body: StreamResult +} diff --git a/specification/inference/stream_inference/examples/request/StreamInferenceRequestExample1.yaml b/specification/inference/stream_inference/examples/request/StreamInferenceRequestExample1.yaml new file mode 100644 index 0000000000..12a0b1cbb0 --- /dev/null +++ b/specification/inference/stream_inference/examples/request/StreamInferenceRequestExample1.yaml @@ -0,0 +1,6 @@ +summary: Perform a completion task +description: Run `POST _inference/completion/openai-completion/_stream` to perform a completion on the example question with streaming. +# method_request: "POST _inference/completion/openai-completion/_stream" +# type: "request" +value: + input: 'What is Elastic?' diff --git a/specification/inference/update/UpdateInferenceRequest.ts b/specification/inference/update/UpdateInferenceRequest.ts new file mode 100644 index 0000000000..ecaf6dbc3a --- /dev/null +++ b/specification/inference/update/UpdateInferenceRequest.ts @@ -0,0 +1,51 @@ +/* + * 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. + */ + +import { InferenceEndpoint } from '@inference/_types/Services' +import { TaskType } from '@inference/_types/TaskType' +import { RequestBase } from '@_types/Base' +import { Id } from '@_types/common' + +/** + * Update an inference endpoint. + * + * Modify `task_settings`, secrets (within `service_settings`), or `num_allocations` for an inference endpoint, depending on the specific endpoint service and `task_type`. + * + * IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. + * For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. + * 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. + * @rest_spec_name inference.update + * @availability stack since=8.17.0 stability=stable visibility=public + * @cluster_privileges manage_inference + * @doc_id inference-api-update + */ +export interface Request extends RequestBase { + path_parts: { + /** + * The unique identifier of the inference endpoint. + */ + inference_id: Id + /** + * The type of inference task that the model performs. + */ + task_type?: TaskType + } + /** @codegen_name inference_config */ + body: InferenceEndpoint +} diff --git a/specification/inference/update/UpdateInferenceResponse.ts b/specification/inference/update/UpdateInferenceResponse.ts new file mode 100644 index 0000000000..d40639b031 --- /dev/null +++ b/specification/inference/update/UpdateInferenceResponse.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +import { InferenceEndpointInfo } from '@inference/_types/Services' + +export class Response { + body: InferenceEndpointInfo +}