Skip to content

Commit

Permalink
[8.17] [Obs AI Assistant] Fix null pointer in function definition (#2…
Browse files Browse the repository at this point in the history
…03344) (#203435)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Obs AI Assistant] Fix null pointer in function definition
(#203344)](#203344)

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

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-09T14:00:05Z","message":"[Obs
AI Assistant] Fix null pointer in function definition
(#203344)\n\nCloses
#201713","sha":"1d9ca1ebf66f4cb8a367de8a8854d40dd4789ec8","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","backport:prev-minor","Team:Obs
AI
Assistant","ci:project-deploy-observability","v8.16.0","v8.17.0"],"title":"[Obs
AI Assistant] Fix null pointer in function
definition","number":203344,"url":"https://github.com/elastic/kibana/pull/203344","mergeCommit":{"message":"[Obs
AI Assistant] Fix null pointer in function definition
(#203344)\n\nCloses
#201713","sha":"1d9ca1ebf66f4cb8a367de8a8854d40dd4789ec8"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203344","number":203344,"mergeCommit":{"message":"[Obs
AI Assistant] Fix null pointer in function definition
(#203344)\n\nCloses
#201713","sha":"1d9ca1ebf66f4cb8a367de8a8854d40dd4789ec8"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Søren Louv-Jansen <[email protected]>
  • Loading branch information
kibanamachine and sorenlouv authored Dec 9, 2024
1 parent 1c3f161 commit b746cb4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useJsonEditorModel = ({

const initialJsonString = initialJsonValue
? JSON.stringify(safeJsonParse(initialJsonValue), null, 4) // prettify the json
: functionDefinition.parameters.properties
: functionDefinition.parameters?.properties
? JSON.stringify(createInitializedObject(functionDefinition.parameters), null, 4)
: '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { FunctionDefinition } from '@kbn/observability-ai-assistant-plugin/common';

type Params = FunctionDefinition['parameters'];
type Params = NonNullable<FunctionDefinition['parameters']>;

export function createInitializedObject(parameters: Params) {
const emptyObject: Record<string, string | any> = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export type FunctionResponse =
}
| Observable<ChatCompletionChunkEvent | MessageAddEvent>;

export interface FunctionDefinition<TParameters extends CompatibleJSONSchema = any> {
export interface FunctionDefinition<
TParameters extends CompatibleJSONSchema = CompatibleJSONSchema
> {
name: string;
description: string;
visibility?: FunctionVisibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { isChatCompletionChunkEvent, isOutputEvent } from '@kbn/inference-common';
import { ToolDefinition, isChatCompletionChunkEvent, isOutputEvent } from '@kbn/inference-common';
import { correctCommonEsqlMistakes } from '@kbn/inference-plugin/common';
import { naturalLanguageToEsql } from '@kbn/inference-plugin/server';
import {
Expand Down Expand Up @@ -132,9 +132,10 @@ export function registerQueryFunction({
),
logger: resources.logger,
tools: Object.fromEntries(
actions
.concat(esqlFunctions)
.map((fn) => [fn.name, { description: fn.description, schema: fn.parameters }])
[...actions, ...esqlFunctions].map((fn) => [
fn.name,
{ description: fn.description, schema: fn.parameters } as ToolDefinition,
])
),
functionCalling: useSimulatedFunctionCalling ? 'simulated' : 'native',
});
Expand Down

0 comments on commit b746cb4

Please sign in to comment.