Skip to main content

LLM App and OpenAI

The Business Input Data Source supports LLM models (OpenAI, custom) using LLM App from Grafana.

LLM App

Add LLM App plugin and set up OpenAI API Key with OpenAI API Organization ID.

Configure LLM App plugin for Grafana to set API key and organization ID.
Configure LLM App plugin for Grafana to set API key and organization ID.

When LLM App configured, a text area will appear in Code editor mode of the Business Input Data Source.

Variables

Dashboard and Global variable are supported in the text area.

This text area allows you to use the response that will be received from the LLM App together with OpenAI. The result is stored in context.llmResult.

Result returned from LLM App for BTC price.
Result returned from LLM App for BTC price.

Example with BTC price

Message

Please return JSON with 2 arrays: datetime and price which contain BTC price
from ${__from:date} to ${__to:date} for every hour

JavaScript code editor

console.log("result", context.llmResult);

const content = context.llmResult?.choices?.[0]?.message?.content;
let data = {};

try {
data = JSON.parse(content);
} catch (e) {
console.error("Unable to parse result", e);
}

console.log("parsedData", data);

const result = {
...frame,
fields: frame.fields.map((field) => ({
...field,
values: field.name === "date" ? data.datetime || [] : data.price || [],
})),
};

return Promise.resolve(result);

Result

Produced data frame with results can be displayed with any panel plugin.

Display OpenAI results for BTC price using native Time Series panel.
Display OpenAI results for BTC price using native Time Series panel.