Skip to content
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

[8.x] [Obs AI Assistant] Fix null pointer in function definition (#203344) #203436

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading