-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[DOCS] Adds stream inference API docs #115333
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dd21dc0
[DOCS] Initial docs for stream inference API.
szabosteve f23153f
[DOCS] Modifies stream docs.
szabosteve c680921
[DOCS] Gives a streaming example.
szabosteve f59f377
[DOCS] Updates section ID.
szabosteve bb3cfaf
[DOCS] Changes snippet type.
szabosteve ee36692
Update docs/reference/inference/stream-inference.asciidoc
szabosteve 7195c64
Update docs/reference/inference/stream-inference.asciidoc
szabosteve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
[role="xpack"] | ||
[[stream-inference-api]] | ||
=== Stream inference API | ||
|
||
Streams a chat completion response. | ||
|
||
IMPORTANT: The {infer} APIs enable you to use certain services, such as built-in {ml} 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 {infer} APIs offer an alternative way to use and manage trained models. | ||
However, if you do not plan to use the {infer} APIs to use these models or if you want to use non-NLP models, use the <<ml-df-trained-models-apis>>. | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-request]] | ||
==== {api-request-title} | ||
|
||
`POST /_inference/<inference_id>/_stream` | ||
|
||
`POST /_inference/<task_type>/<inference_id>/_stream` | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-prereqs]] | ||
==== {api-prereq-title} | ||
|
||
* Requires the `monitor_inference` <<privileges-list-cluster,cluster privilege>> | ||
(the built-in `inference_admin` and `inference_user` roles grant this privilege) | ||
* You must use a client that supports streaming. | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-desc]] | ||
==== {api-description-title} | ||
|
||
The stream {infer} API enables real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation. | ||
It only works with the `completion` task type. | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-path-params]] | ||
==== {api-path-parms-title} | ||
|
||
`<inference_id>`:: | ||
(Required, string) | ||
The unique identifier of the {infer} endpoint. | ||
|
||
|
||
`<task_type>`:: | ||
(Optional, string) | ||
The type of {infer} task that the model performs. | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-request-body]] | ||
==== {api-request-body-title} | ||
|
||
`input`:: | ||
(Required, string or array of strings) | ||
The text on which you want to perform the {infer} task. | ||
`input` can be a single string or an array. | ||
+ | ||
-- | ||
[NOTE] | ||
==== | ||
Inference endpoints for the `completion` task type currently only support a | ||
single string as input. | ||
==== | ||
-- | ||
|
||
|
||
[discrete] | ||
[[stream-inference-api-example]] | ||
==== {api-examples-title} | ||
|
||
The following example performs a completion on the example question with streaming. | ||
|
||
|
||
[source,console] | ||
------------------------------------------------------------ | ||
POST _inference/completion/openai-completion/_stream | ||
{ | ||
"input": "What is Elastic?" | ||
} | ||
------------------------------------------------------------ | ||
// TEST[skip:TBD] | ||
|
||
|
||
The API returns the following response: | ||
|
||
|
||
[source,txt] | ||
------------------------------------------------------------ | ||
event: message | ||
data: { | ||
"completion":[{ | ||
"delta":"Elastic" | ||
}] | ||
} | ||
event: message | ||
data: { | ||
"completion":[{ | ||
"delta":" is" | ||
}, | ||
{ | ||
"delta":" a" | ||
} | ||
] | ||
} | ||
event: message | ||
data: { | ||
"completion":[{ | ||
"delta":" software" | ||
}, | ||
{ | ||
"delta":" company" | ||
}] | ||
} | ||
(...) | ||
szabosteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
------------------------------------------------------------ | ||
// NOTCONSOLE |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.