Skip to content

[Inference] Inference CLI client#214691

Merged
dgieselaar merged 13 commits intoelastic:mainfrom
dgieselaar:inference-cli-client
Mar 18, 2025
Merged

[Inference] Inference CLI client#214691
dgieselaar merged 13 commits intoelastic:mainfrom
dgieselaar:inference-cli-client

Conversation

@dgieselaar
Copy link
Contributor

@dgieselaar dgieselaar commented Mar 16, 2025

Exposes an Inference (plugin) API client for scripts, that mimicks the chatComplete and output APIs that are available on its start contract. It depends on the KibanaClient that is exposed from the @kbn/kibana-api-cli package. It automatically selects a connector if available.

@dgieselaar dgieselaar added release_note:skip Skip the PR/issue when compiling release notes backport:version Backport to applied version labels v9.1.0 labels Mar 16, 2025
@dgieselaar dgieselaar marked this pull request as ready for review March 16, 2025 17:14
@dgieselaar dgieselaar requested review from a team as code owners March 16, 2025 17:14
@botelastic botelastic bot added the Team:Obs AI Assistant Observability AI Assistant label Mar 16, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@dgieselaar dgieselaar requested a review from a team March 16, 2025 18:42
* Base class for all inference API errors.
*/
export class InferenceTaskError<
const InferenceTaskError = ServerSentEventError;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgayvallet WDYT here? not very proud of this, but:

  • translating InferenceTaskError from and to ServerSentEventError everywhere is a lot of work
  • they're basically the same
  • not aliasing InferenceTaskError to ServerSentEventError is also a little weird, because essentially ServerSentEventError is an implementation detail and specific to SSE.

@elasticmachine
Copy link
Contributor

elasticmachine commented Mar 17, 2025

💔 Build Failed

Failed CI Steps

History

Comment on lines +5 to +6
that is exposed from the `@kbn/kibana-api-cli` package. It automatically selects a
connector if available. Usage:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It automatically selects a connector if available"

Is it possibly to specify a connector? Say I have connectors from OpenAI and Anthropic in kibana.dev.yml and I want to switch between them.

Copy link
Member

@sorenlouv sorenlouv Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I see it shows the connectors in a dropdown. Nice!
image

Still, I think it would be useful to allow specifying connector via cli like hello_world.ts --connector bedrock-claude

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the option is there, but I've not added it yet as a flag because I want to figure out some stuff around how to configure flags first. so it'll come later

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running the recipe a couple of times and having to navigate to the bottom-most connector every time, I'd really appreciate a --connector option

signal: new AbortController().signal,
});

const response = await inferenceClient.output({
Copy link
Member

@sorenlouv sorenlouv Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no documentation/example for the chatCompletion endpoint. Can you add that, and also a description when to use one over the other.

I assume chatComplete allows me to pass in arbitrary functions whereas output is hardcoded to a single function (structuredOutput)

Running a recipe:

```
$ yarn run ts-node x-pack/solutions/observability/packages/kbn-genai-cli/recipes/hello_world.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ts-node --transpileOnly if you want to bypass compile errors:

Suggested change
$ yarn run ts-node x-pack/solutions/observability/packages/kbn-genai-cli/recipes/hello_world.ts
$ yarn run ts-node --transpileOnly x-pack/solutions/observability/packages/kbn-genai-cli/recipes/hello_world.ts

I was getting a silly error that shouldn't prevent the script from executing (I need to use the enum I guess) but typescript stalls on compile errors:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps wrap this in a script node scripts/inference-client x-pack/solutions/observability/packages/kbn-genai-cli/recipes/hello_world.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the latter, I'm not a fan of using scripts that way tbh. I have a function defined in my zshrc that prepends the called script with the babel-register stuff, that's probably a better way to do it but I also don't want to be too prescriptive here.

const output = await inferenceClient.output({});

log.info(output);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example seems pretty short. Intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - there are more verbose examples in kbn-inference-cli

});

log.info(response);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this! Now also add one for chatComplete :D

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like an example for the chatComplete method and the ability to specify a connector via cli --connector <connector>.
Other than that it lgtm!

@dgieselaar dgieselaar merged commit 70f1880 into elastic:main Mar 18, 2025
10 checks passed
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 19, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

clintandrewhall pushed a commit to clintandrewhall/kibana that referenced this pull request Mar 20, 2025
Exposes an Inference (plugin) API client for scripts, that mimicks the
`chatComplete` and `output` APIs that are available on its start
contract. It depends on the KibanaClient that is exposed from the
`@kbn/kibana-api-cli` package. It automatically selects a connector if
available.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
Exposes an Inference (plugin) API client for scripts, that mimicks the
`chatComplete` and `output` APIs that are available on its start
contract. It depends on the KibanaClient that is exposed from the
`@kbn/kibana-api-cli` package. It automatically selects a connector if
available.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

3 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 214691 locally

@dgieselaar
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@dgieselaar dgieselaar deleted the inference-cli-client branch March 27, 2025 16:01
dgieselaar added a commit to dgieselaar/kibana that referenced this pull request Mar 27, 2025
Exposes an Inference (plugin) API client for scripts, that mimicks the
`chatComplete` and `output` APIs that are available on its start
contract. It depends on the KibanaClient that is exposed from the
`@kbn/kibana-api-cli` package. It automatically selects a connector if
available.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 70f1880)

# Conflicts:
#	.github/CODEOWNERS
dgieselaar added a commit that referenced this pull request Mar 27, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Inference] Inference CLI client
(#214691)](#214691)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Dario
Gieselaar","email":"dario.gieselaar@elastic.co"},"sourceCommit":{"committedDate":"2025-03-18T12:33:30Z","message":"[Inference]
Inference CLI client (#214691)\n\nExposes an Inference (plugin) API
client for scripts, that mimicks the\n`chatComplete` and `output` APIs
that are available on its start\ncontract. It depends on the
KibanaClient that is exposed from the\n`@kbn/kibana-api-cli` package. It
automatically selects a connector
if\navailable.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"70f1880e4fae58c6c969b5b19c9d31abf3af4c45","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","Team:Obs AI
Assistant","backport:version","v9.1.0","v8.19.0"],"title":"[Inference]
Inference CLI
client","number":214691,"url":"https://github.com/elastic/kibana/pull/214691","mergeCommit":{"message":"[Inference]
Inference CLI client (#214691)\n\nExposes an Inference (plugin) API
client for scripts, that mimicks the\n`chatComplete` and `output` APIs
that are available on its start\ncontract. It depends on the
KibanaClient that is exposed from the\n`@kbn/kibana-api-cli` package. It
automatically selects a connector
if\navailable.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"70f1880e4fae58c6c969b5b19c9d31abf3af4c45"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214691","number":214691,"mergeCommit":{"message":"[Inference]
Inference CLI client (#214691)\n\nExposes an Inference (plugin) API
client for scripts, that mimicks the\n`chatComplete` and `output` APIs
that are available on its start\ncontract. It depends on the
KibanaClient that is exposed from the\n`@kbn/kibana-api-cli` package. It
automatically selects a connector
if\navailable.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"70f1880e4fae58c6c969b5b19c9d31abf3af4c45"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 27, 2025
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Mar 31, 2025
Exposes an Inference (plugin) API client for scripts, that mimicks the
`chatComplete` and `output` APIs that are available on its start
contract. It depends on the KibanaClient that is exposed from the
`@kbn/kibana-api-cli` package. It automatically selects a connector if
available.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Obs AI Assistant Observability AI Assistant v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants