From 61e67423ff21185a75f69cfbe5a423f816184fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 27 Mar 2024 14:55:48 +0100 Subject: [PATCH] LLMApp: Skip 404 requests to know if the plugin exists (#85226) --------- Co-authored-by: Ivan Ortega --- .../features/dashboard/components/GenAI/utils.test.ts | 10 ++++++++++ .../app/features/dashboard/components/GenAI/utils.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/public/app/features/dashboard/components/GenAI/utils.test.ts b/public/app/features/dashboard/components/GenAI/utils.test.ts index 48d6dfafc08..95ffa9a4e9b 100644 --- a/public/app/features/dashboard/components/GenAI/utils.test.ts +++ b/public/app/features/dashboard/components/GenAI/utils.test.ts @@ -16,6 +16,16 @@ jest.mock('@grafana/experimental', () => ({ }, })); +jest.mock('@grafana/runtime', () => ({ + ...jest.requireActual('@grafana/runtime'), + config: { + ...jest.requireActual('@grafana/runtime').config, + apps: { + 'grafana-llm-app': true, + }, + }, +})); + describe('getDashboardChanges', () => { it('should correctly split user changes and migration changes', () => { // Mock data for testing diff --git a/public/app/features/dashboard/components/GenAI/utils.ts b/public/app/features/dashboard/components/GenAI/utils.ts index d195d289a0b..a0caf3065b4 100644 --- a/public/app/features/dashboard/components/GenAI/utils.ts +++ b/public/app/features/dashboard/components/GenAI/utils.ts @@ -1,6 +1,7 @@ import { pick } from 'lodash'; import { llms } from '@grafana/experimental'; +import { config } from '@grafana/runtime'; import { Panel } from '@grafana/schema'; import { DashboardModel, PanelModel } from '../../state'; @@ -63,6 +64,10 @@ export function getDashboardChanges(dashboard: DashboardModel): { * @returns true if the LLM plugin is enabled. */ export async function isLLMPluginEnabled() { + if (!config.apps['grafana-llm-app']) { + return false; + } + // Check if the LLM plugin is enabled. // If not, we won't be able to make requests, so return early. return llms.openai.health().then((response) => response.ok);