Skip to content

Commit

Permalink
[8.x] [ML] Switching from _unified to _stream for the chat_completion…
Browse files Browse the repository at this point in the history
… task type (elastic#210104) (elastic#210111)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML] Switching from _unified to _stream for the chat_completion task
type (elastic#210104)](elastic#210104)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jonathan
Buttner","email":"56361221+jonathan-buttner@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-06T21:40:47Z","message":"[ML]
Switching from _unified to _stream for the chat_completion task type
(elastic#210104)\n\nThis PR switch the endpoint used for the `chat_completion`
task type to\r\n`_stream`. Only the URL changes, the request and
response format stay\r\nthe same. The `_stream` URL was introduced a
couple verisons ago and is\r\nthe preferred route for interacting with
`chat_completion`.\r\n\r\n### Testing\r\n\r\nSetup a pre-configured
connector for security. Add this to
your\r\n`config/kibana.dev.yml`\r\n\r\n```\r\nxpack.actions.preconfigured:\r\n
my-inference-open-ai:\r\n name: Inference Preconfig Jon\r\n
actionTypeId: .inference\r\n exposeConfig: true\r\n config:\r\n
provider: 'openai'\r\n taskType: 'chat_completion'\r\n inferenceId:
'openai-chat_completion-123'\r\n providerConfig:\r\n rate_limit:\r\n
requests_per_minute: 80000\r\n model_id: 'gpt-4o'\r\n url:
https://api.openai.com/v1/chat/completions\r\n secrets:\r\n
providerSecrets:\r\n api_key: '<api key>'\r\n```\r\n\r\nThen via the
Connectors page, create an AI connector with the inference\r\nendpoint
id set to
`openai-chat_completion-123`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/29d56d58-cd96-432f-9d13-460446d204a1","sha":"3a14752dad189a9702be1f108b14680e7d1fe9bc","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:ML","Feature:GenAI","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[ML]
Switching from _unified to _stream for the chat_completion task
type","number":210104,"url":"https://github.com/elastic/kibana/pull/210104","mergeCommit":{"message":"[ML]
Switching from _unified to _stream for the chat_completion task type
(elastic#210104)\n\nThis PR switch the endpoint used for the `chat_completion`
task type to\r\n`_stream`. Only the URL changes, the request and
response format stay\r\nthe same. The `_stream` URL was introduced a
couple verisons ago and is\r\nthe preferred route for interacting with
`chat_completion`.\r\n\r\n### Testing\r\n\r\nSetup a pre-configured
connector for security. Add this to
your\r\n`config/kibana.dev.yml`\r\n\r\n```\r\nxpack.actions.preconfigured:\r\n
my-inference-open-ai:\r\n name: Inference Preconfig Jon\r\n
actionTypeId: .inference\r\n exposeConfig: true\r\n config:\r\n
provider: 'openai'\r\n taskType: 'chat_completion'\r\n inferenceId:
'openai-chat_completion-123'\r\n providerConfig:\r\n rate_limit:\r\n
requests_per_minute: 80000\r\n model_id: 'gpt-4o'\r\n url:
https://api.openai.com/v1/chat/completions\r\n secrets:\r\n
providerSecrets:\r\n api_key: '<api key>'\r\n```\r\n\r\nThen via the
Connectors page, create an AI connector with the inference\r\nendpoint
id set to
`openai-chat_completion-123`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/29d56d58-cd96-432f-9d13-460446d204a1","sha":"3a14752dad189a9702be1f108b14680e7d1fe9bc"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210104","number":210104,"mergeCommit":{"message":"[ML]
Switching from _unified to _stream for the chat_completion task type
(elastic#210104)\n\nThis PR switch the endpoint used for the `chat_completion`
task type to\r\n`_stream`. Only the URL changes, the request and
response format stay\r\nthe same. The `_stream` URL was introduced a
couple verisons ago and is\r\nthe preferred route for interacting with
`chat_completion`.\r\n\r\n### Testing\r\n\r\nSetup a pre-configured
connector for security. Add this to
your\r\n`config/kibana.dev.yml`\r\n\r\n```\r\nxpack.actions.preconfigured:\r\n
my-inference-open-ai:\r\n name: Inference Preconfig Jon\r\n
actionTypeId: .inference\r\n exposeConfig: true\r\n config:\r\n
provider: 'openai'\r\n taskType: 'chat_completion'\r\n inferenceId:
'openai-chat_completion-123'\r\n providerConfig:\r\n rate_limit:\r\n
requests_per_minute: 80000\r\n model_id: 'gpt-4o'\r\n url:
https://api.openai.com/v1/chat/completions\r\n secrets:\r\n
providerSecrets:\r\n api_key: '<api key>'\r\n```\r\n\r\nThen via the
Connectors page, create an AI connector with the inference\r\nendpoint
id set to
`openai-chat_completion-123`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/29d56d58-cd96-432f-9d13-460446d204a1","sha":"3a14752dad189a9702be1f108b14680e7d1fe9bc"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com>
  • Loading branch information
kibanamachine and jonathan-buttner authored Feb 6, 2025
1 parent 336b2fe commit ce88180
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('InferenceConnector', () => {
n: undefined,
},
method: 'POST',
path: '_inference/chat_completion/test/_unified',
path: '_inference/chat_completion/test/_stream',
},
{ asStream: true, meta: true }
);
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('InferenceConnector', () => {
n: undefined,
},
method: 'POST',
path: '_inference/chat_completion/test/_unified',
path: '_inference/chat_completion/test/_stream',
},
{ asStream: true, meta: true }
);
Expand All @@ -310,7 +310,7 @@ describe('InferenceConnector', () => {
{
body: { messages: [{ content: 'Hello world', role: 'user' }], n: undefined },
method: 'POST',
path: '_inference/chat_completion/test/_unified',
path: '_inference/chat_completion/test/_stream',
},
{ asStream: true, meta: true, signal }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class InferenceConnector extends SubActionConnector<Config, Secrets> {
const response = await this.esClient.transport.request<UnifiedChatCompleteResponse>(
{
method: 'POST',
path: `_inference/chat_completion/${this.inferenceId}/_unified`,
path: `_inference/chat_completion/${this.inferenceId}/_stream`,
body: { ...params.body, n: undefined }, // exclude n param for now, constant is used on the inference API side
},
{
Expand Down

0 comments on commit ce88180

Please sign in to comment.