-
Notifications
You must be signed in to change notification settings - Fork 105
Adds custom inference service API docs #4852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
65cb119
ac77396
389ce57
a9a560e
3c4eb3f
3d90b42
bc66328
1b3fe33
fab50c4
e185149
859713d
8051083
61c6a98
e0963ae
bd8ec2b
d568234
b4c99e6
9dfe0ef
3961f12
a0baab6
d63c4d7
294a143
52c19aa
f45f46f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"inference.put_custom": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put-custom", | ||
"description": "Configure a custom inference endpoint" | ||
}, | ||
"stability": "stable", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": ["application/json"], | ||
"content_type": ["application/json"] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_inference/{task_type}/{custom_inference_id}", | ||
"methods": ["PUT"], | ||
"parts": { | ||
"task_type": { | ||
"type": "string", | ||
"description": "The task type" | ||
}, | ||
"custom_inference_id": { | ||
"type": "string", | ||
"description": "The inference Id" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"body": { | ||
"description": "The inference endpoint's task and service settings" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -756,6 +756,256 @@ export class CohereTaskSettings { | |
truncate?: CohereTruncateType | ||
} | ||
|
||
export class CustomServiceSettings { | ||
/** | ||
* Specifies the HTTPS header parameters – such as `Authentication` or `Contet-Type` – that are required to access the custom service. | ||
* For example: | ||
* ``` | ||
* "headers":{ | ||
* "Authorization": "Bearer ${api_key}", | ||
* "Content-Type": "application/json;charset=utf-8" | ||
* } | ||
* ``` | ||
*/ | ||
headers?: UserDefinedValue | ||
/** | ||
* Specifies the input type translation values that are used to replace the `${input_type}` template in the request body. | ||
* For example: | ||
* ``` | ||
* "input_type": { | ||
* "translation": { | ||
* "ingest": "do_ingest", | ||
* "search": "do_search" | ||
* }, | ||
* "default": "a_default" | ||
* }, | ||
* ``` | ||
* If the subsequent inference requests come from a search context, the `search` key will be used and the template will be replaced with `do_search`. | ||
* If it comes from the ingest context `do_ingest` is used. If it's a different context that is not specified, the default value will be used. If no default is specified an empty string is used. | ||
* `translation` can be: | ||
* * `classification` | ||
* * `clustering` | ||
* * `ingest` | ||
* * `search` | ||
*/ | ||
input_type?: UserDefinedValue | ||
/** | ||
* Specifies the query parameters as a list of tuples. The arrays inside the `query_parameters` must have two items, a key and a value. | ||
* For example: | ||
* ``` | ||
szabosteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* "query_parameters":[ | ||
* ["param_key", "some_value"], | ||
* ["param_key", "another_value"], | ||
* ["other_key", "other_value"] | ||
* ] | ||
* ``` | ||
* If the base url is `https://www.elastic.co` it results in: `https://www.elastic.co?param_key=some_value¶m_key=another_value&other_key=other_value`. | ||
*/ | ||
query_parameters?: UserDefinedValue | ||
/** | ||
* The request configuration object. | ||
*/ | ||
request: CustomRequestParams | ||
/** | ||
* The response configuration object. | ||
*/ | ||
response: CustomResponseParams | ||
/** | ||
* Specifies secret parameters, like `api_key` or `api_token`, that are required to access the custom service. | ||
* For example: | ||
* ``` | ||
* "secret_parameters":{ | ||
* "api_key":"<api_key>" | ||
* } | ||
* ``` | ||
*/ | ||
secret_parameters: UserDefinedValue | ||
/** | ||
* The URL endpoint to use for the requests. | ||
*/ | ||
url?: string | ||
} | ||
szabosteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export class CustomRequestParams { | ||
/** | ||
* The body structure of the request. It requires passing in the string-escaped result of the JSON format HTTP request body. | ||
* For example: | ||
* ``` | ||
* "request": "{\"input\":${input}}" | ||
* ``` | ||
* > info | ||
* > The content string needs to be a single line except when using the Kibana console. | ||
*/ | ||
content: string | ||
} | ||
|
||
export class CustomResponseParams { | ||
/** | ||
* Specifies the JSON parser that is used to parse the response from the custom service. | ||
* Different task types require different json_parser parameters. | ||
* For example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonathan-buttner Do you think we should specify a JsonParser class for each task type, or is this list sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I think it might be better if we give an example of the response structure for each task type and explain how to create the parser from that. We should also say that the format is a less featured version of JSONPath: https://en.wikipedia.org/wiki/JSONPath Here are some examples: Text EmbeddingsFor a response that looks like:
We'd need this definition:
RerankFor a response that looks like:
We'd need this definition:
CompletionFor a response that looks like:
We'd need this definition:
Sparse embeddingFor a response that looks like:
We'd need this definition:
If the |
||
* ``` | ||
* # text_embedding | ||
* # For a response like this: | ||
* | ||
* { | ||
* "object": "list", | ||
* "data": [ | ||
* { | ||
* "object": "embedding", | ||
* "index": 0, | ||
* "embedding": [ | ||
* 0.014539449, | ||
* -0.015288644 | ||
* ] | ||
* } | ||
* ], | ||
* "model": "text-embedding-ada-002-v2", | ||
* "usage": { | ||
* "prompt_tokens": 8, | ||
* "total_tokens": 8 | ||
* } | ||
* } | ||
* | ||
* # the json_parser definition should look like this: | ||
* | ||
* "response":{ | ||
* "json_parser":{ | ||
* "text_embeddings":"$.data[*].embedding[*]" | ||
* } | ||
* } | ||
* | ||
* # sparse_embedding | ||
* # For a response like this: | ||
* | ||
* { | ||
* "request_id": "75C50B5B-E79E-4930-****-F48DBB392231", | ||
* "latency": 22, | ||
* "usage": { | ||
* "token_count": 11 | ||
* }, | ||
* "result": { | ||
* "sparse_embeddings": [ | ||
* { | ||
* "index": 0, | ||
* "embedding": [ | ||
* { | ||
* "token_id": 6, | ||
* "weight": 0.101 | ||
* }, | ||
* { | ||
* "token_id": 163040, | ||
* "weight": 0.28417 | ||
* } | ||
* ] | ||
* } | ||
* ] | ||
* } | ||
* } | ||
* | ||
* # the json_parser definition should look like this: | ||
* | ||
* "response":{ | ||
* "json_parser":{ | ||
* "token_path":"$.result.sparse_embeddings[*].embedding[*].token_id", | ||
* "weight_path":"$.result.sparse_embeddings[*].embedding[*].weight" | ||
* } | ||
* } | ||
* | ||
* # rerank | ||
* # For a response like this: | ||
* | ||
* { | ||
* "results": [ | ||
* { | ||
* "index": 3, | ||
* "relevance_score": 0.999071, | ||
* "document": "abc" | ||
* }, | ||
* { | ||
* "index": 4, | ||
* "relevance_score": 0.7867867, | ||
* "document": "123" | ||
* }, | ||
* { | ||
* "index": 0, | ||
* "relevance_score": 0.32713068, | ||
* "document": "super" | ||
* } | ||
* ], | ||
* } | ||
* | ||
* # the json_parser definition should look like this: | ||
* | ||
* "response":{ | ||
* "json_parser":{ | ||
* "reranked_index":"$.result.scores[*].index", // optional | ||
* "relevance_score":"$.result.scores[*].score", | ||
* "document_text":"xxx" // optional | ||
* } | ||
* } | ||
* | ||
* # completion | ||
* # For a response like this: | ||
* | ||
* { | ||
* "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT", | ||
* "object": "chat.completion", | ||
* "created": 1741569952, | ||
* "model": "gpt-4.1-2025-04-14", | ||
* "choices": [ | ||
* { | ||
* "index": 0, | ||
* "message": { | ||
* "role": "assistant", | ||
* "content": "Hello! How can I assist you today?", | ||
* "refusal": null, | ||
* "annotations": [] | ||
* }, | ||
* "logprobs": null, | ||
* "finish_reason": "stop" | ||
* } | ||
* ] | ||
* } | ||
* | ||
* # the json_parser definition should look like this: | ||
* | ||
* "response":{ | ||
* "json_parser":{ | ||
* "completion_result":"$.choices[*].message.content" | ||
* } | ||
* } | ||
*/ | ||
json_parser: UserDefinedValue | ||
} | ||
|
||
export enum CustomTaskType { | ||
text_embedding, | ||
sparse_embedding, | ||
rerank, | ||
completion | ||
} | ||
|
||
export enum CustomServiceType { | ||
custom | ||
szabosteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export class CustomTaskSettings { | ||
/** | ||
* Specifies parameters that are required to run the custom service. The parameters depend on the model your custom service uses. | ||
* For example: | ||
* ``` | ||
* "task_settings":{ | ||
* "parameters":{ | ||
* "input_type":"query", | ||
* "return_token":true | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
parameters?: UserDefinedValue | ||
} | ||
|
||
export class EisServiceSettings { | ||
/** | ||
* The name of the model to use for the inference task. | ||
|
Uh oh!
There was an error while loading. Please reload this page.