From aabe6f77bf4d2c7aa25978e9cce7357e629e6397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Fri, 7 Jun 2024 14:31:15 +0200 Subject: [PATCH] improve types --- .../server/functions/context.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/server/functions/context.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/server/functions/context.ts index 46de19198e7f2..05bbdd6ac57c6 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/server/functions/context.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/server/functions/context.ts @@ -70,8 +70,10 @@ export function registerContextFunction({ messages.filter((message) => message.message.role === MessageRole.User) ); - const userPrompt = userMessage?.message.content!; - const queries = compact([{ text: userPrompt, boost: 3 }, { text: screenDescription }]); + const userPrompt = userMessage?.message.content; + const queries = [{ text: userPrompt, boost: 3 }, { text: screenDescription }].filter( + ({ text }) => text + ) as Array<{ text: string; boost?: number }>; const suggestions = await retrieveSuggestions({ client, queries }); if (suggestions.length === 0) { @@ -90,7 +92,7 @@ export function registerContextFunction({ }); analytics.reportEvent(RecallRankingEventType, { - prompt: `${screenDescription} | ${userPrompt}`, + prompt: queries.map((query) => query.text).join('|'), scoredDocuments: suggestions.map((suggestion) => { const llmScore = scores.find((score) => score.id === suggestion.id); return {