Skip to content

Commit

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

Closes elastic#201713

(cherry picked from commit 1d9ca1e)
  • Loading branch information
sorenlouv committed Dec 9, 2024
1 parent 859c567 commit 374456d
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 374456d

Please sign in to comment.