From cf1f2c9aef10b395681418361ca455610bcf8531 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 | 10 +- output/openapi/elasticsearch-openapi.json | 210 +++++++++++++++- output/schema/schema.json | 237 +++++++++++++++++- output/schema/validation-errors.json | 6 - output/typescript/types.ts | 18 ++ specification/_doc_ids/table.csv | 2 + .../_json_spec/inference.update.json | 45 ++++ .../StreamInferenceRequest.ts | 57 +++++ .../StreamInferenceResponse.ts | 24 ++ .../StreamInferenceRequestExample1.yaml | 6 + .../update/UpdateInferenceRequest.ts | 51 ++++ .../update/UpdateInferenceResponse.ts | 24 ++ 13 files changed, 677 insertions(+), 15 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 4be0ef8ad7..2523534f1c 100644 --- a/docs/overlays/elasticsearch-openapi-overlays.yaml +++ b/docs/overlays/elasticsearch-openapi-overlays.yaml @@ -566,4 +566,12 @@ actions: examples: updateWatcherSettingsRequestExample1: $ref: "../../specification/watcher/get_settings/examples/200_response/WatcherGetSettingsResponseExample1.yaml" - +## 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" diff --git a/output/openapi/elasticsearch-openapi.json b/output/openapi/elasticsearch-openapi.json index de81fa624f..d22f229c3a 100644 --- a/output/openapi/elasticsearch-openapi.json +++ b/output/openapi/elasticsearch-openapi.json @@ -15985,6 +15985,57 @@ "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}/_unified": { "post": { "tags": [ @@ -16040,6 +16091,57 @@ "x-state": "Added in 8.18.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": [ @@ -72655,6 +72757,9 @@ "score" ] }, + "_types:StreamResult": { + "type": "object" + }, "inference.unified_inference:Message": { "type": "object", "properties": { @@ -72825,9 +72930,6 @@ "name" ] }, - "_types:StreamResult": { - "type": "object" - }, "_types:ElasticsearchVersionInfo": { "type": "object", "properties": { @@ -94188,6 +94290,16 @@ } } }, + "inference.stream_inference#200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/_types:StreamResult" + } + } + } + }, "inference.unified_inference#200": { "description": "", "content": { @@ -94198,6 +94310,16 @@ } } }, + "inference.update#200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/inference._types:InferenceEndpointInfo" + } + } + } + }, "ingest.get_geoip_database#200": { "description": "", "content": { @@ -101637,6 +101759,28 @@ }, "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.unified_inference#task_type": { "in": "path", "name": "task_type", @@ -101669,6 +101813,28 @@ }, "style": "form" }, + "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", @@ -107202,6 +107368,34 @@ }, "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.unified_inference": { "content": { "application/json": { @@ -107256,6 +107450,16 @@ } } }, + "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.json b/output/schema/schema.json index 9131e16e69..cf01801f90 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -8817,19 +8817,32 @@ { "availability": { "stack": { + "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" ], @@ -8893,6 +8906,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": { @@ -144333,6 +144393,101 @@ }, "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": "interface", "description": "A list of tools that the model can call.", @@ -144912,6 +145067,80 @@ ], "specLocation": "inference/unified_inference/UnifiedRequest.ts#L106-L118" }, + { + "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 57542f9d1b..2e2edb86de 100644 --- a/output/schema/validation-errors.json +++ b/output/schema/validation-errors.json @@ -259,12 +259,6 @@ ], "response": [] }, - "inference.stream_inference": { - "request": [ - "Missing request & response" - ], - "response": [] - }, "ingest.get_ip_location_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 f8b9a2684d..fe049c6636 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -12939,6 +12939,16 @@ 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 InferenceUnifiedInferenceCompletionTool { type: string function: InferenceUnifiedInferenceCompletionToolFunction @@ -13005,6 +13015,14 @@ export interface InferenceUnifiedInferenceToolCallFunction { name: string } +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 a6c6ad2efe..f14965b004 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/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 +}