From 83961902f87c290cb48b30efc7dbb297c6e066cd Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Thu, 3 Aug 2023 11:31:27 +0100 Subject: [PATCH] Remove panelExplainer plugin extension link I've moved this to the grafana-llmexamples-app plugin instead, since it's really more of an example of how to use this functionality in a panel extension. --- src/extensions/index.ts | 1 - src/extensions/panelExplainer.tsx | 72 ------------------------------- src/module.ts | 4 +- 3 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 src/extensions/index.ts delete mode 100644 src/extensions/panelExplainer.tsx diff --git a/src/extensions/index.ts b/src/extensions/index.ts deleted file mode 100644 index fa2035e2..00000000 --- a/src/extensions/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { panelExplainer } from './panelExplainer'; diff --git a/src/extensions/panelExplainer.tsx b/src/extensions/panelExplainer.tsx deleted file mode 100644 index e0005d7d..00000000 --- a/src/extensions/panelExplainer.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import React from 'react'; - -import { PluginExtensionLinkConfig, PluginExtensionPanelContext, PluginExtensionPoints, PluginExtensionTypes } from "@grafana/data" -import { getBackendSrv } from '@grafana/runtime'; -import { useAsync } from 'react-use'; -import { scan } from 'rxjs/operators'; -import { Spinner } from '@grafana/ui'; -import { Dashboard } from '@grafana/schema'; -import { streamChatCompletions } from 'utils/utils.api'; - -interface ExplainPanelModalProps { - context: PluginExtensionPanelContext, -} - -const panelExplainerPrompt = 'Given the following JSON representation of a Grafana panel, explain what it shows. Be fairly brief in your summary, and use the present tense.'; - -const ExplainPanelModal = ({ context }: ExplainPanelModalProps) => { - const backendSrv = getBackendSrv(); - const [streamState, setStreamState] = React.useState(''); - const state = useAsync(async () => { - // Load the current dashboard JSON and find the relevant panel. - const dashboardJSON = await backendSrv.get(`/api/dashboards/uid/${context.dashboard.uid}`) as { dashboard: Dashboard }; - const panelJSON = dashboardJSON.dashboard.panels?.find( - // @ts-ignore: some panels don't have IDs, that's fine because they just won't match. - (panel) => panel.id === context.id - ); - // Use the panel JSON as the user prompt. - // TODO: include the data? or in future some kind of screenshot - // of the data, somehow. - const userPrompt = JSON.stringify(panelJSON, null, 2); - // Stream the completions. Each element is the next stream chunk. - const stream = streamChatCompletions({ - model: 'gpt-3.5-turbo', - systemPrompt: panelExplainerPrompt, - userPrompt, - }).pipe( - // Accumulate the stream chunks into a single string. - scan((acc, delta) => acc + delta, '') - ); - // Subscribe to the stream and update the state for each returned value. - return stream.subscribe(setStreamState); - }); - if (state.loading || streamState === '') { - return - } - if (state.error) { - // TODO: handle errors. - return null; - } - return ( -
{streamState}
- ) -} - -export const panelExplainer: PluginExtensionLinkConfig = { - title: 'Explain this panel', - description: 'Explain this panel', - type: PluginExtensionTypes.link, - extensionPointId: PluginExtensionPoints.DashboardPanelMenu, - onClick: (event, { context, openModal }) => { - if (event !== undefined) { - event.preventDefault(); - } - if (context === undefined) { - return; - } - openModal({ - title: 'Panel explanation', - body: () => , - }); - }, -}; diff --git a/src/module.ts b/src/module.ts index 6327c901..6f84db54 100644 --- a/src/module.ts +++ b/src/module.ts @@ -2,7 +2,6 @@ import { AppPlugin } from '@grafana/data'; import { App } from './components/App'; import { AppConfig } from './components/AppConfig'; -import { panelExplainer } from './extensions'; export const plugin = new AppPlugin<{}>() .setRootPage(App) @@ -11,5 +10,4 @@ export const plugin = new AppPlugin<{}>() icon: 'cog', body: AppConfig, id: 'configuration', - }) - .configureExtensionLink(panelExplainer); + });