|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +/* eslint-disable import/export */ |
| 21 | +/* eslint-disable @typescript-eslint/no-misused-new */ |
| 22 | +/* eslint-disable @typescript-eslint/no-extraneous-class */ |
| 23 | +/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 24 | + |
| 25 | +// This file was automatically generated by elastic/elastic-client-generator-js |
| 26 | +// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file, |
| 27 | +// and elastic/elastic-client-generator-js to regenerate this file again. |
| 28 | + |
| 29 | +import { |
| 30 | + Transport, |
| 31 | + TransportRequestOptions, |
| 32 | + TransportRequestOptionsWithMeta, |
| 33 | + TransportRequestOptionsWithOutMeta, |
| 34 | + TransportResult |
| 35 | +} from '@elastic/transport' |
| 36 | +import * as T from '../types' |
| 37 | +import * as TB from '../typesWithBodyKey' |
| 38 | +interface That { transport: Transport } |
| 39 | + |
| 40 | +export default class Inference { |
| 41 | + transport: Transport |
| 42 | + constructor (transport: Transport) { |
| 43 | + this.transport = transport |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Delete model in the Inference API |
| 48 | + * @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-inference-api.html | Elasticsearch API documentation} |
| 49 | + */ |
| 50 | + async deleteModel (this: That, params: T.InferenceDeleteModelRequest | TB.InferenceDeleteModelRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.InferenceDeleteModelResponse> |
| 51 | + async deleteModel (this: That, params: T.InferenceDeleteModelRequest | TB.InferenceDeleteModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceDeleteModelResponse, unknown>> |
| 52 | + async deleteModel (this: That, params: T.InferenceDeleteModelRequest | TB.InferenceDeleteModelRequest, options?: TransportRequestOptions): Promise<T.InferenceDeleteModelResponse> |
| 53 | + async deleteModel (this: That, params: T.InferenceDeleteModelRequest | TB.InferenceDeleteModelRequest, options?: TransportRequestOptions): Promise<any> { |
| 54 | + const acceptedPath: string[] = ['task_type', 'model_id'] |
| 55 | + const querystring: Record<string, any> = {} |
| 56 | + const body = undefined |
| 57 | + |
| 58 | + for (const key in params) { |
| 59 | + if (acceptedPath.includes(key)) { |
| 60 | + continue |
| 61 | + } else if (key !== 'body') { |
| 62 | + // @ts-expect-error |
| 63 | + querystring[key] = params[key] |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + const method = 'DELETE' |
| 68 | + const path = `/_inference/${encodeURIComponent(params.task_type.toString())}/${encodeURIComponent(params.model_id.toString())}` |
| 69 | + return await this.transport.request({ path, method, querystring, body }, options) |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Get a model in the Inference API |
| 74 | + * @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/get-inference-api.html | Elasticsearch API documentation} |
| 75 | + */ |
| 76 | + async getModel (this: That, params: T.InferenceGetModelRequest | TB.InferenceGetModelRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.InferenceGetModelResponse> |
| 77 | + async getModel (this: That, params: T.InferenceGetModelRequest | TB.InferenceGetModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceGetModelResponse, unknown>> |
| 78 | + async getModel (this: That, params: T.InferenceGetModelRequest | TB.InferenceGetModelRequest, options?: TransportRequestOptions): Promise<T.InferenceGetModelResponse> |
| 79 | + async getModel (this: That, params: T.InferenceGetModelRequest | TB.InferenceGetModelRequest, options?: TransportRequestOptions): Promise<any> { |
| 80 | + const acceptedPath: string[] = ['task_type', 'model_id'] |
| 81 | + const querystring: Record<string, any> = {} |
| 82 | + const body = undefined |
| 83 | + |
| 84 | + for (const key in params) { |
| 85 | + if (acceptedPath.includes(key)) { |
| 86 | + continue |
| 87 | + } else if (key !== 'body') { |
| 88 | + // @ts-expect-error |
| 89 | + querystring[key] = params[key] |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + const method = 'GET' |
| 94 | + const path = `/_inference/${encodeURIComponent(params.task_type.toString())}/${encodeURIComponent(params.model_id.toString())}` |
| 95 | + return await this.transport.request({ path, method, querystring, body }, options) |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Perform inference on a model |
| 100 | + * @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/post-inference-api.html | Elasticsearch API documentation} |
| 101 | + */ |
| 102 | + async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.InferenceInferenceResponse> |
| 103 | + async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceInferenceResponse, unknown>> |
| 104 | + async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<T.InferenceInferenceResponse> |
| 105 | + async inference (this: That, params: T.InferenceInferenceRequest | TB.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<any> { |
| 106 | + const acceptedPath: string[] = ['task_type', 'model_id'] |
| 107 | + const acceptedBody: string[] = ['input', 'task_settings'] |
| 108 | + const querystring: Record<string, any> = {} |
| 109 | + // @ts-expect-error |
| 110 | + const userBody: any = params?.body |
| 111 | + let body: Record<string, any> | string |
| 112 | + if (typeof userBody === 'string') { |
| 113 | + body = userBody |
| 114 | + } else { |
| 115 | + body = userBody != null ? { ...userBody } : undefined |
| 116 | + } |
| 117 | + |
| 118 | + for (const key in params) { |
| 119 | + if (acceptedBody.includes(key)) { |
| 120 | + body = body ?? {} |
| 121 | + // @ts-expect-error |
| 122 | + body[key] = params[key] |
| 123 | + } else if (acceptedPath.includes(key)) { |
| 124 | + continue |
| 125 | + } else if (key !== 'body') { |
| 126 | + // @ts-expect-error |
| 127 | + querystring[key] = params[key] |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + const method = 'POST' |
| 132 | + const path = `/_inference/${encodeURIComponent(params.task_type.toString())}/${encodeURIComponent(params.model_id.toString())}` |
| 133 | + return await this.transport.request({ path, method, querystring, body }, options) |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Configure a model for use in the Inference API |
| 138 | + * @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/put-inference-api.html | Elasticsearch API documentation} |
| 139 | + */ |
| 140 | + async putModel (this: That, params: T.InferencePutModelRequest | TB.InferencePutModelRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.InferencePutModelResponse> |
| 141 | + async putModel (this: That, params: T.InferencePutModelRequest | TB.InferencePutModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferencePutModelResponse, unknown>> |
| 142 | + async putModel (this: That, params: T.InferencePutModelRequest | TB.InferencePutModelRequest, options?: TransportRequestOptions): Promise<T.InferencePutModelResponse> |
| 143 | + async putModel (this: That, params: T.InferencePutModelRequest | TB.InferencePutModelRequest, options?: TransportRequestOptions): Promise<any> { |
| 144 | + const acceptedPath: string[] = ['task_type', 'model_id'] |
| 145 | + const acceptedBody: string[] = ['model_config'] |
| 146 | + const querystring: Record<string, any> = {} |
| 147 | + // @ts-expect-error |
| 148 | + let body: any = params.body ?? undefined |
| 149 | + |
| 150 | + for (const key in params) { |
| 151 | + if (acceptedBody.includes(key)) { |
| 152 | + // @ts-expect-error |
| 153 | + body = params[key] |
| 154 | + } else if (acceptedPath.includes(key)) { |
| 155 | + continue |
| 156 | + } else if (key !== 'body') { |
| 157 | + // @ts-expect-error |
| 158 | + querystring[key] = params[key] |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + const method = 'PUT' |
| 163 | + const path = `/_inference/${encodeURIComponent(params.task_type.toString())}/${encodeURIComponent(params.model_id.toString())}` |
| 164 | + return await this.transport.request({ path, method, querystring, body }, options) |
| 165 | + } |
| 166 | +} |
0 commit comments