Skip to content

Commit c5dd4e9

Browse files
Auto-generated API code (#2735)
1 parent c9666e1 commit c5dd4e9

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

docs/reference.asciidoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8038,6 +8038,42 @@ client.inference.get({ ... })
80388038
** *`task_type` (Optional, Enum("sparse_embedding" | "text_embedding" | "rerank" | "completion" | "chat_completion"))*: The task type
80398039
** *`inference_id` (Optional, string)*: The inference Id
80408040

8041+
[discrete]
8042+
==== inference
8043+
Perform inference on the service.
8044+
8045+
This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
8046+
It returns a response with the results of the tasks.
8047+
The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API.
8048+
8049+
For details about using this API with a service, such as Amazon Bedrock, Anthropic, or HuggingFace, refer to the service-specific documentation.
8050+
8051+
> info
8052+
> 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.
8053+
8054+
{ref}/post-inference-api.html[Endpoint documentation]
8055+
[source,ts]
8056+
----
8057+
client.inference.inference({ inference_id, input })
8058+
----
8059+
8060+
[discrete]
8061+
==== Arguments
8062+
8063+
* *Request (object):*
8064+
** *`inference_id` (string)*: The unique identifier for the inference endpoint.
8065+
** *`input` (string | string[])*: The text on which you want to perform the inference task.
8066+
It can be a single string or an array.
8067+
8068+
> info
8069+
> Inference endpoints for the `completion` task type currently only support a single string as input.
8070+
** *`task_type` (Optional, Enum("sparse_embedding" | "text_embedding" | "rerank" | "completion" | "chat_completion"))*: The type of inference task that the model performs.
8071+
** *`query` (Optional, string)*: The query input, which is required only for the `rerank` task.
8072+
It is not required for other tasks.
8073+
** *`task_settings` (Optional, User-defined value)*: Task settings for the individual inference request.
8074+
These settings are specific to the task type you specified and override the task settings specified when initializing the service.
8075+
** *`timeout` (Optional, string | -1 | 0)*: The amount of time to wait for the inference request to complete.
8076+
80418077
[discrete]
80428078
==== put
80438079
Create an inference endpoint.

src/api/api/inference.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,58 @@ export default class Inference {
209209
return await this.transport.request({ path, method, querystring, body, meta }, options)
210210
}
211211

212+
/**
213+
* Perform inference on the service. This API enables you to use machine learning models to perform specific tasks on data that you provide as an input. It returns a response with the results of the tasks. The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API. For details about using this API with a service, such as Amazon Bedrock, Anthropic, or HuggingFace, refer to the service-specific documentation. > info > 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.
214+
* @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/8.18/post-inference-api.html | Elasticsearch API documentation}
215+
*/
216+
async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.InferenceInferenceResponse>
217+
async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceInferenceResponse, unknown>>
218+
async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<T.InferenceInferenceResponse>
219+
async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<any> {
220+
const acceptedPath: string[] = ['task_type', 'inference_id']
221+
const acceptedBody: string[] = ['query', 'input', 'task_settings']
222+
const querystring: Record<string, any> = {}
223+
// @ts-expect-error
224+
const userBody: any = params?.body
225+
let body: Record<string, any> | string
226+
if (typeof userBody === 'string') {
227+
body = userBody
228+
} else {
229+
body = userBody != null ? { ...userBody } : undefined
230+
}
231+
232+
for (const key in params) {
233+
if (acceptedBody.includes(key)) {
234+
body = body ?? {}
235+
// @ts-expect-error
236+
body[key] = params[key]
237+
} else if (acceptedPath.includes(key)) {
238+
continue
239+
} else if (key !== 'body') {
240+
// @ts-expect-error
241+
querystring[key] = params[key]
242+
}
243+
}
244+
245+
let method = ''
246+
let path = ''
247+
if (params.task_type != null && params.inference_id != null) {
248+
method = 'POST'
249+
path = `/_inference/${encodeURIComponent(params.task_type.toString())}/${encodeURIComponent(params.inference_id.toString())}`
250+
} else {
251+
method = 'POST'
252+
path = `/_inference/${encodeURIComponent(params.inference_id.toString())}`
253+
}
254+
const meta: TransportRequestMetadata = {
255+
name: 'inference.inference',
256+
pathParts: {
257+
task_type: params.task_type,
258+
inference_id: params.inference_id
259+
}
260+
}
261+
return await this.transport.request({ path, method, querystring, body, meta }, options)
262+
}
263+
212264
/**
213265
* Create an inference endpoint. When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running. After creating the endpoint, wait for the model deployment to complete before using it. To verify the deployment status, use the get trained model statistics API. Look for `"state": "fully_allocated"` in the response and ensure that the `"allocation_count"` matches the `"target_allocation_count"`. Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources. 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, Mistral, Azure OpenAI, 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.
214266
* @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/8.18/put-inference-api.html | Elasticsearch API documentation}

src/api/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13099,6 +13099,15 @@ export interface InferenceInferenceEndpointInfo extends InferenceInferenceEndpoi
1309913099
task_type: InferenceTaskType
1310013100
}
1310113101

13102+
export interface InferenceInferenceResult {
13103+
text_embedding_bytes?: InferenceTextEmbeddingByteResult[]
13104+
text_embedding_bits?: InferenceTextEmbeddingByteResult[]
13105+
text_embedding?: InferenceTextEmbeddingResult[]
13106+
sparse_embedding?: InferenceSparseEmbeddingResult[]
13107+
completion?: InferenceCompletionResult[]
13108+
rerank?: InferenceRankedDocument[]
13109+
}
13110+
1310213111
export interface InferenceJinaAIServiceSettings {
1310313112
api_key: string
1310413113
model_id?: string
@@ -13288,6 +13297,17 @@ export interface InferenceGetResponse {
1328813297
endpoints: InferenceInferenceEndpointInfo[]
1328913298
}
1329013299

13300+
export interface InferenceInferenceRequest extends RequestBase {
13301+
task_type?: InferenceTaskType
13302+
inference_id: Id
13303+
timeout?: Duration
13304+
query?: string
13305+
input: string | string[]
13306+
task_settings?: InferenceTaskSettings
13307+
}
13308+
13309+
export type InferenceInferenceResponse = InferenceInferenceResult
13310+
1329113311
export interface InferencePutRequest extends RequestBase {
1329213312
task_type?: InferenceTaskType
1329313313
inference_id: Id

src/api/typesWithBodyKey.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13341,6 +13341,15 @@ export interface InferenceInferenceEndpointInfo extends InferenceInferenceEndpoi
1334113341
task_type: InferenceTaskType
1334213342
}
1334313343

13344+
export interface InferenceInferenceResult {
13345+
text_embedding_bytes?: InferenceTextEmbeddingByteResult[]
13346+
text_embedding_bits?: InferenceTextEmbeddingByteResult[]
13347+
text_embedding?: InferenceTextEmbeddingResult[]
13348+
sparse_embedding?: InferenceSparseEmbeddingResult[]
13349+
completion?: InferenceCompletionResult[]
13350+
rerank?: InferenceRankedDocument[]
13351+
}
13352+
1334413353
export interface InferenceJinaAIServiceSettings {
1334513354
api_key: string
1334613355
model_id?: string
@@ -13534,6 +13543,20 @@ export interface InferenceGetResponse {
1353413543
endpoints: InferenceInferenceEndpointInfo[]
1353513544
}
1353613545

13546+
export interface InferenceInferenceRequest extends RequestBase {
13547+
task_type?: InferenceTaskType
13548+
inference_id: Id
13549+
timeout?: Duration
13550+
/** @deprecated The use of the 'body' key has been deprecated, move the nested keys to the top level object. */
13551+
body?: {
13552+
query?: string
13553+
input: string | string[]
13554+
task_settings?: InferenceTaskSettings
13555+
}
13556+
}
13557+
13558+
export type InferenceInferenceResponse = InferenceInferenceResult
13559+
1353713560
export interface InferencePutRequest extends RequestBase {
1353813561
task_type?: InferenceTaskType
1353913562
inference_id: Id

0 commit comments

Comments
 (0)