LLMApp: Skip 404 requests to know if the plugin exists (#85226)

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
This commit is contained in:
Torkel Ödegaard
2024-03-27 14:55:48 +01:00
committed by GitHub
parent fe209fdf7c
commit 61e67423ff
2 changed files with 15 additions and 0 deletions

View File

@@ -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

View File

@@ -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);